What is the best way to create a new line in React that resembles a terminal?

What technologies am I working with?

I am currently using React and CSS modules in my development

Greetings! I am in the process of creating a website for a Portfolio Terminal

I have a vision to incorporate a feature where users can simulate creating a new line, similar to how terminals operate. When Enter is pressed in the terminal, it generates a new line like this: Terminal New Line Image

However, I have encountered an issue where after pressing enter and attempting another command, it fails to execute the command

I hope that explanation was clear enough

Below is the JSX code snippet:

// JS code here...
// Import statements and component definition

export default TerminalPage;

And if necessary, here are the associated styles:

:root {
  --main-text-color: #a16b56;
  --text-input-color: #73abad;
  --main-color: #e2d7a7;
  --text-url-hover: #1a4645;
  --text-url-color: #f8bc24;
  --user-text-color: rgb(81, 153, 117);
}

/* CSS styles go here... */

.commandBlock {
  background-color: var(--main-color);
  padding: 10px;
  border-radius: 5px;
  margin-bottom: 5px;
  color: var(--text-input-color);
  font-size: 1rem;
  font-weight: bold;
  text-shadow: 0 0 5px rgba(115, 171, 173, 0.5),
    0 0 10px rgba(115, 171, 173, 0.5), 0 0 15px rgba(115, 171, 173, 0.5);
}

Answer №1

Check out the updated codesandbox link: https://codesandbox.io/s/material-demo-forked-7dsyf2?file=/demo.js

=> I've included a new state named "inputHistory" to keep track of entered commands, similar to a Terminal.

Updated JSX code:

import React, { useEffect, useRef, useState } from "react";
import styles from "./TerminalPage.module.css";

function Demo() {
  const [textInput, setTextInput] = useState("");
  // more state variables
}

export default Demo;

Here's the Updated CSS code:

:root {
  --main-text-color: #a16b56;
  /* Custom CSS properties */
}

.terminalContainer {
  margin: 10px 0 0 10px;
  /* Styling for terminal container */
}

/* More CSS styles here */

.commandBlock {
  background-color: var(--main-color);
  padding: 10px;
  border-radius: 5px;
  /* Styling for command block */
}

If you have any questions, feel free to ask.

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

Transitioning from a material design list element to a card design

After reviewing the elevation section in the material design docs, I have encountered several challenges when it comes to implementation. I am trying to grasp how to implement this elevation using html+css+js, but my experience in these languages is limit ...

Having trouble sending a FormData object with Axios for a user uploaded file in a React, Node.JS project

My goal is to enable users to upload images to my application, which consists of a React frontend and a Node backend. The process involves sending the uploaded file from the client to the server, followed by making a request from the server to Firebase clo ...

Creating a 2D array in Objective-C with a variable size is simple and straightforward

I've recently started learning objective-c and I'm facing some challenges with 2D arrays. To help explain my issue, I'll make use of my knowledge in javascript. var row = 10; var col = 10; var array[row][col]; for (var i = 0; i < row; i ...

No files were located in the devDependencies

My package.json file has the following configuration: { "name": "essentials", "version": "1.0.0", "private": true, "devDependencies": { "concurrently": "3.4.0", "react-scripts": "1.0.14", "fsr-helpers": "file:../../fsr-helpers" }, ...

The transformation rotation applied in CSS must not have any impact on the styling of my span and paragraph

Snippet: .details-section{ background-color: rgb(83, 83, 83); height: 200px; } .icon-container{ border: 2px solid #c49b63; width: 90px; height: 90px; transition: 0.5s ease; } .box i{ font-size: 60px; color: black; margin-top: 13px ...

Populate two MUI-Autocomplete fields by selecting one item

Is it possible to have two different Autocomplete components on the same row within a table? I'm unsure if this can be done, and how to execute it based on the example provided below. [Feel free to check out the sandbox for more context] sandbox A ne ...

Using arrow functions in a Polymer or lit-element project is a simple and efficient way to write

I am currently exploring Polymer/lit-element and attempting to create a simple demo project. I have been trying to incorporate an ES6 arrow function within the class (specifically, the getButtonStyle function), but encountered the following error: Synta ...

Converting a standard redux object into a format suitable for display

Working on a React Native project with Redux, I need guidance on transforming data for rendering purposes. The data structure I have is a normalized object called userDetails, which looks like this: "userDetails": Object { "allIds": ...

How can I make TypeScript properly export function names for closure-compiler?

Here is the TypeScript code I am working with: namespace CompanyName.HtmlTools.Cookie { export function eraseCookie(name:string, path:string) { createCookie(name, "", path, -1); } export function readCookie(name:string) { ...

The JavaScript array remains unaltered

I've got an express server set up with GET and POST routes. The initial state looks something like this: let orders = [ { sum: 0, purchases: [ { id: 1, contractId: ...

The identifier "resolve" in the catch block has not been defined

Why is it not possible to call resolve in the catch block? I wanted to catch a failed request and attempt it again in the catch block, but I am encountering an issue where resolve is not defined. I am confused since I am inside of the promise, so why is i ...

All fields in the form are showing the same error message during validation

This is the HTML code: The form below consists of two fields, firstname and lastname. Validation Form <form action="" method="post"> Firstname : <input type="text" placeholder="first name" class="fname" name="fname" /> <span class= ...

The Bootstrap/Angular tab list items are generated dynamically based on the API response, leading to issues with the DOM

In one of my Angular templates, I have the following snippet. It consists of Bootstrap 3 tabs, but the tab list items (links) are generated dynamically after receiving a response from the API. <ul class="nav nav-tabs pull-right" role="tablist"> &l ...

Tool designed to analyze the timing of sub requests and methods in Node for benchmarking purposes

For my benchmarking and load testing needs, I initially utilized tools such as Apache Bench, Siege, and benchmark.js. However, these tools only provided me with the overall result or time taken from start to finish of the test. I am now seeking a tool or l ...

Verification message appears once the SQL database has provided the necessary information to the data table

function alertbox() { var mode = document.getElementById('<%= hdnMode.ClientID %>').value; if (mode == "EDIT") return false; if (confirm("Is the same data present against that ID?") == true) { document.getElemen ...

The received URL from the POST request in React is now being opened

After completing an API call, I successfully received the correct response in my console. Is there a way to redirect my React app from the local host to the URL provided (in this case, the one labeled GatewayUrl under data)? Any assistance would be greatly ...

Issues with AJAX chat system functionality

I've been struggling with this issue for a while now. Despite rewriting the code multiple times, I can't seem to make any progress. Below is the JavaScript code (located on the same page as the HTML): Summary: The user inputs text into a box, w ...

Update the class of the element that is currently selected using jQuery and the `this` keyword

Is there a way to change the class on hover only for the current element using 'this'? The code I have changes classes for all elements, but I need it to work individually. Here is the code snippet I'm currently using: https://codepen.io/ky ...

Whenever I adjust the zoom on my HTML page, it either scrolls upwards or downwards

Is there a way to prevent the page from scrolling when using zoom-in or zoom-out? I attempted using overflow: hidden in the body, but it did not work. <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...