installed pty
[VSoRC/.git] / node_modules / node-pty / src / index.ts
1 /**
2  * Copyright (c) 2012-2015, Christopher Jeffrey, Peter Sunde (MIT License)
3  * Copyright (c) 2016, Daniel Imms (MIT License).
4  * Copyright (c) 2018, Microsoft Corporation (MIT License).
5  */
6
7 import { ITerminal, IPtyOpenOptions, IPtyForkOptions, IWindowsPtyForkOptions } from './interfaces';
8 import { ArgvOrCommandLine } from './types';
9
10 let terminalCtor: any;
11 if (process.platform === 'win32') {
12   terminalCtor = require('./windowsTerminal').WindowsTerminal;
13 } else {
14   terminalCtor = require('./unixTerminal').UnixTerminal;
15 }
16
17 /**
18  * Forks a process as a pseudoterminal.
19  * @param file The file to launch.
20  * @param args The file's arguments as argv (string[]) or in a pre-escaped
21  * CommandLine format (string). Note that the CommandLine option is only
22  * available on Windows and is expected to be escaped properly.
23  * @param options The options of the terminal.
24  * @throws When the file passed to spawn with does not exists.
25  * @see CommandLineToArgvW https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx
26  * @see Parsing C++ Comamnd-Line Arguments https://msdn.microsoft.com/en-us/library/17w5ykft.aspx
27  * @see GetCommandLine https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156.aspx
28  */
29 export function spawn(file?: string, args?: ArgvOrCommandLine, opt?: IPtyForkOptions | IWindowsPtyForkOptions): ITerminal {
30   return new terminalCtor(file, args, opt);
31 }
32
33 /** @deprecated */
34 export function fork(file?: string, args?: ArgvOrCommandLine, opt?: IPtyForkOptions | IWindowsPtyForkOptions): ITerminal {
35   return new terminalCtor(file, args, opt);
36 }
37
38 /** @deprecated */
39 export function createTerminal(file?: string, args?: ArgvOrCommandLine, opt?: IPtyForkOptions | IWindowsPtyForkOptions): ITerminal {
40   return new terminalCtor(file, args, opt);
41 }
42
43 export function open(options: IPtyOpenOptions): ITerminal {
44   return terminalCtor.open(options);
45 }
46
47 /**
48  * Expose the native API when not Windows, note that this is not public API and
49  * could be removed at any time.
50  */
51 export const native = (process.platform !== 'win32' ? require('../build/Release/pty.node') : null);