React Terminal Component

React component that renders a terminal emulator.

React Terminal Component is a customizable React component backed by a JavaScript terminal emulator.

Some of cool features of this React component are:

  • Emulator themes
  • In-memory file system
  • Built-in commands like ls, cd, head, cat, echo, rm and more
  • Autocompletion of terminal commands
  • Keyboard navigation of past commands using up and down arrow key


Install with npm or with yarn.

npm install react-terminal-component javascript-terminal --save
yarn add react-terminal-component javascript-terminal



import React, { Component } from 'react';
import ReactTerminal from 'react-terminal-component';

class App extends Component {
  render() {
    return (



Emulator state is created using the JavaScript terminal emulator library and contains:

  • the file system,
  • command mapping,
  • history,
  • command outputs, and
  • environment variables

The emulatorState prop allows you to provide a custom emulator state.

See the library documentation for information on creating the emulator state, or view the code examples to get started.


The theme prop accepts an object from ReactThemes. The themes current available are:

  • ReactThemes.magpie
  • ReactThemes.ember
  • ReactThemes.dye
  • ReactThemes.forest
  • ReactThemes.hacker
  • ReactThemes.sea
  • ReactThemes.light

To import ReactThemes use the following code:

import { ReactThemes } from 'react-terminal-component';

Alternatively, you can specify your own theme with an object like this:

<ReactTerminal theme={{
  background: '#141313',
  promptSymbolColor: '#6effe6',
  commandColor: '#fcfcfc',
  outputColor: '#fcfcfc',
  errorOutputColor: '#ff89bd',
  fontSize: '1.1rem',
  spacing: '1%',
  fontFamily: 'monospace'


The promptSymbol prop accepts a string to be displayed in command headers and the input field.


The outputRenderers prop allows you to create new ways of displaying terminal output. See the code example, which creates a new type of output (output with a white background).

The default renderers are accessible in ReactOutputRenderers.

import { ReactOutputRenderers } from 'react-terminal-component';


The acceptInput prop is a boolean value, defaulting to true. When disabled, the input field is removed. This may be useful in conjunction with ReactTerminalStateless if you're managing state externally and simulating long-running commands.


The clickToFocus prop is a boolean value, defaulting to false. When enabled, clicking anywhere within the terminal will shift focus to the input field.

Managing state externally

The ReactTerminal component allows the initial values of emulatorState and inputStr to be specified, but thereafter the component handles the state internally. In some cases you may need to manage the state externally from the react-terminal-component module.

You can use ReactTerminalStateless to control the state of emulatorState and inputStr, but you must also supply the onInputChange and onStateChange props.

All of the props documented above apply to both ReactTerminal and ReactTerminalStateless.

This is a simple component which handles the terminal state. You could adapt this idea to make the state be handled by Redux and to modify the state asynchronously, not in direct response to a command within the terminal.

import React, { Component } from 'react';
import {ReactTerminalStateless} from 'react-terminal-component';

class App extends Component {
  constructor() {
    this.state = {
      emulatorState: EmulatorState.createEmpty(),
      inputStr: 'initial value'

  render() {
    return (
        onInputChange={(inputStr) => this.setState({inputStr})}
        onStateChange={(emulatorState) => this.setState({emulatorState})}



First, make sure you have Node.js, Yarn and Git installed.

Now, fork and clone repo and install the dependencies.

git clone
cd react-terminal-component/
yarn install


Build scripts

  • yarn build - creates a production build of the library in lib
  • yarn dev - creates a development build of the library and runs a watcher

Test scripts

  • yarn test - run tests
  • yarn test:min - run tests with summary reports
  • yarn test:coverage - shows test coverage stats


  • yarn artifact:coverage-report - creates HTML test coverage report in .nyc_output
  • yarn artifact:storybook - emulator demos

Potential uses

Some ideas for using React Terminal Component in your next project:

  • Games: Create a command-line based game, playable in the browser
  • Education: Teach popular *NIX commands sandboxed in the browser (no important files accidentally removed with rm -r!)
  • Personal website: Make your personal website or web resume a command-line interface
  • Demos: Create mock commands in JavaScript for your CLI app, and let users try out commands in their browser with simulated output