Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bgoodman/react-console-component

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bgoodman/react-console-component

A unix-style text console as a React component.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
0
Weekly downloads
 
Created
Source

React Console Component

A React component that provides a console-like interface for displaying the output of commands and to capture user input. The component itself does not provide any functionality for executing commands.

Try the demo here.

An example using a Bash interpreter

Installation

npm install @bgoodman/react-console-component

Usage

import { Console } from '@bgoodman/react-console-component'

const App = () => {
    const onInit = (): Promise<string> => {
        // do something when the console is initialized.
        const output = new Date().toString()
        // return the console output as a promise.
        return Promise.resolve(output)
    }

    const evalCmd = (cmd) => {
        try {
            // do something with the input command.
            const result = eval(cmd).toString()
            // return the result as a promise
            return Promise.resolve(result)
        } catch (err) {
            return Promise.resolve(err.toString())
        }
    }

    return (
        <Console
            onEnter={execCode}
            onInit={onInit}
            prompt="$"
            height="300px"
            autoScroll
        />
    )
}

an example using javascript eval

Props

PropTypeDefaultDescription
onEnter(cmd: string) => Promise<string>undefinedFunction to execute when the user presses 'Enter'.
onInit() => Promise<string>undefinedFunction to execute when the console is initialized.
promptstring"$"The prompt string.
heightstring"300px"The height of the console.
autoScrollbooleantrueIf true, the console will automatically scroll to the bottom when new content is added.
themeThemeSee 'Themes' section.A custom theme to use for the console. If not provided, the default light theme will be used.

Themes

The console component uses the styled-components library to style the console. You can provide your own theme by passing a Theme object to the theme prop. For example, the default theme is defined as:

import { type Theme } from '@bgoodman/react-console-component'

const lightTheme: Theme = {
    font: {
        size: '16px',
        family: 'monospace'
    },
    colors: {
        background: '#FFFFFF',
        text: '#5F6368'
    },
}

Additional themes can be defined as needed. For example, a dark theme could be defined as:

const darkTheme: Theme = {
    font: {
        size: '16px',
        family: 'monospace'
    },
    colors: {
        background: '#272822',
        text: '#F8F8F2'
    },
}

Reserved Commands

The console component reserves the following commands:

  • clear - Clears the console output.

Keywords

FAQs

Package last updated on 28 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc