dirvi-lib 0.4.0 → 0.6.0

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.
Files changed (119) hide show
  1. package/dist/domain/posix-node.d.ts +29 -0
  2. package/dist/domain/posix-node.d.ts.map +1 -0
  3. package/dist/domain/posix-node.js +20 -0
  4. package/dist/domain/unix-path.d.ts +1 -1
  5. package/dist/domain/unix-path.js +6 -9
  6. package/dist/index.d.ts +9 -14
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +8 -13
  9. package/dist/tree-surfer/cursor.d.ts +24 -0
  10. package/dist/tree-surfer/cursor.d.ts.map +1 -0
  11. package/dist/tree-surfer/cursor.js +65 -0
  12. package/dist/tree-surfer/fold-node/fold-node.impl.d.ts +5 -0
  13. package/dist/tree-surfer/fold-node/fold-node.impl.d.ts.map +1 -0
  14. package/dist/tree-surfer/fold-node/fold-node.impl.js +143 -0
  15. package/dist/tree-surfer/fold-node/fold-node.types.d.ts +70 -0
  16. package/dist/tree-surfer/fold-node/fold-node.types.d.ts.map +1 -0
  17. package/dist/tree-surfer/fold-node/fold-node.types.js +1 -0
  18. package/dist/tree-surfer/index.d.ts +9 -0
  19. package/dist/tree-surfer/index.d.ts.map +1 -0
  20. package/dist/tree-surfer/index.js +8 -0
  21. package/dist/tree-surfer/nav-node/nav-node.impl.d.ts +6 -0
  22. package/dist/tree-surfer/nav-node/nav-node.impl.d.ts.map +1 -0
  23. package/dist/tree-surfer/nav-node/nav-node.impl.js +191 -0
  24. package/dist/tree-surfer/nav-node/nav-node.types.d.ts +42 -0
  25. package/dist/tree-surfer/nav-node/nav-node.types.d.ts.map +1 -0
  26. package/dist/tree-surfer/nav-node/nav-node.types.js +3 -0
  27. package/dist/tree-surfer/state.d.ts +19 -0
  28. package/dist/tree-surfer/state.d.ts.map +1 -0
  29. package/dist/tree-surfer/state.js +109 -0
  30. package/dist/tree-surfer/tree-node/tree-node.arb.d.ts +31 -0
  31. package/dist/tree-surfer/tree-node/tree-node.arb.d.ts.map +1 -0
  32. package/dist/tree-surfer/tree-node/tree-node.arb.js +80 -0
  33. package/dist/tree-surfer/tree-node/tree-node.impl.d.ts +14 -0
  34. package/dist/tree-surfer/tree-node/tree-node.impl.d.ts.map +1 -0
  35. package/dist/tree-surfer/tree-node/tree-node.impl.js +89 -0
  36. package/dist/tree-surfer/tree-node/tree-node.test.d.ts +2 -0
  37. package/dist/tree-surfer/tree-node/tree-node.test.d.ts.map +1 -0
  38. package/dist/tree-surfer/tree-node/tree-node.test.js +117 -0
  39. package/dist/tree-surfer/tree-node/tree-node.types.d.ts +184 -0
  40. package/dist/tree-surfer/tree-node/tree-node.types.d.ts.map +1 -0
  41. package/dist/tree-surfer/tree-node/tree-node.types.js +12 -0
  42. package/dist/tree-surfer-ui/application/index.d.ts +3 -0
  43. package/dist/tree-surfer-ui/application/index.d.ts.map +1 -0
  44. package/dist/tree-surfer-ui/application/index.js +2 -0
  45. package/dist/tree-surfer-ui/application/intent-to-effect-no-state.test.d.ts +2 -0
  46. package/dist/tree-surfer-ui/application/intent-to-effect-no-state.test.d.ts.map +1 -0
  47. package/dist/tree-surfer-ui/application/intent-to-effect-no-state.test.js +192 -0
  48. package/dist/tree-surfer-ui/application/intent-to-effect.d.ts +6 -0
  49. package/dist/tree-surfer-ui/application/intent-to-effect.d.ts.map +1 -0
  50. package/dist/tree-surfer-ui/application/intent-to-effect.js +139 -0
  51. package/dist/tree-surfer-ui/application/user-input-to-intent.d.ts +3 -0
  52. package/dist/tree-surfer-ui/application/user-input-to-intent.d.ts.map +1 -0
  53. package/dist/tree-surfer-ui/application/user-input-to-intent.js +98 -0
  54. package/dist/tree-surfer-ui/application/user-input-to-intent.test.d.ts +2 -0
  55. package/dist/tree-surfer-ui/application/user-input-to-intent.test.d.ts.map +1 -0
  56. package/dist/tree-surfer-ui/application/user-input-to-intent.test.js +118 -0
  57. package/dist/tree-surfer-ui/domain/effect.d.ts +35 -0
  58. package/dist/tree-surfer-ui/domain/effect.d.ts.map +1 -0
  59. package/dist/tree-surfer-ui/domain/index.d.ts +5 -0
  60. package/dist/tree-surfer-ui/domain/index.d.ts.map +1 -0
  61. package/dist/tree-surfer-ui/domain/index.js +4 -0
  62. package/dist/tree-surfer-ui/domain/input-state.d.ts +8 -0
  63. package/dist/tree-surfer-ui/domain/input-state.d.ts.map +1 -0
  64. package/dist/tree-surfer-ui/domain/intent.d.ts +25 -0
  65. package/dist/tree-surfer-ui/domain/intent.d.ts.map +1 -0
  66. package/dist/tree-surfer-ui/domain/user-input.d.ts +19 -0
  67. package/dist/tree-surfer-ui/domain/user-input.d.ts.map +1 -0
  68. package/package.json +3 -2
  69. package/dist/application/intent-to-effect-no-state.test.d.ts +0 -2
  70. package/dist/application/intent-to-effect-no-state.test.d.ts.map +0 -1
  71. package/dist/application/intent-to-effect-no-state.test.js +0 -178
  72. package/dist/application/intent-to-effect.d.ts +0 -8
  73. package/dist/application/intent-to-effect.d.ts.map +0 -1
  74. package/dist/application/intent-to-effect.js +0 -142
  75. package/dist/application/intent-to-effect.test-no-state.d.ts +0 -2
  76. package/dist/application/intent-to-effect.test-no-state.d.ts.map +0 -1
  77. package/dist/application/intent-to-effect.test-no-state.js +0 -178
  78. package/dist/application/user-input-to-intent.d.ts +0 -8
  79. package/dist/application/user-input-to-intent.d.ts.map +0 -1
  80. package/dist/application/user-input-to-intent.js +0 -98
  81. package/dist/application/user-input-to-intent.test.d.ts +0 -2
  82. package/dist/application/user-input-to-intent.test.d.ts.map +0 -1
  83. package/dist/application/user-input-to-intent.test.js +0 -125
  84. package/dist/domain/cursor.d.ts +0 -19
  85. package/dist/domain/cursor.d.ts.map +0 -1
  86. package/dist/domain/cursor.js +0 -46
  87. package/dist/domain/display-row.d.ts +0 -34
  88. package/dist/domain/display-row.d.ts.map +0 -1
  89. package/dist/domain/display-row.js +0 -33
  90. package/dist/domain/effect.d.ts +0 -48
  91. package/dist/domain/effect.d.ts.map +0 -1
  92. package/dist/domain/fold-node.d.ts +0 -25
  93. package/dist/domain/fold-node.d.ts.map +0 -1
  94. package/dist/domain/fold-node.js +0 -93
  95. package/dist/domain/input-state.d.ts +0 -10
  96. package/dist/domain/input-state.d.ts.map +0 -1
  97. package/dist/domain/intent.d.ts +0 -34
  98. package/dist/domain/intent.d.ts.map +0 -1
  99. package/dist/domain/navigation-node.d.ts +0 -58
  100. package/dist/domain/navigation-node.d.ts.map +0 -1
  101. package/dist/domain/navigation-node.js +0 -210
  102. package/dist/domain/state.d.ts +0 -12
  103. package/dist/domain/state.d.ts.map +0 -1
  104. package/dist/domain/state.js +0 -12
  105. package/dist/domain/unix-entry.d.ts +0 -44
  106. package/dist/domain/unix-entry.d.ts.map +0 -1
  107. package/dist/domain/unix-entry.js +0 -108
  108. package/dist/domain/user-input.d.ts +0 -27
  109. package/dist/domain/user-input.d.ts.map +0 -1
  110. package/dist/infrastructure/get-cwd.d.ts +0 -3
  111. package/dist/infrastructure/get-cwd.d.ts.map +0 -1
  112. package/dist/infrastructure/get-cwd.js +0 -15
  113. package/dist/infrastructure/get-dir-lazy-entries.d.ts +0 -6
  114. package/dist/infrastructure/get-dir-lazy-entries.d.ts.map +0 -1
  115. package/dist/infrastructure/get-dir-lazy-entries.js +0 -40
  116. /package/dist/{domain → tree-surfer-ui/domain}/effect.js +0 -0
  117. /package/dist/{domain → tree-surfer-ui/domain}/input-state.js +0 -0
  118. /package/dist/{domain → tree-surfer-ui/domain}/intent.js +0 -0
  119. /package/dist/{domain → tree-surfer-ui/domain}/user-input.js +0 -0
@@ -1,142 +0,0 @@
1
- import { View } from '../domain/state.js';
2
- import { Cursor } from '../domain/cursor.js';
3
- function dispatchAction(action) {
4
- return {
5
- effectType: 'dispatchEffectAction',
6
- action,
7
- };
8
- }
9
- // Effect derived from intent and the state.
10
- export function intentToEffect(intent, state) {
11
- switch (intent.intentType) {
12
- case 'setNormalBuffer':
13
- return normalBufferToEffectResult(intent.normalBuffer);
14
- case 'normalRight':
15
- return normalInteractRightToEffect(state);
16
- case 'normalLeft':
17
- return normalInteractLeftToEffect(state);
18
- case 'normalDown':
19
- return dispatchAction({
20
- effectActionType: 'nextEntry',
21
- });
22
- case 'normalUp':
23
- return dispatchAction({
24
- effectActionType: 'prevEntry',
25
- });
26
- case 'enterCommandLineMode':
27
- return {
28
- effectType: 'setInputState',
29
- inputState: {
30
- inputMode: 'command',
31
- commandLine: ':',
32
- },
33
- };
34
- case 'setCommandLine':
35
- return {
36
- effectType: 'setInputState',
37
- inputState: {
38
- inputMode: 'command',
39
- commandLine: intent.commandLine,
40
- },
41
- };
42
- case 'exitCommandLineMode':
43
- return {
44
- effectType: 'setInputState',
45
- inputState: {
46
- inputMode: 'normal',
47
- normalBuffer: '',
48
- },
49
- };
50
- case 'executeCommandLine':
51
- if (intent.commandLine === ':q') {
52
- return {
53
- effectType: 'quit',
54
- exitMessage: '',
55
- };
56
- }
57
- return {
58
- effectType: 'setInputState',
59
- inputState: {
60
- inputMode: 'normal',
61
- normalBuffer: '',
62
- },
63
- };
64
- }
65
- }
66
- // Sets the buffer. Three possibilities:
67
- // - New command buffer is recognized as a motion, this dispatches the
68
- // "effect action". Consumer will know to reset the input state.
69
- // - Prefix of a possible motion, updates normal buffer.
70
- // - Not a prefix, clears the buffer.
71
- function normalBufferToEffectResult(updatedNormalBuffer) {
72
- switch (updatedNormalBuffer) {
73
- case 'z':
74
- return {
75
- effectType: 'setInputState',
76
- inputState: {
77
- inputMode: 'normal',
78
- normalBuffer: updatedNormalBuffer,
79
- },
80
- };
81
- case 'za':
82
- return dispatchAction({
83
- effectActionType: 'toggleFold',
84
- });
85
- case 'zc':
86
- return dispatchAction({
87
- effectActionType: 'fold',
88
- });
89
- case 'zo':
90
- return dispatchAction({
91
- effectActionType: 'unfold',
92
- });
93
- default:
94
- return {
95
- effectType: 'setInputState',
96
- inputState: {
97
- inputMode: 'normal',
98
- normalBuffer: '',
99
- },
100
- };
101
- }
102
- }
103
- function normalInteractRightToEffect(state) {
104
- const currentEntry = View.getEntryAtCursor(state);
105
- if (currentEntry === undefined) {
106
- return undefined;
107
- }
108
- const path = Cursor.getPath(state.cursor);
109
- if (path === undefined) {
110
- return undefined;
111
- }
112
- if (currentEntry.kind === 'directory') {
113
- if (currentEntry.entries === undefined) {
114
- return {
115
- effectType: 'loadDir',
116
- path,
117
- };
118
- } else {
119
- return dispatchAction({
120
- effectActionType: 'updateDir',
121
- path,
122
- entries: undefined,
123
- });
124
- }
125
- }
126
- if (currentEntry.kind === 'file') {
127
- return {
128
- effectType: 'printFile',
129
- path,
130
- };
131
- }
132
- // TODO Later: Peeking on folds
133
- return undefined;
134
- }
135
- function normalInteractLeftToEffect(state) {
136
- if (state.cursor.parentPath.length === 0) {
137
- return undefined;
138
- }
139
- return dispatchAction({
140
- effectActionType: 'outDir',
141
- });
142
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=intent-to-effect.test-no-state.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"intent-to-effect.test-no-state.d.ts","sourceRoot":"","sources":["../../src/application/intent-to-effect.test-no-state.ts"],"names":[],"mappings":""}
@@ -1,178 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { intentToEffect } from './intent-to-effect.js';
3
- const state = {};
4
- describe('intentToEffectNoState', () => {
5
- describe('normal mode buffer', () => {
6
- it('stores z as a possible command prefix', () => {
7
- expect(
8
- intentToEffect(
9
- {
10
- intentType: 'setNormalBuffer',
11
- normalBuffer: 'z',
12
- },
13
- state,
14
- ),
15
- ).toEqual({
16
- effectType: 'setInputState',
17
- inputState: {
18
- inputMode: 'normal',
19
- normalBuffer: 'z',
20
- },
21
- });
22
- });
23
- it.each([
24
- ['za', 'toggleFold'],
25
- ['zc', 'fold'],
26
- ['zo', 'unfold'],
27
- ])(
28
- 'converts %s into a %s effect action',
29
- (normalBuffer, effectActionType) => {
30
- expect(
31
- intentToEffect(
32
- {
33
- intentType: 'setNormalBuffer',
34
- normalBuffer,
35
- },
36
- state,
37
- ),
38
- ).toEqual({
39
- effectType: 'dispatchEffectAction',
40
- action: {
41
- effectActionType,
42
- },
43
- });
44
- },
45
- );
46
- it('clears the normal buffer when the input is not a known command', () => {
47
- expect(
48
- intentToEffect(
49
- {
50
- intentType: 'setNormalBuffer',
51
- normalBuffer: 'x',
52
- },
53
- state,
54
- ),
55
- ).toEqual({
56
- effectType: 'setInputState',
57
- inputState: {
58
- inputMode: 'normal',
59
- normalBuffer: '',
60
- },
61
- });
62
- });
63
- });
64
- describe('normal mode navigation', () => {
65
- it('moves to the next entry', () => {
66
- expect(
67
- intentToEffect(
68
- {
69
- intentType: 'normalDown',
70
- },
71
- state,
72
- ),
73
- ).toEqual({
74
- effectType: 'dispatchEffectAction',
75
- action: {
76
- effectActionType: 'nextEntry',
77
- },
78
- });
79
- });
80
- it('moves to the previous entry', () => {
81
- expect(
82
- intentToEffect(
83
- {
84
- intentType: 'normalUp',
85
- },
86
- state,
87
- ),
88
- ).toEqual({
89
- effectType: 'dispatchEffectAction',
90
- action: {
91
- effectActionType: 'prevEntry',
92
- },
93
- });
94
- });
95
- });
96
- describe('command-line mode', () => {
97
- it('enters command-line mode', () => {
98
- expect(
99
- intentToEffect(
100
- {
101
- intentType: 'enterCommandLineMode',
102
- },
103
- state,
104
- ),
105
- ).toEqual({
106
- effectType: 'setInputState',
107
- inputState: {
108
- inputMode: 'command',
109
- commandLine: ':',
110
- },
111
- });
112
- });
113
- it('updates the command line', () => {
114
- expect(
115
- intentToEffect(
116
- {
117
- intentType: 'setCommandLine',
118
- commandLine: ':w',
119
- },
120
- state,
121
- ),
122
- ).toEqual({
123
- effectType: 'setInputState',
124
- inputState: {
125
- inputMode: 'command',
126
- commandLine: ':w',
127
- },
128
- });
129
- });
130
- it('exits command-line mode', () => {
131
- expect(
132
- intentToEffect(
133
- {
134
- intentType: 'exitCommandLineMode',
135
- },
136
- state,
137
- ),
138
- ).toEqual({
139
- effectType: 'setInputState',
140
- inputState: {
141
- inputMode: 'normal',
142
- normalBuffer: '',
143
- },
144
- });
145
- });
146
- it('returns to normal mode after executing a gibberish command line', () => {
147
- expect(
148
- intentToEffect(
149
- {
150
- intentType: 'executeCommandLine',
151
- commandLine: ':sijbas',
152
- },
153
- state,
154
- ),
155
- ).toEqual({
156
- effectType: 'setInputState',
157
- inputState: {
158
- inputMode: 'normal',
159
- normalBuffer: '',
160
- },
161
- });
162
- });
163
- it('quits when the :q command is executed', () => {
164
- expect(
165
- intentToEffect(
166
- {
167
- intentType: 'executeCommandLine',
168
- commandLine: ':q',
169
- },
170
- state,
171
- ),
172
- ).toEqual({
173
- effectType: 'quit',
174
- exitMessage: '',
175
- });
176
- });
177
- });
178
- });
@@ -1,8 +0,0 @@
1
- import { UserInput } from '../domain/user-input.js';
2
- import { InputState } from '../domain/input-state.js';
3
- import { Intent } from '../domain/intent.js';
4
- export declare function userInputToIntent(
5
- userInput: UserInput,
6
- inputState: InputState,
7
- ): Intent | undefined;
8
- //# sourceMappingURL=user-input-to-intent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"user-input-to-intent.d.ts","sourceRoot":"","sources":["../../src/application/user-input-to-intent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,UAAU,GACrB,MAAM,GAAG,SAAS,CAQpB"}
@@ -1,98 +0,0 @@
1
- // Derive the intent from the user input and the current input state.
2
- export function userInputToIntent(userInput, inputState) {
3
- switch (inputState.inputMode) {
4
- case 'normal':
5
- return normalUserInputToIntent(userInput, inputState.normalBuffer);
6
- case 'command':
7
- return commandUserInputToIntent(userInput, inputState.commandLine);
8
- }
9
- }
10
- function normalUserInputToIntent(userInput, normalBuffer) {
11
- if (userInput.userInputType === 'esc') {
12
- return {
13
- intentType: 'setNormalBuffer',
14
- normalBuffer: '',
15
- };
16
- }
17
- if (userInput.userInputType === 'character') {
18
- return normalCharacterToIntent(userInput.string, normalBuffer);
19
- }
20
- switch (userInput.userInputType) {
21
- case 'rightArrow':
22
- return {
23
- intentType: 'normalRight',
24
- };
25
- case 'leftArrow':
26
- return {
27
- intentType: 'normalLeft',
28
- };
29
- case 'downArrow':
30
- return {
31
- intentType: 'normalDown',
32
- };
33
- case 'upArrow':
34
- return {
35
- intentType: 'normalUp',
36
- };
37
- }
38
- }
39
- function normalCharacterToIntent(character, normalBuffer) {
40
- if (normalBuffer === '') {
41
- switch (character) {
42
- case 'l':
43
- return {
44
- intentType: 'normalRight',
45
- };
46
- case 'h':
47
- return {
48
- intentType: 'normalLeft',
49
- };
50
- case 'j':
51
- return {
52
- intentType: 'normalDown',
53
- };
54
- case 'k':
55
- return {
56
- intentType: 'normalUp',
57
- };
58
- case ':':
59
- return {
60
- intentType: 'enterCommandLineMode',
61
- };
62
- }
63
- }
64
- return {
65
- intentType: 'setNormalBuffer',
66
- normalBuffer: normalBuffer + character,
67
- };
68
- }
69
- function commandUserInputToIntent(userInput, commandLine) {
70
- if (userInput.userInputType === 'esc') {
71
- return {
72
- intentType: 'exitCommandLineMode',
73
- };
74
- }
75
- if (userInput.userInputType === 'enter') {
76
- return {
77
- intentType: 'executeCommandLine',
78
- commandLine: commandLine,
79
- };
80
- }
81
- if (userInput.userInputType === 'backspace') {
82
- if (commandLine.length < 2) {
83
- return {
84
- intentType: 'exitCommandLineMode',
85
- };
86
- }
87
- return {
88
- intentType: 'setCommandLine',
89
- commandLine: commandLine.slice(0, -1),
90
- };
91
- }
92
- if (userInput.userInputType === 'character') {
93
- return {
94
- intentType: 'setCommandLine',
95
- commandLine: commandLine + userInput.string,
96
- };
97
- }
98
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=user-input-to-intent.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"user-input-to-intent.test.d.ts","sourceRoot":"","sources":["../../src/application/user-input-to-intent.test.ts"],"names":[],"mappings":""}
@@ -1,125 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { userInputToIntent } from './user-input-to-intent.js';
3
- function normalInputState(normalBuffer = '') {
4
- return {
5
- inputMode: 'normal',
6
- normalBuffer,
7
- };
8
- }
9
- function commandInputState(commandLine = ':') {
10
- return {
11
- inputMode: 'command',
12
- commandLine,
13
- };
14
- }
15
- describe('userInputToIntent', () => {
16
- describe('normal mode', () => {
17
- it.each([
18
- ['l', { intentType: 'normalRight' }],
19
- ['h', { intentType: 'normalLeft' }],
20
- ['j', { intentType: 'normalDown' }],
21
- ['k', { intentType: 'normalUp' }],
22
- [':', { intentType: 'enterCommandLineMode' }],
23
- ])('converts "%s" to the expected intent', (character, expected) => {
24
- const userInput = {
25
- userInputType: 'character',
26
- string: character,
27
- };
28
- expect(userInputToIntent(userInput, normalInputState())).toEqual(
29
- expected,
30
- );
31
- });
32
- it('adds an unrecognized character to the normal buffer', () => {
33
- const userInput = {
34
- userInputType: 'character',
35
- string: 'g',
36
- };
37
- expect(userInputToIntent(userInput, normalInputState())).toEqual({
38
- intentType: 'setNormalBuffer',
39
- normalBuffer: 'g',
40
- });
41
- });
42
- it('appends a character to an existing normal buffer', () => {
43
- const userInput = {
44
- userInputType: 'character',
45
- string: 'g',
46
- };
47
- expect(userInputToIntent(userInput, normalInputState('2'))).toEqual({
48
- intentType: 'setNormalBuffer',
49
- normalBuffer: '2g',
50
- });
51
- });
52
- it('clears the normal buffer when Escape is pressed', () => {
53
- const userInput = {
54
- userInputType: 'esc',
55
- };
56
- expect(userInputToIntent(userInput, normalInputState('gg'))).toEqual({
57
- intentType: 'setNormalBuffer',
58
- normalBuffer: '',
59
- });
60
- });
61
- it.each([
62
- ['rightArrow', 'normalRight'],
63
- ['leftArrow', 'normalLeft'],
64
- ['downArrow', 'normalDown'],
65
- ['upArrow', 'normalUp'],
66
- ])('converts %s to %s', (userInputType, intentType) => {
67
- const userInput = {
68
- userInputType,
69
- };
70
- expect(userInputToIntent(userInput, normalInputState())).toEqual({
71
- intentType,
72
- });
73
- });
74
- it('does not enter command-line mode when the normal buffer is non-empty', () => {
75
- const userInput = {
76
- userInputType: 'character',
77
- string: ':',
78
- };
79
- expect(userInputToIntent(userInput, normalInputState('g'))).toEqual({
80
- intentType: 'setNormalBuffer',
81
- normalBuffer: 'g:',
82
- });
83
- });
84
- });
85
- describe('command-line mode', () => {
86
- it('appends a character to the command line', () => {
87
- const userInput = {
88
- userInputType: 'character',
89
- string: 'w',
90
- };
91
- expect(userInputToIntent(userInput, commandInputState(':'))).toEqual({
92
- intentType: 'setCommandLine',
93
- commandLine: ':w',
94
- });
95
- });
96
- it('executes the command line when Enter is pressed', () => {
97
- const userInput = {
98
- userInputType: 'enter',
99
- };
100
- expect(userInputToIntent(userInput, commandInputState(':w'))).toEqual({
101
- intentType: 'executeCommandLine',
102
- commandLine: ':w',
103
- });
104
- });
105
- it('exits command-line mode when Escape is pressed', () => {
106
- const userInput = {
107
- userInputType: 'esc',
108
- };
109
- expect(userInputToIntent(userInput, commandInputState(':w'))).toEqual({
110
- intentType: 'exitCommandLineMode',
111
- });
112
- });
113
- it.each(['rightArrow', 'leftArrow', 'downArrow', 'upArrow'])(
114
- 'ignores %s in command-line mode',
115
- (userInputType) => {
116
- const userInput = {
117
- userInputType,
118
- };
119
- expect(
120
- userInputToIntent(userInput, commandInputState()),
121
- ).toBeUndefined();
122
- },
123
- );
124
- });
125
- });
@@ -1,19 +0,0 @@
1
- import { UnixEntryName, UnixEntryPath } from './unix-entry.js';
2
- import { DisplayRow } from './display-row.js';
3
- export type Cursor =
4
- | {
5
- kind: 'entry';
6
- parentPath: UnixEntryPath;
7
- entryName: UnixEntryName;
8
- }
9
- | {
10
- kind: 'fold';
11
- parentPath: UnixEntryPath;
12
- };
13
- export declare const Cursor: {
14
- equal(left: Cursor, right: Cursor): boolean;
15
- matchesDisplayRow(cursor: Cursor, row: DisplayRow): boolean;
16
- fromDisplayRow(row: DisplayRow): Cursor;
17
- getPath(cursor: Cursor): UnixEntryPath | undefined;
18
- };
19
- //# sourceMappingURL=cursor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../src/domain/cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,MAAM,MAAM,GACd;IACE,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,aAAa,CAAC;IAC1B,SAAS,EAAE,aAAa,CAAC;CAC1B,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,aAAa,CAAC;CAC3B,CAAC;AAEN,eAAO,MAAM,MAAM;gBACL,MAAM,SAAS,MAAM,GAAG,OAAO;8BAgBjB,MAAM,OAAO,UAAU,GAAG,OAAO;wBAevC,UAAU,GAAG,MAAM;oBAevB,MAAM,GAAG,aAAa,GAAG,SAAS;CAOnD,CAAC"}
@@ -1,46 +0,0 @@
1
- import { UnixEntryPath } from './unix-entry.js';
2
- export const Cursor = {
3
- equal(left, right) {
4
- if (left.kind !== right.kind) {
5
- return false;
6
- }
7
- if (!UnixEntryPath.equal(left.parentPath, right.parentPath)) {
8
- return false;
9
- }
10
- if (left.kind === 'entry' && right.kind === 'entry') {
11
- return left.entryName === right.entryName;
12
- }
13
- return true;
14
- },
15
- matchesDisplayRow(cursor, row) {
16
- if (cursor.kind === 'entry' && row.kind === 'entry') {
17
- return (
18
- UnixEntryPath.equal(cursor.parentPath, row.parentPath) &&
19
- cursor.entryName === row.entry.name
20
- );
21
- }
22
- if (cursor.kind === 'fold' && row.kind === 'fold') {
23
- return UnixEntryPath.equal(cursor.parentPath, row.parentPath);
24
- }
25
- return false;
26
- },
27
- fromDisplayRow(row) {
28
- if (row.kind === 'entry') {
29
- return {
30
- kind: 'entry',
31
- parentPath: row.parentPath,
32
- entryName: row.entry.name,
33
- };
34
- }
35
- return {
36
- kind: 'fold',
37
- parentPath: row.parentPath,
38
- };
39
- },
40
- getPath(cursor) {
41
- if (cursor.kind === 'fold') {
42
- return undefined;
43
- }
44
- return [...cursor.parentPath, cursor.entryName];
45
- },
46
- };
@@ -1,34 +0,0 @@
1
- import { UnixEntry, UnixEntryName, UnixEntryPath } from './unix-entry.js';
2
- import type { UnixPath } from './unix-path.js';
3
- export type DisplayEntry =
4
- | {
5
- kind: 'file';
6
- name: UnixEntryName;
7
- }
8
- | {
9
- kind: 'symlink';
10
- name: UnixEntryName;
11
- target: UnixPath;
12
- }
13
- | {
14
- kind: 'directory';
15
- name: UnixEntryName;
16
- };
17
- export declare const DisplayEntry: {
18
- fromUnixEntry(entry: UnixEntry): DisplayEntry;
19
- };
20
- export type DisplayRow =
21
- | {
22
- kind: 'entry';
23
- parentPath: UnixEntryPath;
24
- entry: DisplayEntry;
25
- }
26
- | {
27
- kind: 'fold';
28
- parentPath: UnixEntryPath;
29
- entryNames: UnixEntryName[];
30
- };
31
- export declare const DisplayRow: {
32
- equal(firstRow: DisplayRow, secondRow: DisplayRow): boolean;
33
- };
34
- //# sourceMappingURL=display-row.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"display-row.d.ts","sourceRoot":"","sources":["../../src/domain/display-row.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,MAAM,YAAY,GACpB;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;CACrB,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,QAAQ,CAAC;CAClB,GACD;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEN,eAAO,MAAM,YAAY;yBACF,SAAS,GAAG,YAAY;CAU9C,CAAC;AAEF,MAAM,MAAM,UAAU,GAClB;IACE,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,aAAa,CAAC;IAC1B,KAAK,EAAE,YAAY,CAAC;CACrB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,aAAa,CAAC;IAC1B,UAAU,EAAE,aAAa,EAAE,CAAC;CAC7B,CAAC;AAEN,eAAO,MAAM,UAAU;oBACL,UAAU,aAAa,UAAU,GAAG,OAAO;CAqB5D,CAAC"}