diff --git a/src/components/applications/terminal/Terminal.js b/src/components/applications/terminal/Terminal.js index 6274c87..4ee89b5 100644 --- a/src/components/applications/terminal/Terminal.js +++ b/src/components/applications/terminal/Terminal.js @@ -1,7 +1,7 @@ import { useState } from "react"; import styles from "./Terminal.module.css"; -import { Command } from "./commands.js"; import { useVirtualRoot } from "../../../hooks/VirtualRootContext.js"; +import { Command } from "../../../features/applications/terminal/commands.js"; const USERNAME = "user"; const HOSTNAME = "prozilla-os"; @@ -32,11 +32,14 @@ function InputLine({ value, prefix, onChange, onKeyUp, onKeyDown }) { } export function Terminal() { + const [inputKey, setInputKey] = useState(0); const [inputValue, setInputValue] = useState(""); const [history, setHistory] = useState([]); const virtualRoot = useVirtualRoot(); const [currentDirectory, setCurrentDirectory] = useState(virtualRoot.navigate("~")); + // console.log(currentDirectory); + const prefix = `${USERNAME}@${HOSTNAME}:${currentDirectory.root ? "/" : currentDirectory.path}$ `; const updatedHistory = history; @@ -53,10 +56,6 @@ export function Terminal() { }; const submitInput = (value) => { - // To do: make empty submit go to new line - if (value.trim() === "") - return; - pushHistory({ text: prefix + value, isInput: true @@ -66,6 +65,9 @@ export function Terminal() { value = value.trim(); + if (value === "") + return; + const args = value.split(/ +/); const commandName = args.shift().toLowerCase(); @@ -105,6 +107,7 @@ export function Terminal() { // console.log(event); if (event.key === "Enter") { submitInput(value); + setInputKey((previousKey) => previousKey + 1); } }; @@ -131,6 +134,7 @@ export function Terminal() {