1.0.6 • Published 4 months ago

keepix-react-simple-terminal-ui v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

react-simple-terminal-ui

A simple react component to display an interactive terminal. You can define commands yourself, customize the styling and choose between different window frames.

NPM

Checkout the Demo

Usage

import { TerminalUi } from 'react-simple-terminal-ui';
import "react-simple-terminal-ui/dist/styles.css"

const commands = [{
  command: "help", print: <div>
      <b>print</b> print something<br />
      <b>alert</b> show an alert<br />
      <br/>
  </div>
},
{ command: "print", print: "Hello world!"},
{ command: "alert", callback: () => alert("this is an alert triggered by a callback.") }]

const initialFeed =  ["Please type help for a list of commands."]

const Example = () => {

    return <TerminalUi
            initialFeed={initialFeed}
            prompt='[visitor@my-desktop]$ '
            commands={commands}
            blinkerChar={"_"}
            frame={"Win98"}
            commandNotFoundMessage={cmd => `Sorry, I can't find '${cmd}'`}
           />
}

Props

TerminalUi

NameTypeFunctionDefaultOptional
commandsArrayArray of commands (see below)-
styleobjectstyle for the root component-
titlestringa title that is shown in the title section of the window framesprompt/unset
initialFeedArray<string|ReactNode>Initial records that are shown before the first prompt-
classNamestringclassName for the root component-
recordClassNamestringclassName for each record component-
promptstringThe prompt string that is shown in the beginning of each new line"$"
commandNotFoundMessage(cmd: string) => stringcustom message if the command was not found(cmd) => command '${cmd}' not found.
blinkerComponentReactNodedefine your own blinking-component-
blinkerCharstringthe char that blinks (e.g. '_')-
frame"None", "Win98", "MacOs", "GnomeUbuntu"The window frame that is going to be used"None"

Command

NameTypeFunctionDefaultOptional
commandstringthe command that needs to be typed in the terminal
printstringReactNodethe content that is rendered when the command matches.
callbackFunctiona callback that is executed when the command matches.

License

MIT © movcmpret

1.0.6

4 months ago

1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago