2 * Copyright (c) 2017, Daniel Imms (MIT License).
3 * Copyright (c) 2018, Microsoft Corporation (MIT License).
6 declare module 'node-pty' {
8 * Forks a process as a pseudoterminal.
9 * @param file The file to launch.
10 * @param args The file's arguments as argv (string[]) or in a pre-escaped CommandLine format
11 * (string). Note that the CommandLine option is only available on Windows and is expected to be
13 * @param options The options of the terminal.
14 * @see CommandLineToArgvW https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx
15 * @see Parsing C++ Comamnd-Line Arguments https://msdn.microsoft.com/en-us/library/17w5ykft.aspx
16 * @see GetCommandLine https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156.aspx
18 export function spawn(file: string, args: string[] | string, options: IPtyForkOptions | IWindowsPtyForkOptions): IPty;
20 export interface IBasePtyForkOptions {
23 * Name of the terminal to be set in environment ($TERM variable).
28 * Number of intial cols of the pty.
33 * Number of initial rows of the pty.
38 * Working directory to be set for the slave program.
43 * Environment to be set for the slave program.
45 env?: { [key: string]: string };
48 * String encoding of the underlying pty.
49 * If set, incoming data will be decoded to strings and outgoing strings to bytes applying this encoding.
50 * If unset, incoming data will be delivered as raw bytes (Buffer type).
51 * By default 'utf8' is assumed, to unset it explicitly set it to `null`.
53 encoding?: string | null;
57 * Whether to enable flow control handling (false by default). If enabled a message of `flowControlPause`
58 * will pause the socket and thus blocking the slave program execution due to buffer back pressure.
59 * A message of `flowControlResume` will resume the socket into flow mode.
60 * For performance reasons only a single message as a whole will match (no message part matching).
61 * If flow control is enabled the `flowControlPause` and `flowControlResume` messages are not forwarded to
62 * the underlying pseudoterminal.
64 handleFlowControl?: boolean;
68 * The string that should pause the pty when `handleFlowControl` is true. Default is XOFF ('\x13').
70 flowControlPause?: string;
74 * The string that should resume the pty when `handleFlowControl` is true. Default is XON ('\x11').
76 flowControlResume?: string;
79 export interface IPtyForkOptions extends IBasePtyForkOptions {
81 * Security warning: use this option with great caution, as opened file descriptors
82 * with higher privileges might leak to the slave program.
88 export interface IWindowsPtyForkOptions extends IBasePtyForkOptions {
90 * Whether to use the ConPTY system on Windows. When this is not set, ConPTY will be used when
91 * the Windows build number is >= 18309 (instead of winpty). Note that ConPTY is available from
92 * build 17134 but is too unstable to enable by default.
94 * This setting does nothing on non-Windows.
99 * Whether to use PSEUDOCONSOLE_INHERIT_CURSOR in conpty.
100 * @see https://docs.microsoft.com/en-us/windows/console/createpseudoconsole
102 conptyInheritCursor?: boolean;
106 * An interface representing a pseudoterminal, on Windows this is emulated via the winpty library.
108 export interface IPty {
110 * The process ID of the outer process.
112 readonly pid: number;
115 * The column size in characters.
117 readonly cols: number;
120 * The row size in characters.
122 readonly rows: number;
125 * The title of the active process.
127 readonly process: string;
131 * Whether to handle flow control. Useful to disable/re-enable flow control during runtime.
132 * Use this for binary data that is likely to contain the `flowControlPause` string by accident.
134 handleFlowControl: boolean;
137 * Adds an event listener for when a data event fires. This happens when data is returned from
139 * @returns an `IDisposable` to stop listening.
141 readonly onData: IEvent<string>;
144 * Adds an event listener for when an exit event fires. This happens when the pty exits.
145 * @returns an `IDisposable` to stop listening.
147 readonly onExit: IEvent<{ exitCode: number, signal?: number }>;
150 * Adds a listener to the data event, fired when data is returned from the pty.
151 * @param event The name of the event.
152 * @param listener The callback function.
153 * @deprecated Use IPty.onData
155 on(event: 'data', listener: (data: string) => void): void;
158 * Adds a listener to the exit event, fired when the pty exits.
159 * @param event The name of the event.
160 * @param listener The callback function, exitCode is the exit code of the process and signal is
161 * the signal that triggered the exit. signal is not supported on Windows.
162 * @deprecated Use IPty.onExit
164 on(event: 'exit', listener: (exitCode: number, signal?: number) => void): void;
167 * Resizes the dimensions of the pty.
168 * @param columns THe number of columns to use.
169 * @param rows The number of rows to use.
171 resize(columns: number, rows: number): void;
174 * Writes data to the pty.
175 * @param data The data to write.
177 write(data: string): void;
181 * @param signal The signal to use, defaults to SIGHUP. This parameter is not supported on
183 * @throws Will throw when signal is used on Windows.
185 kill(signal?: string): void;
189 * An object that can be disposed via a dispose function.
191 export interface IDisposable {
196 * An event that can be listened to.
197 * @returns an `IDisposable` to stop listening.
199 export interface IEvent<T> {
200 (listener: (e: T) => any): IDisposable;