You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to update prompt with useState hook?
I need to be able to run setPromptText() somewhere to update the prompt, but... I don't know how since the component doesn't have such a function to do that and I don't know how to extend it if its not a class.
How to call the an environment variable from my function?
Look at the buildPrompt function and see the comment where I point out my failing attempt to get the cwd from environment variables in state.
This is my code
importReact,{useState}from'react';importReactTerminalStateless,{ReactOutputRenderers}from'react-terminal-component';import{EmulatorState,getEnvironmentVariable}from'javascript-terminal';importmyThemefrom'./myTheme';importLevelfrom'./levels/level1/index';import"./app.css";// Define Emulator State From ModulesconstemulatorState=EmulatorState.create({'fs': Level.FS,'outputs': Level.Output,'history': Level.History,'environmentVariables': Level.Env,'commandMapping': Level.Commands,})constbuildPrompt=(state)=>{constheadDelim="┌──("constuser=Level.Data.userconstatChar="@"consthost=Level.Data.hostnameconstpathDelim=")-["// NOTE: This results in TypeError: Object(...) is not a function so Im not doing this right either.constcwd=getEnvironmentVariable(state.getEnvVariables(),'cwd')consttailDelim="]\n└─$ "returnheadDelim+user+atChar+host+pathDelim+cwd+tailDelim}// Component: AppexportdefaultfunctionApp(){// Declaring State Hooksconst[input,setInput]=useState('');const[emuState,setEmuState]=useState(emulatorState);const[promptText,setPromptText]=useState(buildPrompt(emuState))return(<ReactTerminalStatelessemulatorState={emuState}theme={myTheme}promptSymbol={promptText}outputRenderers={ReactOutputRenderers}inputStr={input}onInputChange={((inp)=>setInput(inp))}onStateChange={((eS)=>setEmuState(eS))}clickToFocus/>);}
Any tips for a newbie? Thank you.
The text was updated successfully, but these errors were encountered:
Two related problems:
How to update prompt with
useState
hook?I need to be able to run
setPromptText()
somewhere to update the prompt, but... I don't know how since the component doesn't have such a function to do that and I don't know how to extend it if its not a class.How to call the an environment variable from my function?
Look at the
buildPrompt
function and see the comment where I point out my failing attempt to get the cwd from environment variables in state.This is my code
Any tips for a newbie? Thank you.
The text was updated successfully, but these errors were encountered: