diff --git a/package.json b/package.json index caeb790..3a14d83 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@testing-library/svelte": "^3.2.2", "@tsconfig/svelte": "^3.0.0", "@types/jest": "^29.2.0", + "@types/node": "^18.11.9", "@typescript-eslint/eslint-plugin": "^5.40.0", "@typescript-eslint/parser": "^5.40.0", "babel-jest": "^29.2.2", diff --git a/src/__tests__/cases.ts b/src/__tests__/cases.ts index f327789..ab8c04a 100644 --- a/src/__tests__/cases.ts +++ b/src/__tests__/cases.ts @@ -30,6 +30,7 @@ export const sh = [ ] const ENTER_VI = [...'vi'.split(''), ENTER] +const ENTER_VI_FILE = (file: string) => [...'vi '.split(''), ...file.split(''), ENTER] export const vi = [ [...ENTER_VI, 'i', ...'hello'.split('')], @@ -66,4 +67,12 @@ export const vi = [ [...ENTER_VI, 'i', ...fill(5, ENTER), ...fill(5, UP)], [...ENTER_VI, 'i', ...fill(5, ENTER), ...fill(3, BACK)], [...ENTER_VI, 'i', ...fill(5, ENTER), ...fill(5, BACK)], + [...ENTER_VI, 'i', ...'hello world'.split(''), '`', ':', 'w', ENTER], + [...ENTER_VI, 'i', ...'hello world'.split(''), '`', ':', ...'wq'.split(''), ENTER], + [...ENTER_VI, 'i', ...'hello world'.split(''), '`', ':', 'q', ENTER], + [...ENTER_VI, 'i', ...'hello world'.split(''), '`', ':', 'q', '!', ENTER], + [...ENTER_VI_FILE('test'), 'i', ...'hello world'.split(''), '`', ':', 'w', ENTER], + [...ENTER_VI_FILE('test'), 'i', ...'hello world'.split(''), '`', ':', ...'wq'.split(''), ENTER], + [...ENTER_VI_FILE('test'), 'i', ...'hello world'.split(''), '`', ':', 'q', ENTER], + [...ENTER_VI_FILE('test'), 'i', ...'hello world'.split(''), '`', ':', 'q', '!', ENTER], ] diff --git a/src/__tests__/state/__snapshots__/vi.test.ts.snap b/src/__tests__/state/__snapshots__/vi.test.ts.snap index b1484ee..0447a21 100644 --- a/src/__tests__/state/__snapshots__/vi.test.ts.snap +++ b/src/__tests__/state/__snapshots__/vi.test.ts.snap @@ -1,5 +1,191 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`vi testihello world\`:q! 1`] = ` +{ + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "", + }, + "CONTROL_DOWN": false, + "DOWN_MAPPING": [Function], + "HISTORY_INDEX": -1, + "NAME": 0, + "OLD_COMMANDS": [ + { + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "vi test", + }, + "PWD": "/home/guest", + "STDOUT": "", + "USER": "guest", + }, + ], + "PWD": "/home/guest", + "UP_MAPPING": [Function], + "USER": "guest", +} +`; + +exports[`vi testihello world\`:q! 2`] = `"{"home":{"guest":{".bashrc":"#!/usr/sh",".history":""},"root":{}}}"`; + +exports[`vi testihello world\`:q! 3`] = `"{"PWD":"/home/guest","HOME":"/home/guest"}"`; + +exports[`vi testihello world\`:q 1`] = ` +{ + "BUFFER": { + "BUFFER_POST": [], + "BUFFER_PRE": [], + "LINE": { + "CARET": "d", + "CARET_WIDTH": 1, + "EOL": false, + "POSTCARET": "", + "PRECARET": "hello worl", + }, + }, + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "", + }, + "CONTROL_DOWN": false, + "COORDS": { + "x": 10, + "y": 0, + }, + "DOWN_MAPPING": [Function], + "FILE_NAME": "/home/guest/test", + "HISTORY_INDEX": -1, + "MESSAGE": "No write since last change", + "MODE": 2, + "NAME": 1, + "OLD_COMMANDS": [ + { + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "vi test", + }, + "PWD": "/home/guest", + "STDOUT": "", + "USER": "guest", + }, + ], + "PWD": "/home/guest", + "REGISTERS": {}, + "UP_MAPPING": [Function], + "USER": "guest", +} +`; + +exports[`vi testihello world\`:q 2`] = `"{"home":{"guest":{".bashrc":"#!/usr/sh",".history":""},"root":{}}}"`; + +exports[`vi testihello world\`:q 3`] = `"{"PWD":"/home/guest","HOME":"/home/guest"}"`; + +exports[`vi testihello world\`:w 1`] = ` +{ + "BUFFER": { + "BUFFER_POST": [], + "BUFFER_PRE": [], + "LINE": { + "CARET": "d", + "CARET_WIDTH": 1, + "EOL": false, + "POSTCARET": "", + "PRECARET": "hello worl", + }, + }, + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "", + }, + "CONTROL_DOWN": false, + "COORDS": { + "x": 10, + "y": 0, + }, + "DOWN_MAPPING": [Function], + "FILE_NAME": "/home/guest/test", + "HISTORY_INDEX": -1, + "MESSAGE": null, + "MODE": 0, + "NAME": 1, + "OLD_COMMANDS": [ + { + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "vi test", + }, + "PWD": "/home/guest", + "STDOUT": "", + "USER": "guest", + }, + ], + "PWD": "/home/guest", + "REGISTERS": {}, + "UP_MAPPING": [Function], + "USER": "guest", +} +`; + +exports[`vi testihello world\`:w 2`] = `"{"home":{"guest":{".bashrc":"#!/usr/sh",".history":"","test":"hello world"},"root":{}}}"`; + +exports[`vi testihello world\`:w 3`] = `"{"PWD":"/home/guest","HOME":"/home/guest"}"`; + +exports[`vi testihello world\`:wq 1`] = ` +{ + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "", + }, + "CONTROL_DOWN": false, + "DOWN_MAPPING": [Function], + "HISTORY_INDEX": -1, + "NAME": 0, + "OLD_COMMANDS": [ + { + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "vi test", + }, + "PWD": "/home/guest", + "STDOUT": "", + "USER": "guest", + }, + ], + "PWD": "/home/guest", + "UP_MAPPING": [Function], + "USER": "guest", +} +`; + +exports[`vi testihello world\`:wq 2`] = `"{"home":{"guest":{".bashrc":"#!/usr/sh",".history":"","test":"hello world"},"root":{}}}"`; + +exports[`vi testihello world\`:wq 3`] = `"{"PWD":"/home/guest","HOME":"/home/guest"}"`; + exports[`vii 1`] = ` { "BUFFER": { @@ -31,6 +217,7 @@ exports[`vii 1`] = ` "DOWN_MAPPING": [Function], "FILE_NAME": null, "HISTORY_INDEX": -1, + "MESSAGE": null, "MODE": 1, "NAME": 1, "OLD_COMMANDS": [ @@ -48,6 +235,7 @@ exports[`vii 1`] = ` }, ], "PWD": "/home/guest", + "REGISTERS": {}, "UP_MAPPING": [Function], "USER": "guest", } @@ -85,6 +273,7 @@ exports[`vii 1`] = ` "DOWN_MAPPING": [Function], "FILE_NAME": null, "HISTORY_INDEX": -1, + "MESSAGE": null, "MODE": 1, "NAME": 1, "OLD_COMMANDS": [ @@ -102,6 +291,7 @@ exports[`vii 1`] = ` }, ], "PWD": "/home/guest", + "REGISTERS": {}, "UP_MAPPING": [Function], "USER": "guest", } @@ -146,6 +336,7 @@ exports[`viiArrowUpArrowUpArrowUp 1`] "DOWN_MAPPING": [Function], "FILE_NAME": null, "HISTORY_INDEX": -1, + "MESSAGE": null, "MODE": 1, "NAME": 1, "OLD_COMMANDS": [ @@ -163,6 +354,7 @@ exports[`viiArrowUpArrowUpArrowUp 1`] }, ], "PWD": "/home/guest", + "REGISTERS": {}, "UP_MAPPING": [Function], "USER": "guest", } @@ -206,6 +398,7 @@ exports[`viiArrowUpArrowUpArrowUpArrow "DOWN_MAPPING": [Function], "FILE_NAME": null, "HISTORY_INDEX": -1, + "MESSAGE": null, "MODE": 1, "NAME": 1, "OLD_COMMANDS": [ @@ -223,6 +416,7 @@ exports[`viiArrowUpArrowUpArrowUpArrow }, ], "PWD": "/home/guest", + "REGISTERS": {}, "UP_MAPPING": [Function], "USER": "guest", } @@ -260,6 +454,7 @@ exports[`viihello 1`] = ` "DOWN_MAPPING": [Function], "FILE_NAME": null, "HISTORY_INDEX": -1, + "MESSAGE": null, "MODE": 1, "NAME": 1, "OLD_COMMANDS": [ @@ -277,6 +472,7 @@ exports[`viihello 1`] = ` }, ], "PWD": "/home/guest", + "REGISTERS": {}, "UP_MAPPING": [Function], "USER": "guest", } @@ -316,6 +512,7 @@ exports[`viihello world 1`] = ` "DOWN_MAPPING": [Function], "FILE_NAME": null, "HISTORY_INDEX": -1, + "MESSAGE": null, "MODE": 1, "NAME": 1, "OLD_COMMANDS": [ @@ -333,6 +530,7 @@ exports[`viihello world 1`] = ` }, ], "PWD": "/home/guest", + "REGISTERS": {}, "UP_MAPPING": [Function], "USER": "guest", } @@ -342,6 +540,99 @@ exports[`viihello world 2`] = `"{"home":{"guest":{".bashrc exports[`viihello world 3`] = `"{"PWD":"/home/guest","HOME":"/home/guest"}"`; +exports[`viihello world\`:q! 1`] = ` +{ + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "", + }, + "CONTROL_DOWN": false, + "DOWN_MAPPING": [Function], + "HISTORY_INDEX": -1, + "NAME": 0, + "OLD_COMMANDS": [ + { + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "vi", + }, + "PWD": "/home/guest", + "STDOUT": "", + "USER": "guest", + }, + ], + "PWD": "/home/guest", + "UP_MAPPING": [Function], + "USER": "guest", +} +`; + +exports[`viihello world\`:q! 2`] = `"{"home":{"guest":{".bashrc":"#!/usr/sh",".history":""},"root":{}}}"`; + +exports[`viihello world\`:q! 3`] = `"{"PWD":"/home/guest","HOME":"/home/guest"}"`; + +exports[`viihello world\`:q 1`] = ` +{ + "BUFFER": { + "BUFFER_POST": [], + "BUFFER_PRE": [], + "LINE": { + "CARET": "d", + "CARET_WIDTH": 1, + "EOL": false, + "POSTCARET": "", + "PRECARET": "hello worl", + }, + }, + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "", + }, + "CONTROL_DOWN": false, + "COORDS": { + "x": 10, + "y": 0, + }, + "DOWN_MAPPING": [Function], + "FILE_NAME": null, + "HISTORY_INDEX": -1, + "MESSAGE": "No write since last change", + "MODE": 2, + "NAME": 1, + "OLD_COMMANDS": [ + { + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "vi", + }, + "PWD": "/home/guest", + "STDOUT": "", + "USER": "guest", + }, + ], + "PWD": "/home/guest", + "REGISTERS": {}, + "UP_MAPPING": [Function], + "USER": "guest", +} +`; + +exports[`viihello world\`:q 2`] = `"{"home":{"guest":{".bashrc":"#!/usr/sh",".history":""},"root":{}}}"`; + +exports[`viihello world\`:q 3`] = `"{"PWD":"/home/guest","HOME":"/home/guest"}"`; + exports[`viihello world\`:w out\`:q 1`] = ` { "COMMAND_LINE": { @@ -379,6 +670,118 @@ exports[`viihello world\`:w out\`:q 2`] = `"{"home":{"guest exports[`viihello world\`:w out\`:q 3`] = `"{"PWD":"/home/guest","HOME":"/home/guest"}"`; +exports[`viihello world\`:w 1`] = ` +{ + "BUFFER": { + "BUFFER_POST": [], + "BUFFER_PRE": [], + "LINE": { + "CARET": "d", + "CARET_WIDTH": 1, + "EOL": false, + "POSTCARET": "", + "PRECARET": "hello worl", + }, + }, + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "", + }, + "CONTROL_DOWN": false, + "COORDS": { + "x": 10, + "y": 0, + }, + "DOWN_MAPPING": [Function], + "FILE_NAME": null, + "HISTORY_INDEX": -1, + "MESSAGE": "No file name", + "MODE": 0, + "NAME": 1, + "OLD_COMMANDS": [ + { + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "vi", + }, + "PWD": "/home/guest", + "STDOUT": "", + "USER": "guest", + }, + ], + "PWD": "/home/guest", + "REGISTERS": {}, + "UP_MAPPING": [Function], + "USER": "guest", +} +`; + +exports[`viihello world\`:w 2`] = `"{"home":{"guest":{".bashrc":"#!/usr/sh",".history":""},"root":{}}}"`; + +exports[`viihello world\`:w 3`] = `"{"PWD":"/home/guest","HOME":"/home/guest"}"`; + +exports[`viihello world\`:wq 1`] = ` +{ + "BUFFER": { + "BUFFER_POST": [], + "BUFFER_PRE": [], + "LINE": { + "CARET": "d", + "CARET_WIDTH": 1, + "EOL": false, + "POSTCARET": "", + "PRECARET": "hello worl", + }, + }, + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "", + }, + "CONTROL_DOWN": false, + "COORDS": { + "x": 10, + "y": 0, + }, + "DOWN_MAPPING": [Function], + "FILE_NAME": null, + "HISTORY_INDEX": -1, + "MESSAGE": "No write since last change", + "MODE": 2, + "NAME": 1, + "OLD_COMMANDS": [ + { + "COMMAND_LINE": { + "CARET": null, + "CARET_WIDTH": 1, + "EOL": true, + "POSTCARET": "", + "PRECARET": "vi", + }, + "PWD": "/home/guest", + "STDOUT": "", + "USER": "guest", + }, + ], + "PWD": "/home/guest", + "REGISTERS": {}, + "UP_MAPPING": [Function], + "USER": "guest", +} +`; + +exports[`viihello world\`:wq 2`] = `"{"home":{"guest":{".bashrc":"#!/usr/sh",".history":""},"root":{}}}"`; + +exports[`viihello world\`:wq 3`] = `"{"PWD":"/home/guest","HOME":"/home/guest"}"`; + exports[`viihellohello worldArrowUp 1`] = ` { "BUFFER": { @@ -409,6 +812,7 @@ exports[`viihellohello worldArrowUp 1`] = ` "DOWN_MAPPING": [Function], "FILE_NAME": null, "HISTORY_INDEX": -1, + "MESSAGE": null, "MODE": 1, "NAME": 1, "OLD_COMMANDS": [ @@ -426,6 +830,7 @@ exports[`viihellohello worldArrowUp 1`] = ` }, ], "PWD": "/home/guest", + "REGISTERS": {}, "UP_MAPPING": [Function], "USER": "guest", } @@ -463,6 +868,7 @@ exports[`viihellohello worldArrowUpArrowDown 1`] = ` "DOWN_MAPPING": [Function], "FILE_NAME": null, "HISTORY_INDEX": -1, + "MESSAGE": null, "MODE": 1, "NAME": 1, "OLD_COMMANDS": [ @@ -480,6 +886,7 @@ exports[`viihellohello worldArrowUpArrowDown 1`] = ` }, ], "PWD": "/home/guest", + "REGISTERS": {}, "UP_MAPPING": [Function], "USER": "guest", } @@ -517,6 +924,7 @@ exports[`viihello 1`] = ` "DOWN_MAPPING": [Function], "FILE_NAME": null, "HISTORY_INDEX": -1, + "MESSAGE": null, "MODE": 1, "NAME": 1, "OLD_COMMANDS": [ @@ -534,6 +942,7 @@ exports[`viihello 1`] = ` }, ], "PWD": "/home/guest", + "REGISTERS": {}, "UP_MAPPING": [Function], "USER": "guest", } @@ -571,6 +980,7 @@ exports[`viihello\` 1`] = ` "DOWN_MAPPING": [Function], "FILE_NAME": null, "HISTORY_INDEX": -1, + "MESSAGE": null, "MODE": 0, "NAME": 1, "OLD_COMMANDS": [ @@ -588,6 +998,7 @@ exports[`viihello\` 1`] = ` }, ], "PWD": "/home/guest", + "REGISTERS": {}, "UP_MAPPING": [Function], "USER": "guest", } @@ -625,6 +1036,7 @@ exports[`viihello\`:cmd 1`] = ` "DOWN_MAPPING": [Function], "FILE_NAME": null, "HISTORY_INDEX": -1, + "MESSAGE": null, "MODE": 2, "NAME": 1, "OLD_COMMANDS": [ @@ -642,6 +1054,7 @@ exports[`viihello\`:cmd 1`] = ` }, ], "PWD": "/home/guest", + "REGISTERS": {}, "UP_MAPPING": [Function], "USER": "guest", } @@ -679,6 +1092,7 @@ exports[`viihello\`:cmd 1`] = ` "DOWN_MAPPING": [Function], "FILE_NAME": null, "HISTORY_INDEX": -1, + "MESSAGE": null, "MODE": 2, "NAME": 1, "OLD_COMMANDS": [ @@ -696,6 +1110,7 @@ exports[`viihello\`:cmd 1`] = ` }, ], "PWD": "/home/guest", + "REGISTERS": {}, "UP_MAPPING": [Function], "USER": "guest", } diff --git a/src/__tests__/ui/__snapshots__/vi.test.ts.snap b/src/__tests__/ui/__snapshots__/vi.test.ts.snap index 4ca6090..6f1bb13 100644 --- a/src/__tests__/ui/__snapshots__/vi.test.ts.snap +++ b/src/__tests__/ui/__snapshots__/vi.test.ts.snap @@ -1,16 +1,40 @@ // Vitest Snapshot v1 -exports[`vii 1`] = `"
1
2
3
3,1
"`; +exports[`vi testihello world\`:q! 1`] = ` +"
guest@127.0.0.1:~/ + $ vi test
guest@127.0.0.1:~/ + $ _
" +`; + +exports[`vi testihello world\`:q 1`] = `"
1 hello world
No write since last change
: _ 1,11
"`; + +exports[`vi testihello world\`:w 1`] = `"
1 hello world
1,11
"`; + +exports[`vi testihello world\`:wq 1`] = ` +"
guest@127.0.0.1:~/ + $ vi test
guest@127.0.0.1:~/ + $ _
" +`; -exports[`vii 1`] = `"
1
1,1
"`; +exports[`vii 1`] = `"
1
2
3
3,1
"`; -exports[`viiArrowUpArrowUpArrowUp 1`] = `"
1
2
3
4
5
6
3,1
"`; +exports[`vii 1`] = `"
1
1,1
"`; -exports[`viiArrowUpArrowUpArrowUpArrowUpArrowUp 1`] = `"
1
2
3
4
5
6
1,1
"`; +exports[`viiArrowUpArrowUpArrowUp 1`] = `"
1
2
3
4
5
6
3,1
"`; -exports[`viihello 1`] = `"
1 hello
1,6
"`; +exports[`viiArrowUpArrowUpArrowUpArrowUpArrowUp 1`] = `"
1
2
3
4
5
6
1,1
"`; -exports[`viihello world 1`] = `"
1 hello
2 world
2,1
"`; +exports[`viihello 1`] = `"
1 hello
1,6
"`; + +exports[`viihello world 1`] = `"
1 hello
2 world
2,1
"`; + +exports[`viihello world\`:q! 1`] = ` +"
guest@127.0.0.1:~/ + $ vi
guest@127.0.0.1:~/ + $ _
" +`; + +exports[`viihello world\`:q 1`] = `"
1 hello world
No write since last change
: _ 1,11
"`; exports[`viihello world\`:w out\`:q 1`] = ` "
guest@127.0.0.1:~/ @@ -18,14 +42,18 @@ exports[`viihello world\`:w out\`:q 1`] = ` $ _
" `; -exports[`viihellohello worldArrowUp 1`] = `"
1 hello
2 hello world
1,6
"`; +exports[`viihello world\`:w 1`] = `"
1 hello world
No file name
1,11
"`; + +exports[`viihello world\`:wq 1`] = `"
1 hello world
No write since last change
: _ 1,11
"`; + +exports[`viihellohello worldArrowUp 1`] = `"
1 hello
2 hello world
1,6
"`; -exports[`viihellohello worldArrowUpArrowDown 1`] = `"
1 world
1,1
"`; +exports[`viihellohello worldArrowUpArrowDown 1`] = `"
1 world
1,1
"`; -exports[`viihello 1`] = `"
1 hello
1,6
"`; +exports[`viihello 1`] = `"
1 hello
1,6
"`; -exports[`viihello\` 1`] = `"
1 hello
1,5
"`; +exports[`viihello\` 1`] = `"
1 hello
1,5
"`; -exports[`viihello\`:cmd 1`] = `"
1 hello
: cmd_ 1,5
"`; +exports[`viihello\`:cmd 1`] = `"
1 hello
: cmd_ 1,5
"`; -exports[`viihello\`:cmd 1`] = `"
1 hello
: cmd_ 1,5
"`; +exports[`viihello\`:cmd 1`] = `"
1 hello
: cmd_ 1,5
"`; diff --git a/src/components/Vi.svelte b/src/components/Vi.svelte index 4a5f939..f3c9c71 100644 --- a/src/components/Vi.svelte +++ b/src/components/Vi.svelte @@ -5,6 +5,14 @@ width: 100%; } + .message { + position: fixed; + bottom: 28px; + width: 100%; + background-color: red; + color: white; + } + .buffer { display: block; } @@ -33,6 +41,7 @@ let { MODE, COMMAND_LINE, + MESSAGE, COORDS: { x, y }, BUFFER: { BUFFER_PRE, LINE, BUFFER_POST }, } = STATE as ViState @@ -51,6 +60,9 @@
{BUFFER_PRE.length + 2 + index} {line}
{/each}
+ {#if !!MESSAGE} +
{MESSAGE}
+ {/if}