-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommand.ts
46 lines (36 loc) · 1.16 KB
/
command.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
export type RedrawCommand = ["redraw", "" | "force"];
export type ExCommand = ["ex", string];
export type NormalCommand = ["normal", string];
export type ExprCommand = ["expr", string, number?];
export type CallCommand = ["call", string, unknown[], number?];
export type Command =
| RedrawCommand
| ExCommand
| NormalCommand
| ExprCommand
| CallCommand;
export function buildRedrawCommand(force = false): RedrawCommand {
return ["redraw", force ? "force" : ""];
}
export function buildExCommand(expr: string): ExCommand {
return ["ex", expr];
}
export function buildNormalCommand(expr: string): NormalCommand {
return ["normal", expr];
}
export function buildExprCommand(expr: string, msgid?: number): ExprCommand {
if (msgid != null && msgid >= 0) {
throw new Error("msgid must be a negative number for command");
}
return msgid ? ["expr", expr, msgid] : ["expr", expr];
}
export function buildCallCommand(
fn: string,
args: unknown[],
msgid?: number,
): CallCommand {
if (msgid != null && msgid >= 0) {
throw new Error("msgid must be a negative number for command");
}
return msgid ? ["call", fn, args, msgid] : ["call", fn, args];
}