Skip to content

Repository files navigation

MIT-licensed console emulator in React. Documentation and more advanced features coming soon!

react-console

React component that emulates console behaviour

NPMJavaScript Style Guidelicense-sh badge

Install

npm install --save @webscopeio/react-console

Demo

https://webscopeio.github.io/react-console/

Screenshot

Webscope React Console

Props

PropsTypeDescription
commands*CommandsProp
promptstring
welcomeMessagestring
autoFocusboolean
noCommandFound(...str: string[]) => Promise
wrapperStyleReact.CSSPropertiesstyles for wrapper
promptWrapperStyleReact.CSSPropertiesstyles for promptWrapper
promptStyleReact.CSSPropertiesstyles for prompt
lineStyleReact.CSSPropertiesstyles for line
inputStyleReact.CSSPropertiesstyles for input
wrapperClassNamestringclassName for wrapper
promptWrapperClassNamestringclassName for promptWrapper
promptClassNamestringclassName for prompt
lineClassNamestringclassName for line
inputClassNamestringclassName for input
historystring[]history array
onAddHistoryItem(entry: string) => voidcallback called when a new history entry is created
onSanitizeOutputLine(line: string) => stringcallback called before a new output line is inserted to DOM

*are mandatory

Usage

importReact,{Component}from'react'importReactConsolefrom'react-console'constApp=()=>{const[history,setHistory]=useState(["echo hello world","sleep 1000","sleep 2000","sleep 3000","echo ola","not found",])return(<div><ReactConsoleautoFocuswelcomeMessage="Welcome"commands={{history: {description: 'History',fn: ()=>newPromise(resolve=>{resolve(`${history.join('\r\n')}`)})},echo: {description: 'Echo',fn: (...args)=>{returnnewPromise((resolve,reject)=>{setTimeout(()=>{resolve(`${args.join(' ')}`)},2000)})}},test: {description: 'Test',fn: (...args)=>{returnnewPromise((resolve,reject)=>{setTimeout(()=>{resolve('Hello world \n\n hello \n')},2000)})}}}}/></div>)}exportdefaultApp

History implementation

You can provide your own history implementation by providing onAddHistoryItem and history properties. If you don't provide history, up/down arrows & reverse search won't work.

License

MIT © jvorcak

About

💻 Simple console emulator in React

Resources

Stars

40 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages