Create a typewriter effect that mimics the backspace feature by allowing overlapping characters

I am interested in creating a simulation for the vintage LGP-30 computer. This will involve input and output on a simulated Friden Flexowriter typewriter.

One unique feature of the typewriter is that pressing the backspace key merely shifts the print head one position to the left, without actually erasing the last character. This allows for printing overlapping characters. For instance, typing O, backspace, / would result in a "Ø" character. Similarly, for underlined text, one could type "text", then press backspace four times followed by _ four times.

So far, the best solution I have come up with involves this CSS class:

.bs {
    letter-spacing: -0.6em;
}

This enables me to use HTML like

<span class="bs">O</span>/
to achieve the desired output. However, it requires an array of overlapping characters for each position in the output div to generate the HTML for overlapping characters.

For example, for the word "text" with underline, the generated output would be:

<span class="bs">t</span>_
<span class="bs">e</span>_
<span class="bs">x</span>_
<span class="bs">t</span>_

What I envision is something like this:

text&bksp;&bksp;&bksp;&bksp;____

Or any other substitution for a backspace character that results in letters appearing as if they are painted over one another.

Do you know any CSS tricks, or perhaps some TypeScript code or a Node.js library, that can assist me in implementing this functionality without much difficulty? The font used will be monospace, so all I need is a "negative space symbol" or a command to "move the cursor 0.6em to the left."

Answer №1

If you have a simple input string with \b characters, it is possible to generate the output HTML from it.
My approach would involve arranging the letters in a grid format, with each child element placed in the same cell.

Here is a complete example:

<script>
    let text = 'hello world\b\b\b\b\b_____';

    $: positions = (() => {
        let positions = [];
        let current = 0;
        for (let i = 0; i < text.length; i++) {
            if (text[i] == '\b') {
                current--;
                continue;
            }

            positions[current] ??= [];
            positions[current].push(text[i]);
            current++;
        }

        return positions;
    })();
</script>

<div class="root">
    {#each positions as list}
        <span class="pos">
            {#each list as letter}<span class="letter">{letter}</span>{/each}
        </span>
    {/each}
</div>

<style>
    .root { font-family: monospace; }
    .pos { display: inline-grid; }
    .pos > * { grid-area: 1 / 1; }
    .letter { white-space: pre; }
</style>

REPL

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leveraging object imported from interface

I have a question regarding Angular/TypeScript. It may seem obvious, but I would like clarification. What I'm doing is creating an interface and exporting it: export interface MainObject { location: string; methodType: string; securityLevel: st ...

The <a href="#divtagid"> link is incapable of triggering the opening of the div tag when called from JavaScript

I need help with displaying the content of a div with the id "hello" in maindiv when clicking on the href "Click Here", but it's not working as expected. Here is the code I have: $(document).ready(function() { var newhtml = '<a href="#he ...

The background image is not showing up

I've been grappling with a CSS background-image dilemma that's got me stumped. Here's the situation: CSS #yes { background-image:url("../tick.png"); background-repeat: no-repeat; height: 16px; width: 16px; }​ #no { backg ...

Decrease the size of ion-list items in Ionic 2

I found a similar query over on Stack Overflow, but it's related to Ionic 1 where the ion-item still includes ion-content. In Ionic 2, there is no ionic-content element. I've attempted to adjust the height, padding, and margin of both the ion-ite ...

Unable to bring in an exported class from a TypeScript file

I have a TypeScript file named foo.ts that contains an exported class called "Foo" export default class Foo{ } I am attempting to import this class into another file within the same directory import {Foo} from './foo'; However, I am encounter ...

What could be causing my submenu to not display the specified hover effect?

Help needed troubleshooting dropdown menu issue in HTML and CSS. Using :hover to switch from display:none; to display:flex;. Want submenu to appear when hovering over "Unsere Produkte". Grateful for any assistance. Thank you. /* Desktop Navigation Bar ...

Personalized Icons for Google Maps. (Designed for iPhone)

I am currently working on a project where I am designing a website specifically for iPhones. The main functionality of the site is to find the latitude and longitude of a certain location and display it on a Google map. I already have all the necessary det ...

Converting JSON data into an HTML table representation

My code reads SQL data and converts it into JSON format. $sql = "SELECT students.studentnumber, students.firstname, students.lastname, badge_id FROM students INNER JOIN student_has_badge WHERE student_has_badge.badge_id = 10 AND student.studentnumber ...

How can I emphasize the React Material UI TextField "Cell" within a React Material UI Table?

Currently, I am working on a project using React Material UI along with TypeScript. In one part of the application, there is a Material UI Table that includes a column of Material TextFields in each row. The goal is to highlight the entire table cell when ...

Challenges with Media Queries post Integration of MUI Library in React

I have been scratching my head for the last few hours. I needed to utilize a react library to design my dog app for a project. Opting for the MUI library, it has been effective for the grid layout. However, the challenge arises when attempting to implement ...

Utilizing Next.js App Router to Enable Static Site Generation for Dynamic Routes in Live Environments

For my portfolio, I am utilizing Next.js's new App Router to highlight projects with dynamic routing (src/app/projects/[id]/page.tsx). During development, useSearchParams is able to correctly retrieve the project ID. However, in production, it returns ...

React TypeScript: The properties of 'X' are not compatible. 'Y' cannot be assigned to 'Z' type

I am currently working on a React-TypeScript application, specifically creating a component for inputting credit card numbers. My goal is to have the FontAwesome icon inside the input update to reflect the brand image as the user enters their credit card n ...

Guide to crafting a flawless pixel-perfect separator with CSS borders

I have a menu with a black background and a submenu with a grey background. Now, I want to add a pixel-perfect divider between them. However, I'm unsure of which border color to use in order to achieve this perfection. Can anyone provide some guidan ...

Secure higher order React component above class components and stateless functional components

I have been working on creating a higher order component to verify the authentication status of a user. Currently, I am using React 15.5.4 and @types/react 15.0.21, and below is a simplified version of my code: import * as React from 'react'; i ...

Display the output of awk on a single line for specific columns

Here is a file called "test" that displays the following information: vserver share-name path acl TEST_SERVER TEST_SHARE_PATH /TEST/TESTSHAREPATH "test\testuser / Read","test\testuser1_R / Read","test\testuser2_RW / Change ...

The exportAs attribute is not specified as "ngForm" for any directive

Encountered an error while attempting to test the LoginComponent PhantomJS 2.1.1 (Linux 0.0.0): Executed 3 of 55 (1 FAILED) (0 secs / 0.307 secs) PhantomJS 2.1.1 (Linux 0.0.0) LoginComponent should create FAILED Failed: Uncaught (in promise): Error: Templ ...

What could be preventing the background image from displaying properly?

I had the idea to create a game where players have to flip cards to reveal what's on the back, but I'm struggling to get the background image to display properly. As a newcomer to Vue, I'm not sure if I made a mistake somewhere. My intuition ...

The canvas is being expanded by utilizing the drawImage method

Ensuring the correct size of a <canvas> element is crucial to prevent stretching, which can be achieved by setting the width and height attributes. Without any CSS applied other than background-color, I am faced with an unusual issue. Using ctx.draw ...

Custom Mapped Types in TypeScript

I'm currently exploring ways to create a custom type that will convert the properties of an object from type Vector to type Array. This is what I have so far type ToArray<T> = { [P in keyof T]: T[P] extends Vector<any> ? Array<any ...

Transforming a Java applet into an <object> tag

After updating my Java to the latest version, I encountered a problem with an applet I regularly use. Despite adjusting the security settings to the lowest level through the Control Panel, the applet still fails to run correctly. Here is how the applet was ...