UNPKG

1.52 kBTypeScriptView Raw
1/***
2 * Node External Editor
3 *
4 * Kevin Gravier <kevin@mrkmg.com>
5 * MIT 2019
6 */
7import { CreateFileError } from "./errors/CreateFileError";
8import { LaunchEditorError } from "./errors/LaunchEditorError";
9import { ReadFileError } from "./errors/ReadFileError";
10import { RemoveFileError } from "./errors/RemoveFileError";
11export interface IEditorParams {
12 args: string[];
13 bin: string;
14}
15export interface IFileOptions {
16 prefix?: string;
17 postfix?: string;
18 mode?: number;
19 template?: string;
20 dir?: string;
21}
22export declare type StringCallback = (err: Error, result: string) => void;
23export declare type VoidCallback = () => void;
24export { CreateFileError, LaunchEditorError, ReadFileError, RemoveFileError };
25export declare function edit(text?: string, fileOptions?: IFileOptions): string;
26export declare function editAsync(text: string, callback: StringCallback, fileOptions?: IFileOptions): void;
27export declare class ExternalEditor {
28 private static splitStringBySpace;
29 text: string;
30 tempFile: string;
31 editor: IEditorParams;
32 lastExitStatus: number;
33 private fileOptions;
34 readonly temp_file: string;
35 readonly last_exit_status: number;
36 constructor(text?: string, fileOptions?: IFileOptions);
37 run(): string;
38 runAsync(callback: StringCallback): void;
39 cleanup(): void;
40 private determineEditor;
41 private createTemporaryFile;
42 private readTemporaryFile;
43 private removeTemporaryFile;
44 private launchEditor;
45 private launchEditorAsync;
46}