input-terminal
    Preparing search index...

    Allows you to turn any HTMLInputElement into a terminal interface. Define custom commands that can be executed by users, track command history, autocomplete commands, and more.

    import { Terminal, Command } from "input-terminal";
    const input = document.getElementById("terminal") as HTMLInputElement;
    const output = document.getElementById("output") as HTMLElement;
    const terminal = new Terminal(input, output, { prompt: ">> " });
    terminal.bin.add(new Command("echo", (args, options, terminal) => {
    terminal.stdout(args.join(" "));
    return {};
    }));
    terminal.init();

    Hierarchy

    • EventTarget
      • Terminal
    Index

    Constructors

    • Parameters

      • input: HTMLInputElement

        input element to turn into a terminal

      • Optionaloutput: HTMLElement

        optional output element to render stdout/stderr to

      • options: TermOptionsConfig = {}

        terminal configuration

      • commandHistory: ExitObject[] = []

        history of commands that have been executed

      • commandList: Command[] = []

        list of commands that can be executed by the user

      Returns Terminal

    Properties

    input: HTMLInputElement

    The input element that the terminal is attached to.

    output: TermOutput | undefined = undefined

    The output manager for the terminal.

    history: TermHistory

    The history of commands that have been executed.

    bin: TermBin

    The commands that can be executed by the user.

    options: TermOptions

    The options for the terminal.

    Accessors

    Methods

    • Emit data to stdout. Dispatches a "stdout" event and logs the data.

      Parameters

      • data: any

        the data to emit

      Returns void

    • Emit data to stderr. Dispatches a "stderr" event and logs the data.

      Parameters

      • data: any

        the data to emit

      Returns void

    • Get the full terminal prompt.

      Returns string

      the full terminal prompt (preprompt + prompt)

    • Initializes the terminal. Attaches input listeners and updates the input.

      Returns void

    • Updates the terminal's user input value.

      Parameters

      • OptionaluserInput: string

        the value to update the input with; clears the input if no value is provided

      Returns void

    • Gets the terminal's user input.

      Returns string

      The string in the input, not including the preprompt and prompt

    • Gets the command predictions based on the user's input.

      Parameters

      • Optionaltext: string

        The text to get predictions for; if no text is provided, all commands are returned

      Returns string[]

      The predictions for the terminal's user input

    • Converts the user's input into an array for command execution.

      Parameters

      • input: string

        The string to convert into an array

      Returns string[]

      The array created from the input

    • Get the last exit object of the terminal.

      Returns ExitObject | undefined

      The last exit object of the terminal; if no exit objects are found, returns undefined

    • Executes a command based on the user's input.

      Parameters

      • input: string

        The command to execute

      Returns ExitObject

      The ExitObject returned by the execution

    • The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

      MDN Reference

      Parameters

      • type: string
      • callback: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | AddEventListenerOptions

      Returns void

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

      MDN Reference

      Parameters

      • event: Event

      Returns boolean

    • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

      MDN Reference

      Parameters

      • type: string
      • callback: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | EventListenerOptions

      Returns void