input-terminal
    Preparing search index...

    Class Terminal

    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
    • 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

    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.

    • get started(): boolean

      Get whether the terminal has been initialized.

      Returns boolean

    • 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 a copy of the current stdout log.

      Returns any[]

      the stdout log

    • Get a copy of the current stderr log.

      Returns any[]

      the stderr log

    • 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

    • Destroys the terminal instance. Detaches input and output listeners and marks the terminal as not started. This does not clear command history, registered commands, input text, or output contents.

      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. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

      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. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

      MDN Reference

      Parameters

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

      Returns void