node-pty

  • Version 1.0.0
  • Published
  • 1.14 MB
  • 1 dependency
  • MIT license

Install

npm i node-pty
yarn add node-pty
pnpm add node-pty

Overview

Fork pseudoterminals in Node.JS

Index

Namespaces

namespace node-pty

module 'node-pty' {}
  • Copyright (c) 2017, Daniel Imms (MIT License). Copyright (c) 2018, Microsoft Corporation (MIT License).

function spawn

spawn: (
file: string,
args: string[] | string,
options: IPtyForkOptions | IWindowsPtyForkOptions
) => IPty;
  • Forks a process as a pseudoterminal.

    Parameter file

    The file to launch.

    Parameter args

    The file's arguments as argv (string[]) or in a pre-escaped CommandLine format (string). Note that the CommandLine option is only available on Windows and is expected to be escaped properly.

    Parameter options

    The options of the terminal.

    See Also

    • CommandLineToArgvW https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx

    • Parsing C++ Comamnd-Line Arguments https://msdn.microsoft.com/en-us/library/17w5ykft.aspx

    • GetCommandLine https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156.aspx

interface IBasePtyForkOptions

interface IBasePtyForkOptions {}

    property cols

    cols?: number;
    • Number of intial cols of the pty.

    property cwd

    cwd?: string;
    • Working directory to be set for the child program.

    property encoding

    encoding?: string | null;
    • String encoding of the underlying pty. If set, incoming data will be decoded to strings and outgoing strings to bytes applying this encoding. If unset, incoming data will be delivered as raw bytes (Buffer type). By default 'utf8' is assumed, to unset it explicitly set it to null.

    property env

    env?: { [key: string]: string | undefined };
    • Environment to be set for the child program.

    property flowControlPause

    flowControlPause?: string;
    • (EXPERIMENTAL) The string that should pause the pty when handleFlowControl is true. Default is XOFF ('\x13').

    property flowControlResume

    flowControlResume?: string;
    • (EXPERIMENTAL) The string that should resume the pty when handleFlowControl is true. Default is XON ('\x11').

    property handleFlowControl

    handleFlowControl?: boolean;
    • (EXPERIMENTAL) Whether to enable flow control handling (false by default). If enabled a message of flowControlPause will pause the socket and thus blocking the child program execution due to buffer back pressure. A message of flowControlResume will resume the socket into flow mode. For performance reasons only a single message as a whole will match (no message part matching). If flow control is enabled the flowControlPause and flowControlResume messages are not forwarded to the underlying pseudoterminal.

    property name

    name?: string;
    • Name of the terminal to be set in environment ($TERM variable).

    property rows

    rows?: number;
    • Number of initial rows of the pty.

    interface IDisposable

    interface IDisposable {}
    • An object that can be disposed via a dispose function.

    method dispose

    dispose: () => void;

      interface IEvent

      interface IEvent<T> {}
      • An event that can be listened to.

        Returns

        an IDisposable to stop listening.

      call signature

      (listener: (e: T) => any): IDisposable;

        interface IPty

        interface IPty {}
        • An interface representing a pseudoterminal, on Windows this is emulated via the winpty library.

        property cols

        readonly cols: number;
        • The column size in characters.

        property handleFlowControl

        handleFlowControl: boolean;
        • (EXPERIMENTAL) Whether to handle flow control. Useful to disable/re-enable flow control during runtime. Use this for binary data that is likely to contain the flowControlPause string by accident.

        property onData

        readonly onData: IEvent<string>;
        • Adds an event listener for when a data event fires. This happens when data is returned from the pty.

          Returns

          an IDisposable to stop listening.

        property onExit

        readonly onExit: IEvent<{ exitCode: number; signal?: number }>;
        • Adds an event listener for when an exit event fires. This happens when the pty exits.

          Returns

          an IDisposable to stop listening.

        property pid

        readonly pid: number;
        • The process ID of the outer process.

        property process

        readonly process: string;
        • The title of the active process.

        property rows

        readonly rows: number;
        • The row size in characters.

        method clear

        clear: () => void;
        • Clears the pty's internal representation of its buffer. This is a no-op unless on Windows/ConPTY. This is useful if the buffer is cleared on the frontend in order to synchronize state with the backend to avoid ConPTY possibly reprinting the screen.

        method kill

        kill: (signal?: string) => void;
        • Kills the pty.

          Parameter signal

          The signal to use, defaults to SIGHUP. This parameter is not supported on Windows.

          Throws

          Will throw when signal is used on Windows.

        method pause

        pause: () => void;
        • Pauses the pty for customizable flow control.

        method resize

        resize: (columns: number, rows: number) => void;
        • Resizes the dimensions of the pty.

          Parameter columns

          The number of columns to use.

          Parameter rows

          The number of rows to use.

        method resume

        resume: () => void;
        • Resumes the pty for customizable flow control.

        method write

        write: (data: string) => void;
        • Writes data to the pty.

          Parameter data

          The data to write.

        interface IPtyForkOptions

        interface IPtyForkOptions extends IBasePtyForkOptions {}

          property gid

          gid?: number;

            property uid

            uid?: number;
            • Security warning: use this option with great caution, as opened file descriptors with higher privileges might leak to the child program.

            interface IWindowsPtyForkOptions

            interface IWindowsPtyForkOptions extends IBasePtyForkOptions {}

              property conptyInheritCursor

              conptyInheritCursor?: boolean;
              • Whether to use PSEUDOCONSOLE_INHERIT_CURSOR in conpty.

                See Also

                • https://docs.microsoft.com/en-us/windows/console/createpseudoconsole

              property useConpty

              useConpty?: boolean;
              • Whether to use the ConPTY system on Windows. When this is not set, ConPTY will be used when the Windows build number is >= 18309 (instead of winpty). Note that ConPTY is available from build 17134 but is too unstable to enable by default.

                This setting does nothing on non-Windows.

              Package Files (1)

              Dependencies (1)

              Dev Dependencies (9)

              Peer Dependencies (0)

              No peer dependencies.

              Badge

              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/node-pty.

              • Markdown
                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/node-pty)
              • HTML
                <a href="https://www.jsdocs.io/package/node-pty"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>