@rse/ink-editor 0.0.0-stage → 0.9.1
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/.claude/CLAUDE.md +1 -0
- package/AGENTS.md +99 -0
- package/CHANGELOG.md +9 -0
- package/README.md +116 -2
- package/dst-stage1/ink-editor-cli.d.ts +2 -0
- package/dst-stage1/ink-editor-cli.js +174 -0
- package/dst-stage1/ink-editor-engine-emacs.d.ts +103 -0
- package/dst-stage1/ink-editor-engine-emacs.js +1530 -0
- package/dst-stage1/ink-editor-engine-nano.d.ts +78 -0
- package/dst-stage1/ink-editor-engine-nano.js +884 -0
- package/dst-stage1/ink-editor-engine-vim.d.ts +124 -0
- package/dst-stage1/ink-editor-engine-vim.js +2220 -0
- package/dst-stage1/ink-editor-engine-vscode.d.ts +79 -0
- package/dst-stage1/ink-editor-engine-vscode.js +850 -0
- package/dst-stage1/ink-editor-mode-emacs.d.ts +12 -0
- package/dst-stage1/ink-editor-mode-emacs.js +143 -0
- package/dst-stage1/ink-editor-mode-nano.d.ts +12 -0
- package/dst-stage1/ink-editor-mode-nano.js +140 -0
- package/dst-stage1/ink-editor-mode-vim.d.ts +12 -0
- package/dst-stage1/ink-editor-mode-vim.js +230 -0
- package/dst-stage1/ink-editor-mode-vscode.d.ts +12 -0
- package/dst-stage1/ink-editor-mode-vscode.js +133 -0
- package/dst-stage1/ink-editor-mode.d.ts +72 -0
- package/dst-stage1/ink-editor-mode.js +24 -0
- package/dst-stage1/ink-editor-syntax.d.ts +14 -0
- package/dst-stage1/ink-editor-syntax.js +149 -0
- package/dst-stage1/ink-editor-text.d.ts +38 -0
- package/dst-stage1/ink-editor-text.js +177 -0
- package/dst-stage1/ink-editor-widget.d.ts +15 -0
- package/dst-stage1/ink-editor-widget.js +132 -0
- package/dst-stage1/ink-editor.d.ts +13 -0
- package/dst-stage1/ink-editor.js +37 -0
- package/dst-stage1/tsc.tsbuildinfo +1 -0
- package/dst-stage2/ink-editor-cli.esm.js +177 -0
- package/dst-stage2/ink-editor.esm.js +5972 -0
- package/etc/c8.json +17 -0
- package/etc/eslint.mts +84 -0
- package/etc/knip.jsonc +51 -0
- package/etc/stx.conf +103 -0
- package/etc/tsc.json +29 -0
- package/etc/vite.mts +79 -0
- package/package.d/@typescript-eslint+typescript-estree+8.74.0.patch +12 -0
- package/package.d/vite+8.4.1.patch +12 -0
- package/package.json +79 -5
- package/src/ink-editor-cli.ts +200 -0
- package/src/ink-editor-engine-emacs.ts +1648 -0
- package/src/ink-editor-engine-nano.ts +978 -0
- package/src/ink-editor-engine-vim.ts +2203 -0
- package/src/ink-editor-engine-vscode.ts +938 -0
- package/src/ink-editor-mode-emacs.ts +137 -0
- package/src/ink-editor-mode-nano.ts +135 -0
- package/src/ink-editor-mode-vim.ts +223 -0
- package/src/ink-editor-mode-vscode.ts +129 -0
- package/src/ink-editor-mode.ts +137 -0
- package/src/ink-editor-syntax.ts +176 -0
- package/src/ink-editor-text.ts +205 -0
- package/src/ink-editor-widget.ts +182 -0
- package/src/ink-editor.ts +48 -0
- package/tst/ink-editor-1-vim.spec.ts +177 -0
- package/tst/ink-editor-2-emacs.spec.ts +211 -0
- package/tst/ink-editor-3-nano.spec.ts +187 -0
- package/tst/ink-editor-4-vscode.spec.ts +187 -0
- package/tst/tsc.json +27 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/*
|
|
2
|
+
** Ink-Editor -- Text Editor with Exchangeable Editing Modes for Ink
|
|
3
|
+
** Copyright (c) 2026 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
4
|
+
**
|
|
5
|
+
** Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
** a copy of this software and associated documentation files (the
|
|
7
|
+
** "Software"), to deal in the Software without restriction, including
|
|
8
|
+
** without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
** distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
** permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
** the following conditions:
|
|
12
|
+
**
|
|
13
|
+
** The above copyright notice and this permission notice shall be included
|
|
14
|
+
** in all copies or substantial portions of the Software.
|
|
15
|
+
**
|
|
16
|
+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
/* text area for Ink, driven by an editing mode, on top of the Textarea of better-ink-ui */
|
|
25
|
+
/* external dependencies */
|
|
26
|
+
import React from "react";
|
|
27
|
+
import { Box, Text, useInput, usePaste, useStdout, useWindowSize } from "ink";
|
|
28
|
+
import { Textarea, TextareaUtils, osc52 } from "better-ink-ui";
|
|
29
|
+
const h = React.createElement;
|
|
30
|
+
/* styles of the highlighting of the mode */
|
|
31
|
+
const STYLES = { highlight: { color: "black", backgroundColor: "yellow" } };
|
|
32
|
+
/* the text area widget, driven by an editing mode */
|
|
33
|
+
export function Editor(props) {
|
|
34
|
+
const [, redraw] = React.useReducer((n) => n + 1, 0);
|
|
35
|
+
const { stdout } = useStdout();
|
|
36
|
+
const { columns } = useWindowSize();
|
|
37
|
+
const width = Math.max(1, props.width ?? columns);
|
|
38
|
+
/* the wrapped rows by line of the last layout, so a layout re-wraps only the changed lines */
|
|
39
|
+
const cache = React.useMemo(() => new Map(), [width]);
|
|
40
|
+
/* the text operations of the Textarea, so the mode agrees with it on graphemes, words, and rows */
|
|
41
|
+
const ops = React.useMemo(() => ({
|
|
42
|
+
previous: TextareaUtils.previous,
|
|
43
|
+
next: TextareaUtils.next,
|
|
44
|
+
wordStart: TextareaUtils.wordStart,
|
|
45
|
+
vertical: (v, o, direction) => {
|
|
46
|
+
const cursor = TextareaUtils.cursor(v, o);
|
|
47
|
+
const rows = TextareaUtils.rows({ value: v, width, cursor, cache });
|
|
48
|
+
return TextareaUtils.vertical({ value: v, rows, cursor, direction });
|
|
49
|
+
}
|
|
50
|
+
}), [width, cache]);
|
|
51
|
+
/* the editing mode, created once and re-bound to the current properties on each rendering */
|
|
52
|
+
const ref = React.useRef(null);
|
|
53
|
+
if (ref.current === null) {
|
|
54
|
+
ref.current = props.mode(props.value, ops);
|
|
55
|
+
if (props.file)
|
|
56
|
+
ref.current.opened(props.file);
|
|
57
|
+
}
|
|
58
|
+
const mode = ref.current;
|
|
59
|
+
mode.bind({
|
|
60
|
+
ops,
|
|
61
|
+
height: props.height,
|
|
62
|
+
emit: props.onChange,
|
|
63
|
+
clip: (text) => { stdout.write(osc52(text)); },
|
|
64
|
+
host: props.host ?? null
|
|
65
|
+
});
|
|
66
|
+
mode.sync(props.value);
|
|
67
|
+
/* the highlighting of the mode, ahead of the syntax highlighting, as the first rule
|
|
68
|
+
to claim a character keeps it (keeping their identity while unchanged) */
|
|
69
|
+
const highlight = mode.highlight();
|
|
70
|
+
const syntax = props.syntax ?? null;
|
|
71
|
+
const labels = React.useMemo(() => [
|
|
72
|
+
...(highlight ? [{ pattern: highlight, label: "highlight" }] : []),
|
|
73
|
+
...(syntax ? [{ ranges: syntax }] : [])
|
|
74
|
+
], [highlight, syntax]);
|
|
75
|
+
/* on a prompt of the status line, the cursor leaves the text area: the Textarea draws
|
|
76
|
+
no cursor without focus, so then the keys and pastes are taken here instead */
|
|
77
|
+
const value = mode.value;
|
|
78
|
+
const cursor = TextareaUtils.cursor(value, mode.off);
|
|
79
|
+
const status = mode.status(cursor);
|
|
80
|
+
const focus = props.focus ?? true;
|
|
81
|
+
const prompt = status.prompt !== null;
|
|
82
|
+
const paste = mode.paste?.bind(mode);
|
|
83
|
+
useInput((input, key) => {
|
|
84
|
+
mode.key(input, key);
|
|
85
|
+
redraw();
|
|
86
|
+
}, { isActive: focus && prompt });
|
|
87
|
+
usePaste((text) => {
|
|
88
|
+
paste?.(text);
|
|
89
|
+
redraw();
|
|
90
|
+
}, { isActive: focus && prompt });
|
|
91
|
+
/* the text area, padded with filler rows below the text end */
|
|
92
|
+
const filler = mode.filler();
|
|
93
|
+
const rows = filler !== "" ? TextareaUtils.rows({ value, width, cursor, cache }).length : props.height;
|
|
94
|
+
const shown = Math.max(1, Math.min(rows, props.height));
|
|
95
|
+
const area = h(Box, { height: shown, flexShrink: 0, flexDirection: "column" }, h(Textarea, {
|
|
96
|
+
value,
|
|
97
|
+
focus: focus && !prompt,
|
|
98
|
+
cursor,
|
|
99
|
+
selection: mode.selection(),
|
|
100
|
+
labels,
|
|
101
|
+
styles: STYLES,
|
|
102
|
+
maxRows: props.height,
|
|
103
|
+
cursorBlink: mode.blink(),
|
|
104
|
+
onChange: (v) => { mode.onText(v); redraw(); },
|
|
105
|
+
onCursorChange: (c) => { mode.onCursor(c); redraw(); },
|
|
106
|
+
onSelectionChange: (s) => { if (mode.onSelect(s))
|
|
107
|
+
redraw(); },
|
|
108
|
+
onPaste: paste ? (text) => { paste(text); redraw(); } : undefined,
|
|
109
|
+
onKey: (input, key) => {
|
|
110
|
+
const handled = mode.key(input, key);
|
|
111
|
+
redraw();
|
|
112
|
+
return handled;
|
|
113
|
+
}
|
|
114
|
+
}));
|
|
115
|
+
const fillers = Array.from({ length: Math.max(0, props.height - shown) }, (_, i) => h(Text, { key: `~${i}`, color: "blue" }, filler));
|
|
116
|
+
/* the status line with the prompt, or the message resp. the label and note, and the information */
|
|
117
|
+
const text = status.message || status.label + status.note;
|
|
118
|
+
const left = prompt
|
|
119
|
+
? h(Text, { wrap: "truncate-start" }, status.prompt, h(Text, { inverse: true }, " "))
|
|
120
|
+
: status.message
|
|
121
|
+
? h(Text, { wrap: "truncate", color: status.error ? "red" : undefined }, status.message)
|
|
122
|
+
: h(Text, { wrap: "truncate" }, h(Text, { bold: true }, status.label), status.note);
|
|
123
|
+
/* a long message overwrites the information and the keystroke hints (shown grey) */
|
|
124
|
+
let right = status.info;
|
|
125
|
+
let hints = status.hints;
|
|
126
|
+
if (prompt || TextareaUtils.textWidth(text) + TextareaUtils.textWidth(right + hints) >= width) {
|
|
127
|
+
right = "";
|
|
128
|
+
hints = "";
|
|
129
|
+
}
|
|
130
|
+
const line = h(Box, { height: 1, flexShrink: 0 }, h(Box, { flexGrow: 1, flexShrink: 1 }, left), h(Box, { flexShrink: 0 }, h(Text, null, right, h(Text, { color: "gray" }, hints))));
|
|
131
|
+
return h(Box, { flexDirection: "column", height: props.height + 1 }, area, fillers, line);
|
|
132
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EditorModeFactory } from "./ink-editor-mode";
|
|
2
|
+
import { VimMode } from "./ink-editor-mode-vim";
|
|
3
|
+
import { EmacsMode } from "./ink-editor-mode-emacs";
|
|
4
|
+
import { NanoMode } from "./ink-editor-mode-nano";
|
|
5
|
+
import { CodeMode } from "./ink-editor-mode-vscode";
|
|
6
|
+
export type * from "./ink-editor-mode";
|
|
7
|
+
export type { TextOps } from "./ink-editor-text";
|
|
8
|
+
export type { Syntax, SyntaxRange, SyntaxStyle } from "./ink-editor-syntax";
|
|
9
|
+
export type { EditorProps } from "./ink-editor-widget";
|
|
10
|
+
export { Editor } from "./ink-editor-widget";
|
|
11
|
+
export { syntaxLanguage, syntaxLoad } from "./ink-editor-syntax";
|
|
12
|
+
export { VimMode, EmacsMode, NanoMode, CodeMode };
|
|
13
|
+
export declare const editorModes: Record<string, EditorModeFactory>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
** Ink-Editor -- Text Editor with Exchangeable Editing Modes for Ink
|
|
3
|
+
** Copyright (c) 2026 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
4
|
+
**
|
|
5
|
+
** Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
** a copy of this software and associated documentation files (the
|
|
7
|
+
** "Software"), to deal in the Software without restriction, including
|
|
8
|
+
** without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
** distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
** permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
** the following conditions:
|
|
12
|
+
**
|
|
13
|
+
** The above copyright notice and this permission notice shall be included
|
|
14
|
+
** in all copies or substantial portions of the Software.
|
|
15
|
+
**
|
|
16
|
+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
import { VimMode } from "./ink-editor-mode-vim";
|
|
25
|
+
import { EmacsMode } from "./ink-editor-mode-emacs";
|
|
26
|
+
import { NanoMode } from "./ink-editor-mode-nano";
|
|
27
|
+
import { CodeMode } from "./ink-editor-mode-vscode";
|
|
28
|
+
export { Editor } from "./ink-editor-widget";
|
|
29
|
+
export { syntaxLanguage, syntaxLoad } from "./ink-editor-syntax";
|
|
30
|
+
export { VimMode, EmacsMode, NanoMode, CodeMode };
|
|
31
|
+
/* the editing modes, by their name */
|
|
32
|
+
export const editorModes = {
|
|
33
|
+
vim: (value, ops) => new VimMode(value, "", ops),
|
|
34
|
+
emacs: (value, ops) => new EmacsMode(value, ops),
|
|
35
|
+
nano: (value, ops) => new NanoMode(value, ops),
|
|
36
|
+
vscode: (value, ops) => new CodeMode(value, ops)
|
|
37
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/ink-editor-cli.ts","../src/ink-editor-engine-emacs.ts","../src/ink-editor-engine-nano.ts","../src/ink-editor-engine-vim.ts","../src/ink-editor-engine-vscode.ts","../src/ink-editor-mode-emacs.ts","../src/ink-editor-mode-nano.ts","../src/ink-editor-mode-vim.ts","../src/ink-editor-mode-vscode.ts","../src/ink-editor-mode.ts","../src/ink-editor-syntax.ts","../src/ink-editor-text.ts","../src/ink-editor-widget.ts","../src/ink-editor.ts"],"version":"6.0.3"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { useApp, useWindowSize } from "ink";
|
|
5
|
+
import { render } from "better-ink-ui";
|
|
6
|
+
import { Editor, editorModes, syntaxLanguage, syntaxLoad } from "./ink-editor.esm.js";
|
|
7
|
+
// dst-stage1/ink-editor-cli.js
|
|
8
|
+
var h = React.createElement;
|
|
9
|
+
var stats = (data) => {
|
|
10
|
+
return {
|
|
11
|
+
lines: data === "" ? 0 : data.split("\n").length - (data.endsWith("\n") ? 1 : 0),
|
|
12
|
+
bytes: Buffer.byteLength(data)
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
var load = (name) => {
|
|
16
|
+
if (name === "") return {
|
|
17
|
+
text: "",
|
|
18
|
+
crlf: false,
|
|
19
|
+
blank: false,
|
|
20
|
+
result: null
|
|
21
|
+
};
|
|
22
|
+
if (!fs.existsSync(name)) return {
|
|
23
|
+
text: "",
|
|
24
|
+
crlf: false,
|
|
25
|
+
blank: false,
|
|
26
|
+
result: {
|
|
27
|
+
name,
|
|
28
|
+
isNew: true,
|
|
29
|
+
crlf: false,
|
|
30
|
+
lines: 0,
|
|
31
|
+
bytes: 0
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
let text;
|
|
35
|
+
try {
|
|
36
|
+
text = fs.readFileSync(name, "utf8");
|
|
37
|
+
} catch {
|
|
38
|
+
return {
|
|
39
|
+
text: "",
|
|
40
|
+
crlf: false,
|
|
41
|
+
blank: false,
|
|
42
|
+
result: {
|
|
43
|
+
error: "read",
|
|
44
|
+
detail: name
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const info = stats(text);
|
|
49
|
+
const crlf = text.includes("\r\n");
|
|
50
|
+
if (crlf) text = text.replaceAll("\r\n", "\n");
|
|
51
|
+
const blank = text === "\n";
|
|
52
|
+
if (text.endsWith("\n")) text = text.slice(0, -1);
|
|
53
|
+
return {
|
|
54
|
+
text,
|
|
55
|
+
crlf,
|
|
56
|
+
blank,
|
|
57
|
+
result: {
|
|
58
|
+
name,
|
|
59
|
+
isNew: false,
|
|
60
|
+
crlf,
|
|
61
|
+
...info
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
function App(props) {
|
|
66
|
+
const app = useApp();
|
|
67
|
+
const { rows } = useWindowSize();
|
|
68
|
+
const [value, setValue] = React.useState(props.file.text);
|
|
69
|
+
const valueRef = React.useRef(props.file.text);
|
|
70
|
+
const savedRef = React.useRef(props.file.text);
|
|
71
|
+
const nameRef = React.useRef(props.name);
|
|
72
|
+
const crlfRef = React.useRef(props.file.crlf);
|
|
73
|
+
const blankRef = React.useRef(props.file.blank);
|
|
74
|
+
const onChange = (v) => {
|
|
75
|
+
valueRef.current = v;
|
|
76
|
+
setValue(v);
|
|
77
|
+
};
|
|
78
|
+
const modified = () => valueRef.current !== savedRef.current;
|
|
79
|
+
const write = (file, force, rename = false) => {
|
|
80
|
+
const target = file || nameRef.current;
|
|
81
|
+
if (target === "") return {
|
|
82
|
+
error: "noname",
|
|
83
|
+
detail: ""
|
|
84
|
+
};
|
|
85
|
+
const isNew = !fs.existsSync(target);
|
|
86
|
+
if (target !== nameRef.current && !isNew && !force) return {
|
|
87
|
+
error: "exists",
|
|
88
|
+
detail: target
|
|
89
|
+
};
|
|
90
|
+
const text = valueRef.current;
|
|
91
|
+
let data = text === "" && !blankRef.current ? "" : text + "\n";
|
|
92
|
+
if (crlfRef.current) data = data.replaceAll("\n", "\r\n");
|
|
93
|
+
try {
|
|
94
|
+
fs.writeFileSync(target, data, "utf8");
|
|
95
|
+
} catch (err) {
|
|
96
|
+
return {
|
|
97
|
+
error: "write",
|
|
98
|
+
detail: err instanceof Error ? err.message : String(err)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (nameRef.current === "" || rename) nameRef.current = target;
|
|
102
|
+
if (target === nameRef.current) savedRef.current = text;
|
|
103
|
+
return {
|
|
104
|
+
name: target,
|
|
105
|
+
isNew,
|
|
106
|
+
crlf: crlfRef.current,
|
|
107
|
+
...stats(data)
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
const reload = () => {
|
|
111
|
+
const file = load(nameRef.current);
|
|
112
|
+
if (file.result === null) return {
|
|
113
|
+
error: "noname",
|
|
114
|
+
detail: ""
|
|
115
|
+
};
|
|
116
|
+
if ("error" in file.result) return file.result;
|
|
117
|
+
valueRef.current = savedRef.current = file.text;
|
|
118
|
+
crlfRef.current = file.crlf;
|
|
119
|
+
blankRef.current = file.blank;
|
|
120
|
+
setValue(file.text);
|
|
121
|
+
return file.result;
|
|
122
|
+
};
|
|
123
|
+
const host = {
|
|
124
|
+
name: () => nameRef.current,
|
|
125
|
+
modified,
|
|
126
|
+
write,
|
|
127
|
+
reload,
|
|
128
|
+
quit: (failed = false) => {
|
|
129
|
+
if (failed) process.exitCode = 1;
|
|
130
|
+
app.exit();
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const height = Math.max(1, rows - 1);
|
|
134
|
+
return h(Editor, {
|
|
135
|
+
value,
|
|
136
|
+
onChange,
|
|
137
|
+
height,
|
|
138
|
+
mode: props.mode,
|
|
139
|
+
host,
|
|
140
|
+
file: props.file.result,
|
|
141
|
+
syntax: props.syntax
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
var mode = "vim";
|
|
145
|
+
var highlight = true;
|
|
146
|
+
var name = "";
|
|
147
|
+
for (const arg of process.argv.slice(2)) if (arg.startsWith("--mode=")) mode = arg.slice(7);
|
|
148
|
+
else if (arg === "--no-syntax") highlight = false;
|
|
149
|
+
else if (arg === "--syntax") highlight = true;
|
|
150
|
+
else if (arg.startsWith("-") && arg !== "-") {
|
|
151
|
+
process.stderr.write(`ink-editor: ERROR: unknown option "${arg}"\nUsage: ink-editor [--mode=vim|emacs|nano|vscode] [--no-syntax] [<file>]\n`);
|
|
152
|
+
process.exit(1);
|
|
153
|
+
} else if (name !== "") {
|
|
154
|
+
process.stderr.write("ink-editor: ERROR: only a single file can be edited\n");
|
|
155
|
+
process.exit(1);
|
|
156
|
+
} else name = arg;
|
|
157
|
+
if (!Object.hasOwn(editorModes, mode)) {
|
|
158
|
+
process.stderr.write(`ink-editor: ERROR: unknown mode "${mode}" (known: ${Object.keys(editorModes).join(", ")})\n`);
|
|
159
|
+
process.exit(1);
|
|
160
|
+
}
|
|
161
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
162
|
+
process.stderr.write("ink-editor: ERROR: standard input and output have to be a terminal\n");
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
var file = load(name);
|
|
166
|
+
var syntax = highlight && name !== "" ? await syntaxLoad(syntaxLanguage(name)) : null;
|
|
167
|
+
syntax?.(file.text);
|
|
168
|
+
await render(h(App, {
|
|
169
|
+
name,
|
|
170
|
+
file,
|
|
171
|
+
mode: editorModes[mode],
|
|
172
|
+
syntax
|
|
173
|
+
}), {
|
|
174
|
+
exitOnCtrlC: false,
|
|
175
|
+
alternateScreen: true
|
|
176
|
+
}).waitUntilExit();
|
|
177
|
+
process.exit();
|