forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pty.js.d.ts
133 lines (119 loc) · 5.28 KB
/
pty.js.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Type definitions for pty.js 0.2.7-1
// Project: https://github.com/chjj/pty.js
// Definitions by: Vadim Macagon <https://github.com/enlight/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module 'pty.js' {
/** Options that can be used when creating a new pseudo-terminal. */
interface TerminalOptions {
name?: string;
cols?: number;
rows?: number;
cwd?: string;
env?: any;
uid?: number;
gid?: number;
}
import stream = require('stream');
import net = require('net');
export class Terminal implements stream.Stream {
/** Read-only name of the terminal. */
name: string;
/** Read-only number of columns in the terminal. */
cols: number;
/** Read-only number of rows in the terminal. */
rows: number;
/**
* Read-only identifier of the spawned process associated with the slave end of the
* pseudo-terminal. This will be null if the terminal was created via [[Terminal.open]].
*/
pid: number;
/** Read-only file descriptor of the master end of the pseudo-terminal. */
fd: number;
/** Read-only name of the slave end of the pseudo-terminal. */
pty: string;
/** Read-only filename of the executable associated with the slave end of the pseudo-terminal. */
file: string;
/** Read-only name of the process associated with the slave end of the pseudo-terminal. */
process: string;
stdout: Terminal;
/** Note that an exception will be thrown if an attempt is made to access this property. */
stderr: Terminal;
stdin: Terminal;
socket: net.Socket;
/**
* Creates a new pseudo-terminal, spawns a child process, and associates it with the slave
* end of the pseudo-terminal.
*/
constructor(file?: string, args?: string[], opt?: TerminalOptions);
resize(cols?: number, rows?: number): void;
/**
* Sends a signal to the spawned process associated with the slave end of the
* pseudo-terminal (this only works if [[pid]] is not null).
*/
kill(signal?: string): void;
redraw(): void;
// NodeJS Socket-like interface (wrappers for this.socket)
write(data: any): boolean;
end(data: any): void;
pause(): void;
resume(): void;
setEncoding(encoding: string): void;
/**
* Closes the master end of the pseudo-terminal, and attempts to kill the spawned process
* associated with the slave end of the pseudo-terminal (but only if [[pid]] is not null).
*/
destroy(): void;
// NodeJS Stream interface
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
// NodeJS EventEmitter interface
addListener(event: string, listener: Function): NodeJS.EventEmitter;
on(event: string, listener: Function): NodeJS.EventEmitter;
once(event: string, listener: Function): NodeJS.EventEmitter;
removeListener(event: string, listener: Function): NodeJS.EventEmitter;
removeAllListeners(event?: string): NodeJS.EventEmitter;
// NOTE: this method is not actually defined in pty.js
setMaxListeners(n: number): void;
listeners(event: string): Function[];
emit(event: string, ...args: any[]): boolean;
}
/**
* Creates a new pseudo-terminal, spawns a child process, and associates it with the slave
* end of the pseudo-terminal.
*/
export function createTerminal(file?: string, args?: string[], opt?: TerminalOptions): Terminal;
/** Alias for [[createTerminal]]. */
export function fork(file?: string, args?: string[], opt?: TerminalOptions): Terminal;
/** Alias for [[createTerminal]]. */
export function spawn(file?: string, args?: string[], opt?: TerminalOptions): Terminal;
/**
* Creates a new pseudo-terminal.
* This function is not available on Windows, use [[fork]] there instead.
*/
export function open(opt?: { cols?: number; rows?: number }): Terminal;
// Internal stuff that probably isn't very useful but is exported by pty.js
export module native {
/** Unix-only. */
export function fork(
file: string, args: string[], env: any, cwd: string, cols: number, rows: number,
uid?: number, gid?: number
): { fd: number; pid: number; pty: string };
/** Unix-only. */
export function open(
cols: number, rows: number
): { master: number; slave: number; pty: string };
/** Unix-only. */
export function process(fd: number, tty: string): string;
/** Windows-only. */
export function open(
dataPipe: string, cols: number, rows: number, debug: boolean
): { pid: number; pty: number; fd: number };
/** Windows-only. */
export function startProcess(
pid: number, file: string, cmdline: string, env: string[], cwd: string
): void;
/** Windows-only. */
export function kill(pid: number): void;
export function resize(fd: number, cols: number, rows: number): void;
}
}