dirvi-lib 0.11.0-beta.4 → 0.11.0-beta.5

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.
@@ -1,4 +1,4 @@
1
- import { parseCommand } from './parse-command.js';
1
+ import { parseExCommand } from './parse-ex-command.js';
2
2
  import { parseNormalCommand } from './parse-normal-command.js';
3
3
  export function createIntentToEffect(stateApi, cursorApi, treeNodeApi) {
4
4
  return (intent, state) => {
@@ -42,7 +42,7 @@ export function createIntentToEffect(stateApi, cursorApi, treeNodeApi) {
42
42
  },
43
43
  };
44
44
  case 'executeCommandLine':
45
- return (parseCommand(intent.commandLine) ?? {
45
+ return (parseExCommand(intent.commandLine) ?? {
46
46
  effectType: 'setInputState',
47
47
  inputState: {
48
48
  inputMode: 'normal',
@@ -0,0 +1,32 @@
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, and all consecutive leading `:`
7
+ * characters are removed before parsing. The remaining text is split on one or
8
+ * more whitespace characters:
9
+ *
10
+ * - The first token is treated as the command name.
11
+ * - All remaining tokens are passed to the command-specific parser as
12
+ * `commandArgs`.
13
+ *
14
+ * Parsing is token-based and does not support quoted or escaped arguments.
15
+ * Consequently, whitespace within an argument cannot currently be preserved.
16
+ * Command-specific parsers are responsible for validating their arguments.
17
+ *
18
+ * An empty command line produces `undefined`. An unknown command produces an
19
+ * `unrecognizedCommand` effect containing the original `commandLine`.
20
+ *
21
+ * Command parsing is independent of the concrete tree-node value type, but the
22
+ * generic parameters allow its result to compose with the application's
23
+ * `Effect<Id, Value>` pipeline.
24
+ *
25
+ * @typeParam Id - The sibling-unique tree-node ID type.
26
+ * @typeParam Value - Application-owned data stored in each tree node.
27
+ * @param commandLine - The raw Ex command line, optionally prefixed with one
28
+ * or more `:` characters.
29
+ * @returns The parsed application effect, or `undefined` for an empty command.
30
+ */
31
+ export declare function parseExCommand<Id extends SerializableKey, Value>(commandLine: string): Effect<Id, Value> | undefined;
32
+ //# 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;AAmKjD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,cAAc,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,EAC9D,WAAW,EAAE,MAAM,GAClB,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,SAAS,CA4D/B"}
@@ -1,5 +1,48 @@
1
1
  const DEFAULT_VIEW_NAME = 'default';
2
2
  const DEFAULT_FOLD_TREE_NAME = 'default';
3
+ function parseAppCommand(commandArgs) {
4
+ const [firstArgument, ...remainingArguments] = commandArgs;
5
+ switch (firstArgument) {
6
+ case 'list':
7
+ return commandArgs.length === 1
8
+ ? {
9
+ effectType: 'listApps',
10
+ }
11
+ : {
12
+ effectType: 'unrecognizedCommand',
13
+ commandLine: `app ${commandArgs.join(' ')}`,
14
+ };
15
+ case 'open':
16
+ case 'switch': {
17
+ const [appId, input] = remainingArguments;
18
+ if (appId === undefined || remainingArguments.length > 2) {
19
+ return {
20
+ effectType: 'unrecognizedCommand',
21
+ commandLine: `app ${commandArgs.join(' ')}`,
22
+ };
23
+ }
24
+ return {
25
+ effectType: 'switchApp',
26
+ appId,
27
+ input,
28
+ };
29
+ }
30
+ default: {
31
+ if (firstArgument === undefined || remainingArguments.length > 1) {
32
+ return {
33
+ effectType: 'unrecognizedCommand',
34
+ commandLine: `app ${commandArgs.join(' ')}`,
35
+ };
36
+ }
37
+ const input = remainingArguments[0];
38
+ return {
39
+ effectType: 'switchApp',
40
+ appId: firstArgument,
41
+ input,
42
+ };
43
+ }
44
+ }
45
+ }
3
46
  function parseFoldCommand(commandArgs) {
4
47
  const [subcommand, name] = commandArgs;
5
48
  switch (subcommand) {
@@ -96,17 +139,35 @@ function parseFoldCommand(commandArgs) {
96
139
  }
97
140
  }
98
141
  /**
99
- * Parses a command-line command into an application effect.
142
+ * Parses a Vim-style Ex command line into an application effect.
143
+ *
144
+ * Leading and trailing whitespace is removed, and all consecutive leading `:`
145
+ * characters are removed before parsing. The remaining text is split on one or
146
+ * more whitespace characters:
147
+ *
148
+ * - The first token is treated as the command name.
149
+ * - All remaining tokens are passed to the command-specific parser as
150
+ * `commandArgs`.
151
+ *
152
+ * Parsing is token-based and does not support quoted or escaped arguments.
153
+ * Consequently, whitespace within an argument cannot currently be preserved.
154
+ * Command-specific parsers are responsible for validating their arguments.
155
+ *
156
+ * An empty command line produces `undefined`. An unknown command produces an
157
+ * `unrecognizedCommand` effect containing the original `commandLine`.
100
158
  *
101
159
  * Command parsing is independent of the concrete tree-node value type, but the
102
160
  * generic parameters allow its result to compose with the application's
103
- * Effect<Id, Value> pipeline.
161
+ * `Effect<Id, Value>` pipeline.
104
162
  *
105
163
  * @typeParam Id - The sibling-unique tree-node ID type.
106
164
  * @typeParam Value - Application-owned data stored in each tree node.
165
+ * @param commandLine - The raw Ex command line, optionally prefixed with one
166
+ * or more `:` characters.
167
+ * @returns The parsed application effect, or `undefined` for an empty command.
107
168
  */
108
- export function parseCommand(commandLine) {
109
- const command = commandLine.trim().replace(/^:/, '');
169
+ export function parseExCommand(commandLine) {
170
+ const command = commandLine.trim().replace(/^:+/, '');
110
171
  if (command === '') {
111
172
  return undefined;
112
173
  }
@@ -117,6 +178,8 @@ export function parseCommand(commandLine) {
117
178
  effectType: 'quit',
118
179
  exitMessage: '',
119
180
  };
181
+ case 'app':
182
+ return parseAppCommand(commandArgs);
120
183
  case 'fold':
121
184
  return parseFoldCommand(commandArgs);
122
185
  case 'evlp':
@@ -1,12 +1,24 @@
1
1
  import type { InputModeState } from './input-mode-state.js';
2
2
  import type { SerializableKey, TreeNode } from '../../trees/index.js';
3
3
  /**
4
- * An effect produced by interpreting an intent against the current state.
4
+ * An effect is some execution to be done in `App`, that could affect any part
5
+ * of dirvi.
6
+ *
7
+ * It is produced by interpreting an intent against the current state.
5
8
  *
6
9
  * @typeParam Id - The sibling-unique tree-node ID type.
7
10
  * @typeParam Value - Application-owned data stored in each tree node.
8
11
  */
9
12
  export type Effect<Id extends SerializableKey, Value> = Readonly<{
13
+ effectType: 'quit';
14
+ exitMessage: string;
15
+ }> | Readonly<{
16
+ effectType: 'listApps';
17
+ }> | Readonly<{
18
+ effectType: 'switchApp';
19
+ appId: string;
20
+ input: string | undefined;
21
+ }> | Readonly<{
10
22
  effectType: 'dispatchEffectAction';
11
23
  action: EffectAction<Id, Value>;
12
24
  }> | Readonly<{
@@ -23,9 +35,6 @@ export type Effect<Id extends SerializableKey, Value> = Readonly<{
23
35
  effectType: 'emitVisibleLeavesPaths';
24
36
  }> | Readonly<{
25
37
  effectType: 'listFolds';
26
- }> | Readonly<{
27
- effectType: 'quit';
28
- exitMessage: string;
29
38
  }> | Readonly<{
30
39
  effectType: 'setInputState';
31
40
  inputState: InputModeState;
@@ -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;;;;;GAKG;AACH,MAAM,MAAM,MAAM,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,IAChD,QAAQ,CAAC;IACP,UAAU,EAAE,sBAAsB,CAAC;IACnC,MAAM,EAAE,YAAY,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;CACjC,CAAC,GACF,QAAQ,CAAC;IACP,UAAU,EAAE,mBAAmB,CAAC;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B,CAAC,GACF,QAAQ,CAAC;IACP,gBAAgB,EAAE,WAAW,CAAC;CAC/B,CAAC,GACF,QAAQ,CAAC;IACP,gBAAgB,EAAE,kBAAkB,CAAC;IACrC,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC;IACpB,OAAO,EAAE,SAAS,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC;CAChD,CAAC,GACF,QAAQ,CAAC;IACP,gBAAgB,EAAE,kBAAkB,CAAC;CACtC,CAAC,GACF,QAAQ,CAAC;IACP,gBAAgB,EAAE,eAAe,CAAC;IAClC,QAAQ,EAAE,iBAAiB,CAAC;CAC7B,CAAC,GACF,QAAQ,CAAC;IACP,gBAAgB,EAAE,oBAAoB,CAAC;IACvC,QAAQ,EAAE,iBAAiB,CAAC;CAC7B,CAAC,GACF,QAAQ,CAAC;IACP,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B,CAAC,GACF,QAAQ,CAAC;IACP,gBAAgB,EAAE,QAAQ,CAAC;IAC3B,QAAQ,EAAE,iBAAiB,CAAC;CAC7B,CAAC,GACF,QAAQ,CAAC;IACP,gBAAgB,EAAE,YAAY,CAAC;IAC/B,QAAQ,EAAE,iBAAiB,CAAC;CAC7B,CAAC,GACF,QAAQ,CAAC;IACP,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,GACF,QAAQ,CAAC;IACP,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirvi-lib",
3
- "version": "0.11.0-beta.4",
3
+ "version": "0.11.0-beta.5",
4
4
  "description": "Dependency for dirvi.",
5
5
  "license": "LGPL-3.0-or-later",
6
6
  "type": "module",
@@ -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"}