the ps1 prompt displays properly

This commit is contained in:
2025-02-17 15:02:06 -05:00
parent 84e7089140
commit 375427b16e
8 changed files with 139 additions and 98 deletions

View File

@ -1,13 +1,28 @@
import create from "../elements/create"
const enum Colors {
red = "red",
green = "green",
blue = "blue",
cyan = "cyan",
bold = "bold"
}
function newcolor(inner: string, color?: Colors) {
const span = create("span", color)
span.innerText = inner
return span
}
const red = (s: string) => <span className="red">{s}</span>
const green = (s: string) => <span className="green">{s}</span>
const blue = (s: string) => <span className="blue">{s}</span>
const cyan = (s: string) => <span className="cyan">{s}</span>
const bold = (s: string) => <span className="bold">{s}</span>
const red = (s: string) => newcolor(s, Colors.red )
const green = (s: string) => newcolor(s, Colors.green)
const blue = (s: string) => newcolor(s, Colors.blue)
const cyan = (s: string) => newcolor(s, Colors.cyan)
const bold = (s: string) => newcolor(s, Colors.bold)
export default function rgb(s: string, Ru8: number, Gu8: number, Bu8: number) {
return <span style={{color: `rgb(${Ru8},${Gu8},${Bu8})`}}>{s}</span>
const rgb_span = newcolor(s)
rgb_span.style.color = `rgb(${Ru8},${Gu8},${Bu8})`
return rgb_span
}
export {

View File

@ -1,9 +1,6 @@
import Display from "./prompt"
import run from "./command/run"
import { type newElement } from "../terminal/exec";
import type { JSX } from "react";
const enum Key {
Enter = "Enter",
ArrowUp = "ArrowUp",
@ -11,28 +8,6 @@ const enum Key {
Tab = "Tab"
}
function display_prompt() {
return <div className="shell-prompt">
<Display/>
<input className="shell-ps1" type="text" spellCheck={false}/>
</div>
}
function get_current_prompt(): HTMLInputElement | undefined {
const shell_input = document.getElementsByClassName("shell-ps1")
return shell_input[shell_input.length-1] as HTMLInputElement
}
function new_prompt(): JSX.Element {
const shell_prompts = document.getElementsByClassName("shell-ps1")
Array.from(shell_prompts).forEach(shellps1 => {
(shellps1 as HTMLInputElement).disabled = true
})
return display_prompt()
}
function keyboard_events(terminal_window: HTMLElement, new_elements_f: newElement) {
const terminal_event = (keyboard_event: KeyboardEvent) => {
if (keyboard_event.key === Key.Enter) {
@ -57,6 +32,4 @@ function keyboard_events(terminal_window: HTMLElement, new_elements_f: newElemen
export {
keyboard_events,
display_prompt,
get_current_prompt
}