UNPKG

2.13 kBTypeScriptView Raw
1import {PathLike} from 'line-column-path';
2
3export interface Options {
4 /**
5 The name, command, or binary path of the editor.
6
7 Default: [Auto-detected](https://github.com/sindresorhus/env-editor).
8
9 __Only use this option if you really have to.__ Can be useful if you want to force a specific editor or implement your own auto-detection.
10 */
11 readonly editor?: string;
12
13 /**
14 Wait until the editor is closed.
15
16 @default false
17
18 @example
19 ```
20 import openEditor from 'open-editor';
21
22 await openEditor(['unicorn.js:5:3'], {wait: true});
23 console.log('File was closed');
24 ```
25 */
26 readonly wait?: boolean;
27}
28
29export interface EditorInfo {
30 /**
31 THe editor binary name.
32 */
33 readonly binary: string;
34
35 /**
36 The arguments provided to the editor binary.
37 */
38 readonly arguments: string[];
39
40 /**
41 A flag indicating whether the editor runs in the terminal.
42 */
43 readonly isTerminalEditor: boolean;
44}
45
46/**
47Open the given files in the user's editor at specific line and column if supported by the editor. It does not wait for the editor to start or quit unless you specify `wait: true` in the options.
48
49@param files - Items should be in the format `foo.js:1:5` or `{file: 'foo.js', line: 1: column: 5}`.
50
51@returns Promise<void> - If options.wait is true, the returned promise resolves as soon as the editor closes. Otherwise it resolves when the editor starts.
52
53@example
54```
55import openEditor from 'open-editor';
56
57openEditor([
58 {
59 file: 'readme.md',
60 line: 10,
61 column: 2,
62 }
63]);
64
65openEditor([
66 'unicorn.js:5:3',
67]);
68```
69*/
70export default function openEditor(files: readonly PathLike[], options?: Options): Promise<void>;
71
72/**
73Same as `openEditor()`, but returns an object with the binary name, arguments, and a flag indicating whether the editor runs in the terminal.
74
75Can be useful if you want to handle opening the files yourself.
76
77@example
78```
79import {getEditorInfo} from 'open-editor';
80
81getEditorInfo([
82 {
83 file: 'foo.js',
84 line: 1,
85 column: 5,
86 }
87]);
88//=> {binary: 'subl', arguments: ['foo.js:1:5'], isTerminalEditor: false}
89```
90*/
91export function getEditorInfo(files: readonly PathLike[], options?: Options): EditorInfo;