dirvi-lib 0.11.0-beta.4 → 0.11.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/input/application/intent-to-effect.d.ts +1 -1
- package/dist/input/application/intent-to-effect.d.ts.map +1 -1
- package/dist/input/application/intent-to-effect.js +3 -3
- package/dist/input/application/parse-ex-command.d.ts +42 -0
- package/dist/input/application/parse-ex-command.d.ts.map +1 -0
- package/dist/input/application/parse-ex-command.js +215 -0
- package/dist/input/domain/effect.d.ts +20 -6
- package/dist/input/domain/effect.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/input/application/parse-command.d.ts +0 -14
- package/dist/input/application/parse-command.d.ts.map +0 -1
- package/dist/input/application/parse-command.js +0 -156
|
@@ -10,5 +10,5 @@ import type { Effect, Intent } from '../domain/index.js';
|
|
|
10
10
|
* @typeParam Value - Application-owned data stored in each tree node.
|
|
11
11
|
*/
|
|
12
12
|
export type IntentToEffect<Id extends SerializableKey, Value> = (intent: Intent, state: State<Id, Value>) => Effect<Id, Value> | undefined;
|
|
13
|
-
export declare function createIntentToEffect<Id extends SerializableKey, Value>(stateApi: StateApi<Id, Value>, cursorApi: CursorApi<Id>, treeNodeApi: TreeNodeApi<Id, Value>): IntentToEffect<Id, Value>;
|
|
13
|
+
export declare function createIntentToEffect<Id extends SerializableKey, Value>(registeredCommands: ReadonlySet<string>, stateApi: StateApi<Id, Value>, cursorApi: CursorApi<Id>, treeNodeApi: TreeNodeApi<Id, Value>): IntentToEffect<Id, Value>;
|
|
14
14
|
//# sourceMappingURL=intent-to-effect.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent-to-effect.d.ts","sourceRoot":"","sources":["../../../src/input/application/intent-to-effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,KAAK,EACL,QAAQ,EACR,WAAW,EACZ,MAAM,sBAAsB,CAAC;AAC9B,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CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,WAAW,CAAC,EAAE,EAAE,KAAK,CAAC,GAClC,cAAc,CAAC,EAAE,EAAE,KAAK,CAAC,CAkE3B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseExCommand } from './parse-ex-command.js';
|
|
2
2
|
import { parseNormalCommand } from './parse-normal-command.js';
|
|
3
|
-
export function createIntentToEffect(stateApi, cursorApi, treeNodeApi) {
|
|
3
|
+
export function createIntentToEffect(registeredCommands, stateApi, cursorApi, treeNodeApi) {
|
|
4
4
|
return (intent, state) => {
|
|
5
5
|
switch (intent.intentType) {
|
|
6
6
|
case 'setNormalBuffer':
|
|
@@ -42,7 +42,7 @@ export function createIntentToEffect(stateApi, cursorApi, treeNodeApi) {
|
|
|
42
42
|
},
|
|
43
43
|
};
|
|
44
44
|
case 'executeCommandLine':
|
|
45
|
-
return (
|
|
45
|
+
return (parseExCommand(intent.commandLine, registeredCommands) ?? {
|
|
46
46
|
effectType: 'setInputState',
|
|
47
47
|
inputState: {
|
|
48
48
|
inputMode: 'normal',
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { SerializableKey } from '../../trees/index.js';
|
|
2
|
+
import type { Effect } from '../domain/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Parses a Vim-style Ex command line into an application effect.
|
|
5
|
+
*
|
|
6
|
+
* Leading and trailing whitespace is removed, followed by all consecutive
|
|
7
|
+
* leading `:` characters. The remaining text is split on one or more
|
|
8
|
+
* whitespace characters:
|
|
9
|
+
*
|
|
10
|
+
* - The first token is treated as the command name.
|
|
11
|
+
* - All remaining tokens are treated as command arguments.
|
|
12
|
+
*
|
|
13
|
+
* Registered user commands are matched by exact name before built-in commands,
|
|
14
|
+
* allowing them to override built-ins. A match produces a `userExCommand`
|
|
15
|
+
* effect containing the registered name and argument tokens. This function
|
|
16
|
+
* neither looks up nor executes the registered callback.
|
|
17
|
+
*
|
|
18
|
+
* Otherwise, the command is interpreted as a built-in, with its arguments
|
|
19
|
+
* passed to the command-specific parser where applicable.
|
|
20
|
+
*
|
|
21
|
+
* Parsing is token-based and does not support quoted or escaped arguments.
|
|
22
|
+
* Consequently, whitespace within an argument cannot currently be preserved.
|
|
23
|
+
* Built-in argument validation is handled by the command-specific parsers;
|
|
24
|
+
* registered user-command arguments are forwarded without validation.
|
|
25
|
+
*
|
|
26
|
+
* An empty command produces `undefined`. An unknown command produces an
|
|
27
|
+
* `emitError` effect whose message includes the original `commandLine`.
|
|
28
|
+
*
|
|
29
|
+
* Command parsing is independent of the concrete tree-node value type, but the
|
|
30
|
+
* generic parameters allow its result to compose with the application's
|
|
31
|
+
* `Effect<Id, Value>` pipeline.
|
|
32
|
+
*
|
|
33
|
+
* @typeParam Id - The sibling-unique tree-node ID type.
|
|
34
|
+
* @typeParam Value - Application-owned data stored in each tree node.
|
|
35
|
+
* @param commandLine - The raw Ex command line, whitespace before or after,
|
|
36
|
+
* optionally prefixed with one or more `:` characters.
|
|
37
|
+
* @param registeredCommands - Registered user-command names that take
|
|
38
|
+
* precedence over built-in commands.
|
|
39
|
+
* @returns The parsed application effect, or `undefined` for an empty command.
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseExCommand<Id extends SerializableKey, Value>(commandLine: string, registeredCommands: ReadonlySet<string>): Effect<Id, Value> | undefined;
|
|
42
|
+
//# sourceMappingURL=parse-ex-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-ex-command.d.ts","sourceRoot":"","sources":["../../../src/input/application/parse-ex-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AA6IjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,cAAc,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,EAC9D,WAAW,EAAE,MAAM,EACnB,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAAC,GACtC,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,SAAS,CAoE/B"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// const DEFAULT_VIEW_NAME = 'default';
|
|
2
|
+
const DEFAULT_FOLD_TREE_NAME = 'default';
|
|
3
|
+
function parseAppCommand(commandArgs) {
|
|
4
|
+
const [firstArgument, ...remainingArguments] = commandArgs;
|
|
5
|
+
const badArgs = {
|
|
6
|
+
effectType: 'emitError',
|
|
7
|
+
message: `Unrecognized command arguments: app ${commandArgs.join(' ')}`,
|
|
8
|
+
};
|
|
9
|
+
switch (firstArgument) {
|
|
10
|
+
case 'list':
|
|
11
|
+
return commandArgs.length === 1
|
|
12
|
+
? {
|
|
13
|
+
effectType: 'listApps',
|
|
14
|
+
}
|
|
15
|
+
: badArgs;
|
|
16
|
+
case 'open':
|
|
17
|
+
case 'switch': {
|
|
18
|
+
const [appId, input] = remainingArguments;
|
|
19
|
+
if (appId === undefined || remainingArguments.length > 2) {
|
|
20
|
+
return badArgs;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
effectType: 'switchApp',
|
|
24
|
+
appId,
|
|
25
|
+
input,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
default: {
|
|
29
|
+
if (firstArgument === undefined || remainingArguments.length > 1) {
|
|
30
|
+
return badArgs;
|
|
31
|
+
}
|
|
32
|
+
const input = remainingArguments[0];
|
|
33
|
+
return {
|
|
34
|
+
effectType: 'switchApp',
|
|
35
|
+
appId: firstArgument,
|
|
36
|
+
input,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function parseFoldCommand(commandArgs) {
|
|
42
|
+
const [subcommand, name] = commandArgs;
|
|
43
|
+
const badArgs = {
|
|
44
|
+
effectType: 'emitError',
|
|
45
|
+
message: `Unrecognized command arguments: fold ${commandArgs.join(' ')}`,
|
|
46
|
+
};
|
|
47
|
+
switch (subcommand) {
|
|
48
|
+
case 'list':
|
|
49
|
+
return commandArgs.length === 1
|
|
50
|
+
? {
|
|
51
|
+
effectType: 'listFolds',
|
|
52
|
+
}
|
|
53
|
+
: badArgs;
|
|
54
|
+
case 'create':
|
|
55
|
+
return name === undefined || commandArgs.length !== 2
|
|
56
|
+
? badArgs
|
|
57
|
+
: {
|
|
58
|
+
effectType: 'dispatchEffectAction',
|
|
59
|
+
action: {
|
|
60
|
+
effectActionType: 'createFoldTree',
|
|
61
|
+
name,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
case 'delete':
|
|
65
|
+
return name === undefined || commandArgs.length !== 2
|
|
66
|
+
? badArgs
|
|
67
|
+
: {
|
|
68
|
+
effectType: 'dispatchEffectAction',
|
|
69
|
+
action: {
|
|
70
|
+
effectActionType: 'deleteFoldTree',
|
|
71
|
+
name,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
case 'enable':
|
|
75
|
+
case 'close':
|
|
76
|
+
return commandArgs.length > 2
|
|
77
|
+
? badArgs
|
|
78
|
+
: {
|
|
79
|
+
effectType: 'dispatchEffectAction',
|
|
80
|
+
action: {
|
|
81
|
+
effectActionType: 'fold',
|
|
82
|
+
foldTree: {
|
|
83
|
+
foldTreeReferenceType: 'name',
|
|
84
|
+
name: name ?? DEFAULT_FOLD_TREE_NAME,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
case 'disable':
|
|
89
|
+
case 'open':
|
|
90
|
+
return commandArgs.length > 2
|
|
91
|
+
? badArgs
|
|
92
|
+
: {
|
|
93
|
+
effectType: 'dispatchEffectAction',
|
|
94
|
+
action: {
|
|
95
|
+
effectActionType: 'unfold',
|
|
96
|
+
foldTree: {
|
|
97
|
+
foldTreeReferenceType: 'name',
|
|
98
|
+
name: name ?? DEFAULT_FOLD_TREE_NAME,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
case 'toggle':
|
|
103
|
+
return commandArgs.length > 2
|
|
104
|
+
? badArgs
|
|
105
|
+
: {
|
|
106
|
+
effectType: 'dispatchEffectAction',
|
|
107
|
+
action: {
|
|
108
|
+
effectActionType: 'toggleFold',
|
|
109
|
+
foldTree: {
|
|
110
|
+
foldTreeReferenceType: 'name',
|
|
111
|
+
name: name ?? DEFAULT_FOLD_TREE_NAME,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
default:
|
|
116
|
+
return badArgs;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Parses a Vim-style Ex command line into an application effect.
|
|
121
|
+
*
|
|
122
|
+
* Leading and trailing whitespace is removed, followed by all consecutive
|
|
123
|
+
* leading `:` characters. The remaining text is split on one or more
|
|
124
|
+
* whitespace characters:
|
|
125
|
+
*
|
|
126
|
+
* - The first token is treated as the command name.
|
|
127
|
+
* - All remaining tokens are treated as command arguments.
|
|
128
|
+
*
|
|
129
|
+
* Registered user commands are matched by exact name before built-in commands,
|
|
130
|
+
* allowing them to override built-ins. A match produces a `userExCommand`
|
|
131
|
+
* effect containing the registered name and argument tokens. This function
|
|
132
|
+
* neither looks up nor executes the registered callback.
|
|
133
|
+
*
|
|
134
|
+
* Otherwise, the command is interpreted as a built-in, with its arguments
|
|
135
|
+
* passed to the command-specific parser where applicable.
|
|
136
|
+
*
|
|
137
|
+
* Parsing is token-based and does not support quoted or escaped arguments.
|
|
138
|
+
* Consequently, whitespace within an argument cannot currently be preserved.
|
|
139
|
+
* Built-in argument validation is handled by the command-specific parsers;
|
|
140
|
+
* registered user-command arguments are forwarded without validation.
|
|
141
|
+
*
|
|
142
|
+
* An empty command produces `undefined`. An unknown command produces an
|
|
143
|
+
* `emitError` effect whose message includes the original `commandLine`.
|
|
144
|
+
*
|
|
145
|
+
* Command parsing is independent of the concrete tree-node value type, but the
|
|
146
|
+
* generic parameters allow its result to compose with the application's
|
|
147
|
+
* `Effect<Id, Value>` pipeline.
|
|
148
|
+
*
|
|
149
|
+
* @typeParam Id - The sibling-unique tree-node ID type.
|
|
150
|
+
* @typeParam Value - Application-owned data stored in each tree node.
|
|
151
|
+
* @param commandLine - The raw Ex command line, whitespace before or after,
|
|
152
|
+
* optionally prefixed with one or more `:` characters.
|
|
153
|
+
* @param registeredCommands - Registered user-command names that take
|
|
154
|
+
* precedence over built-in commands.
|
|
155
|
+
* @returns The parsed application effect, or `undefined` for an empty command.
|
|
156
|
+
*/
|
|
157
|
+
export function parseExCommand(commandLine, registeredCommands) {
|
|
158
|
+
const command = commandLine.trim().replace(/^:+/, '');
|
|
159
|
+
if (command === '') {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
const [commandName, ...commandArgs] = command.split(/\s+/);
|
|
163
|
+
if (commandName !== undefined && registeredCommands.has(commandName)) {
|
|
164
|
+
return {
|
|
165
|
+
effectType: 'userExCommand',
|
|
166
|
+
name: commandName,
|
|
167
|
+
args: commandArgs,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
switch (commandName) {
|
|
171
|
+
case 'q':
|
|
172
|
+
return {
|
|
173
|
+
effectType: 'quit',
|
|
174
|
+
exitMessage: '',
|
|
175
|
+
};
|
|
176
|
+
case 'app':
|
|
177
|
+
return parseAppCommand(commandArgs);
|
|
178
|
+
case 'fold':
|
|
179
|
+
return parseFoldCommand(commandArgs);
|
|
180
|
+
case 'evlp':
|
|
181
|
+
return {
|
|
182
|
+
effectType: 'emitVisibleLeavesPaths',
|
|
183
|
+
};
|
|
184
|
+
// case 'mkview!':
|
|
185
|
+
// return {
|
|
186
|
+
// effectType: 'saveView',
|
|
187
|
+
// name: commandArgs[0] || DEFAULT_VIEW_NAME,
|
|
188
|
+
// overwrite: true,
|
|
189
|
+
// };
|
|
190
|
+
//
|
|
191
|
+
// case 'loadview':
|
|
192
|
+
// return {
|
|
193
|
+
// effectType: 'loadView',
|
|
194
|
+
// name: commandArgs[0] || DEFAULT_VIEW_NAME,
|
|
195
|
+
// };
|
|
196
|
+
default:
|
|
197
|
+
return {
|
|
198
|
+
effectType: 'emitError',
|
|
199
|
+
message: `Unrecognized command: "${commandLine}"`,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/*
|
|
203
|
+
* Vim-style view commands:
|
|
204
|
+
*
|
|
205
|
+
* :mkview!
|
|
206
|
+
* :mkview! project
|
|
207
|
+
* :loadview
|
|
208
|
+
* :loadview project
|
|
209
|
+
*
|
|
210
|
+
* The name may contain spaces, so capture the remainder of the command
|
|
211
|
+
* instead of splitting on whitespace.
|
|
212
|
+
*
|
|
213
|
+
* TODO Later: mkview that checks if a same-named view already exists.
|
|
214
|
+
*/
|
|
215
|
+
}
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import type { InputModeState } from './input-mode-state.js';
|
|
2
2
|
import type { SerializableKey, TreeNode } from '../../trees/index.js';
|
|
3
|
+
export type EffectClosure = () => void | Promise<void>;
|
|
3
4
|
/**
|
|
4
|
-
* An effect
|
|
5
|
+
* An effect is some execution to be done in `App`, that could affect the shell
|
|
6
|
+
* or current app of dirvi.
|
|
7
|
+
*
|
|
8
|
+
* It is produced by interpreting an intent against the current state.
|
|
5
9
|
*
|
|
6
10
|
* @typeParam Id - The sibling-unique tree-node ID type.
|
|
7
11
|
* @typeParam Value - Application-owned data stored in each tree node.
|
|
8
12
|
*/
|
|
9
13
|
export type Effect<Id extends SerializableKey, Value> = Readonly<{
|
|
14
|
+
effectType: 'quit';
|
|
15
|
+
exitMessage: string;
|
|
16
|
+
}> | Readonly<{
|
|
17
|
+
effectType: 'listApps';
|
|
18
|
+
}> | Readonly<{
|
|
19
|
+
effectType: 'switchApp';
|
|
20
|
+
appId: string;
|
|
21
|
+
input: string | undefined;
|
|
22
|
+
}> | Readonly<{
|
|
10
23
|
effectType: 'dispatchEffectAction';
|
|
11
24
|
action: EffectAction<Id, Value>;
|
|
12
25
|
}> | Readonly<{
|
|
@@ -23,15 +36,16 @@ export type Effect<Id extends SerializableKey, Value> = Readonly<{
|
|
|
23
36
|
effectType: 'emitVisibleLeavesPaths';
|
|
24
37
|
}> | Readonly<{
|
|
25
38
|
effectType: 'listFolds';
|
|
26
|
-
}> | Readonly<{
|
|
27
|
-
effectType: 'quit';
|
|
28
|
-
exitMessage: string;
|
|
29
39
|
}> | Readonly<{
|
|
30
40
|
effectType: 'setInputState';
|
|
31
41
|
inputState: InputModeState;
|
|
32
42
|
}> | Readonly<{
|
|
33
|
-
effectType: '
|
|
34
|
-
|
|
43
|
+
effectType: 'userExCommand';
|
|
44
|
+
name: string;
|
|
45
|
+
args: readonly string[];
|
|
46
|
+
}> | Readonly<{
|
|
47
|
+
effectType: 'emitError';
|
|
48
|
+
message: string;
|
|
35
49
|
}>;
|
|
36
50
|
/**
|
|
37
51
|
* A user-facing reference to a fold tree.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../../src/input/domain/effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEtE
|
|
1
|
+
{"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../../src/input/domain/effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEtE,MAAM,MAAM,aAAa,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,MAAM,MAAM,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,IAChD,QAAQ,CAAC;IACP,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CA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@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { SerializableKey } from '../../trees/index.js';
|
|
2
|
-
import type { Effect } from '../domain/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Parses a command-line command into an application effect.
|
|
5
|
-
*
|
|
6
|
-
* Command parsing is independent of the concrete tree-node value type, but the
|
|
7
|
-
* generic parameters allow its result to compose with the application's
|
|
8
|
-
* Effect<Id, Value> pipeline.
|
|
9
|
-
*
|
|
10
|
-
* @typeParam Id - The sibling-unique tree-node ID type.
|
|
11
|
-
* @typeParam Value - Application-owned data stored in each tree node.
|
|
12
|
-
*/
|
|
13
|
-
export declare function parseCommand<Id extends SerializableKey, Value>(commandLine: string): Effect<Id, Value> | undefined;
|
|
14
|
-
//# sourceMappingURL=parse-command.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-command.d.ts","sourceRoot":"","sources":["../../../src/input/application/parse-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AA8GjD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,EAC5D,WAAW,EAAE,MAAM,GAClB,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,SAAS,CAyD/B"}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
const DEFAULT_VIEW_NAME = 'default';
|
|
2
|
-
const DEFAULT_FOLD_TREE_NAME = 'default';
|
|
3
|
-
function parseFoldCommand(commandArgs) {
|
|
4
|
-
const [subcommand, name] = commandArgs;
|
|
5
|
-
switch (subcommand) {
|
|
6
|
-
case 'list':
|
|
7
|
-
return commandArgs.length === 1
|
|
8
|
-
? {
|
|
9
|
-
effectType: 'listFolds',
|
|
10
|
-
}
|
|
11
|
-
: {
|
|
12
|
-
effectType: 'unrecognizedCommand',
|
|
13
|
-
commandLine: `fold ${commandArgs.join(' ')}`,
|
|
14
|
-
};
|
|
15
|
-
case 'create':
|
|
16
|
-
return name === undefined || commandArgs.length !== 2
|
|
17
|
-
? {
|
|
18
|
-
effectType: 'unrecognizedCommand',
|
|
19
|
-
commandLine: `fold ${commandArgs.join(' ')}`,
|
|
20
|
-
}
|
|
21
|
-
: {
|
|
22
|
-
effectType: 'dispatchEffectAction',
|
|
23
|
-
action: {
|
|
24
|
-
effectActionType: 'createFoldTree',
|
|
25
|
-
name,
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
case 'delete':
|
|
29
|
-
return name === undefined || commandArgs.length !== 2
|
|
30
|
-
? {
|
|
31
|
-
effectType: 'unrecognizedCommand',
|
|
32
|
-
commandLine: `fold ${commandArgs.join(' ')}`,
|
|
33
|
-
}
|
|
34
|
-
: {
|
|
35
|
-
effectType: 'dispatchEffectAction',
|
|
36
|
-
action: {
|
|
37
|
-
effectActionType: 'deleteFoldTree',
|
|
38
|
-
name,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
case 'enable':
|
|
42
|
-
case 'close':
|
|
43
|
-
return commandArgs.length > 2
|
|
44
|
-
? {
|
|
45
|
-
effectType: 'unrecognizedCommand',
|
|
46
|
-
commandLine: `fold ${commandArgs.join(' ')}`,
|
|
47
|
-
}
|
|
48
|
-
: {
|
|
49
|
-
effectType: 'dispatchEffectAction',
|
|
50
|
-
action: {
|
|
51
|
-
effectActionType: 'fold',
|
|
52
|
-
foldTree: {
|
|
53
|
-
foldTreeReferenceType: 'name',
|
|
54
|
-
name: name ?? DEFAULT_FOLD_TREE_NAME,
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
case 'disable':
|
|
59
|
-
case 'open':
|
|
60
|
-
return commandArgs.length > 2
|
|
61
|
-
? {
|
|
62
|
-
effectType: 'unrecognizedCommand',
|
|
63
|
-
commandLine: `fold ${commandArgs.join(' ')}`,
|
|
64
|
-
}
|
|
65
|
-
: {
|
|
66
|
-
effectType: 'dispatchEffectAction',
|
|
67
|
-
action: {
|
|
68
|
-
effectActionType: 'unfold',
|
|
69
|
-
foldTree: {
|
|
70
|
-
foldTreeReferenceType: 'name',
|
|
71
|
-
name: name ?? DEFAULT_FOLD_TREE_NAME,
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
case 'toggle':
|
|
76
|
-
return commandArgs.length > 2
|
|
77
|
-
? {
|
|
78
|
-
effectType: 'unrecognizedCommand',
|
|
79
|
-
commandLine: `fold ${commandArgs.join(' ')}`,
|
|
80
|
-
}
|
|
81
|
-
: {
|
|
82
|
-
effectType: 'dispatchEffectAction',
|
|
83
|
-
action: {
|
|
84
|
-
effectActionType: 'toggleFold',
|
|
85
|
-
foldTree: {
|
|
86
|
-
foldTreeReferenceType: 'name',
|
|
87
|
-
name: name ?? DEFAULT_FOLD_TREE_NAME,
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
default:
|
|
92
|
-
return {
|
|
93
|
-
effectType: 'unrecognizedCommand',
|
|
94
|
-
commandLine: `fold ${commandArgs.join(' ')}`,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Parses a command-line command into an application effect.
|
|
100
|
-
*
|
|
101
|
-
* Command parsing is independent of the concrete tree-node value type, but the
|
|
102
|
-
* generic parameters allow its result to compose with the application's
|
|
103
|
-
* Effect<Id, Value> pipeline.
|
|
104
|
-
*
|
|
105
|
-
* @typeParam Id - The sibling-unique tree-node ID type.
|
|
106
|
-
* @typeParam Value - Application-owned data stored in each tree node.
|
|
107
|
-
*/
|
|
108
|
-
export function parseCommand(commandLine) {
|
|
109
|
-
const command = commandLine.trim().replace(/^:/, '');
|
|
110
|
-
if (command === '') {
|
|
111
|
-
return undefined;
|
|
112
|
-
}
|
|
113
|
-
const [commandName, ...commandArgs] = command.split(/\s+/);
|
|
114
|
-
switch (commandName) {
|
|
115
|
-
case 'q':
|
|
116
|
-
return {
|
|
117
|
-
effectType: 'quit',
|
|
118
|
-
exitMessage: '',
|
|
119
|
-
};
|
|
120
|
-
case 'fold':
|
|
121
|
-
return parseFoldCommand(commandArgs);
|
|
122
|
-
case 'evlp':
|
|
123
|
-
return {
|
|
124
|
-
effectType: 'emitVisibleLeavesPaths',
|
|
125
|
-
};
|
|
126
|
-
case 'mkview!':
|
|
127
|
-
return {
|
|
128
|
-
effectType: 'saveView',
|
|
129
|
-
name: commandArgs[0] || DEFAULT_VIEW_NAME,
|
|
130
|
-
overwrite: true,
|
|
131
|
-
};
|
|
132
|
-
case 'loadview':
|
|
133
|
-
return {
|
|
134
|
-
effectType: 'loadView',
|
|
135
|
-
name: commandArgs[0] || DEFAULT_VIEW_NAME,
|
|
136
|
-
};
|
|
137
|
-
default:
|
|
138
|
-
return {
|
|
139
|
-
effectType: 'unrecognizedCommand',
|
|
140
|
-
commandLine,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
/*
|
|
144
|
-
* Vim-style view commands:
|
|
145
|
-
*
|
|
146
|
-
* :mkview!
|
|
147
|
-
* :mkview! project
|
|
148
|
-
* :loadview
|
|
149
|
-
* :loadview project
|
|
150
|
-
*
|
|
151
|
-
* The name may contain spaces, so capture the remainder of the command
|
|
152
|
-
* instead of splitting on whitespace.
|
|
153
|
-
*
|
|
154
|
-
* TODO Later: mkview that checks if a same-named view already exists.
|
|
155
|
-
*/
|
|
156
|
-
}
|