1.2.1 • Published 3 years ago

@webscopeio/react-console v1.2.1

Weekly downloads
73
License
MIT
Repository
github
Last release
3 years ago

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

react-console

React component that emulates console behaviour

NPM JavaScript Style Guide license-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

import React, { Component } from 'react'

import ReactConsole from 'react-console'

const App = () => {
  const [history, setHistory] = useState([
    "echo hello world",
    "sleep 1000",
    "sleep 2000",
    "sleep 3000",
    "echo ola",
    "not found",
  ])

  return (
    <div>
      <ReactConsole
        autoFocus
        welcomeMessage="Welcome"
        commands={{
          history: {
            description: 'History',
            fn: () => new Promise(resolve => {
               resolve(`${history.join('\r\n')}`)
            })
          },
          echo: {
            description: 'Echo',
            fn: (...args) => {
              return new Promise((resolve, reject) => {
                setTimeout(() => {
                  resolve(`${args.join(' ')}`)
                }, 2000)
              })
            }
          },
          test: {
            description: 'Test',
            fn: (...args) => {
              return new Promise((resolve, reject) => {
                setTimeout(() => {
                  resolve('Hello world \n\n hello \n')
                }, 2000)
              })
            }
          }
        }}
      />
    </div>
  )
}
export default App

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

1.2.1

3 years ago

1.2.0

4 years ago

1.1.3

4 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago