upgrade commands & console

develop
TBS093A 2020-07-22 16:12:17 +02:00
parent aca4eb0f2d
commit db4782acf0
2 changed files with 25 additions and 18 deletions

View File

@ -1,11 +1,12 @@
import React from 'react' import React from 'react'
const help = () => { const help = () => {
return "register - register user by form \n" return "register - register user by form \n"
+ "login - login user by form \n" + "login - login user by form \n"
+ "logout - logout user \n" + "logout - logout user \n"
+ "start - start command \n" + "start - start command \n"
+ " -a --app - app flag - start music service app \n" + " -a --app - app flag - start music service app \n"
+ "clean - clean screen \n"
} }
const register = () => { const register = () => {
@ -41,11 +42,8 @@ const startApp = () => {
} }
const undefined = (command) => { const undefined = (command) => {
return ( return 'command "'+ command + '" is undefined\n'
<div> + ' type "help" for more commands\n'
command '{command}' is undefined
</div>
)
} }
export default { export default {

View File

@ -22,26 +22,35 @@ const IndexConsole = () => {
const consoleInput = React.createRef() const consoleInput = React.createRef()
let consoleUser = 'guest@00x097 * > '
const detectCommand = (event) => { const detectCommand = (event) => {
event.preventDefault() event.preventDefault()
setConsoleHistory( '# ' + consoleInput.current.value + '\n') let inputValue = consoleInput.current.value
if (consoleInput.current.value === 'help') consoleUser += inputValue + '\n'
setConsoleHistory( commands.help() ) if ( inputValue === 'help' )
console.log(consoleHistory) setConsoleHistory( consoleHistory + consoleUser + commands.help() )
else if ( inputValue === 'clean' )
setConsoleHistory( '' )
else
setConsoleHistory( consoleHistory + consoleUser + commands.undefined(inputValue) )
consoleInput.current.value = ''
activateInput() activateInput()
} }
return ( return (
<div id='consoleDiv' onClick={ activateInput }> <div id='consoleDiv' onClick={ activateInput }>
<div> <div id='consoleInfo'>
tbs093a@00x097 system, welcome <br /> 00x097 system (Version 0.1.9) <br />
type 'help' to get commands type 'help' for more commands <br />
type 'start -a' for start app
<br /><br />
</div> </div>
<pre id='consoleHistory'> <pre id='consoleHistory'>
{ consoleHistory } { consoleHistory }
</pre> </pre>
<form onSubmit={ detectCommand }> <form onSubmit={ detectCommand }>
# guest@00x097 * >
<input <input
id='consoleInput' id='consoleInput'
ref={consoleInput} ref={consoleInput}