@ridit/lens 0.3.7 → 0.3.9
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/index.mjs +105368 -274002
- package/package.json +13 -19
- package/src/colors.ts +15 -15
- package/src/commands/chat.tsx +32 -23
- package/src/commands/provider.tsx +11 -238
- package/src/commands/repo.tsx +66 -120
- package/src/commands/timeline.tsx +11 -22
- package/src/components/ChatView.tsx +238 -0
- package/src/components/Message.tsx +46 -0
- package/src/components/ToolCall.tsx +67 -0
- package/src/components/chat/ChatView.tsx +550 -0
- package/src/components/chat/Message.tsx +152 -0
- package/src/components/chat/StatusBar.tsx +214 -0
- package/src/components/chat/TextArea.tsx +173 -176
- package/src/components/provider/ApiKeyStep.tsx +207 -199
- package/src/components/provider/ModelStep.tsx +90 -88
- package/src/components/provider/ProviderSetup.tsx +331 -0
- package/src/components/provider/ProviderTypeStep.tsx +53 -61
- package/src/components/repo/StepRow.tsx +68 -69
- package/src/components/timeline/TimelineView.tsx +840 -0
- package/src/components/toolcall-utils.ts +103 -0
- package/src/components/watch/RunView.tsx +497 -0
- package/src/hooks/useChatInput.ts +49 -0
- package/src/hooks/useCommandHandler.ts +117 -0
- package/src/index.tsx +386 -139
- package/src/utils/git.ts +149 -155
- package/src/utils/repo.ts +62 -69
- package/src/utils/thinking.tsx +64 -0
- package/src/utils/watch.ts +165 -307
- package/tests/message.test.ts +38 -0
- package/tests/toolcall-utils.test.ts +111 -0
- package/tsconfig.json +8 -24
- package/CLAUDE.md +0 -50
- package/LENS.md +0 -48
- package/LICENSE +0 -21
- package/README.md +0 -93
- package/addons/README.md +0 -55
- package/addons/clean-cache.js +0 -48
- package/addons/generate-readme.js +0 -67
- package/addons/git-stats.js +0 -29
- package/addons/run-tests.js +0 -127
- package/src/commands/commit.tsx +0 -668
- package/src/commands/review.tsx +0 -294
- package/src/commands/run.tsx +0 -56
- package/src/commands/task.tsx +0 -36
- package/src/components/chat/ChatMessage.tsx +0 -195
- package/src/components/chat/ChatOverlays.tsx +0 -399
- package/src/components/chat/ChatRunner.tsx +0 -517
- package/src/components/chat/hooks/useChat.ts +0 -631
- package/src/components/chat/hooks/useChatInput.ts +0 -79
- package/src/components/chat/hooks/useCommandHandlers.ts +0 -327
- package/src/components/provider/ProviderPicker.tsx +0 -76
- package/src/components/provider/RemoveProviderStep.tsx +0 -82
- package/src/components/repo/DiffViewer.tsx +0 -175
- package/src/components/repo/FileReviewer.tsx +0 -70
- package/src/components/repo/FileViewer.tsx +0 -60
- package/src/components/repo/IssueFixer.tsx +0 -666
- package/src/components/repo/LensFileMenu.tsx +0 -115
- package/src/components/repo/NoProviderPrompt.tsx +0 -28
- package/src/components/repo/PreviewRunner.tsx +0 -217
- package/src/components/repo/RepoAnalysis.tsx +0 -534
- package/src/components/task/TaskRunner.tsx +0 -396
- package/src/components/timeline/CommitDetail.tsx +0 -272
- package/src/components/timeline/CommitList.tsx +0 -162
- package/src/components/timeline/TimelineChat.tsx +0 -166
- package/src/components/timeline/TimelineRunner.tsx +0 -1285
- package/src/components/watch/RunRunner.tsx +0 -929
- package/src/prompts/fewshot.ts +0 -252
- package/src/prompts/index.ts +0 -2
- package/src/prompts/system.ts +0 -285
- package/src/tools/chart.ts +0 -202
- package/src/tools/convert-image.ts +0 -312
- package/src/tools/files.ts +0 -253
- package/src/tools/git.ts +0 -603
- package/src/tools/index.ts +0 -17
- package/src/tools/pdf.ts +0 -164
- package/src/tools/shell.ts +0 -96
- package/src/tools/view-image.ts +0 -335
- package/src/tools/web.ts +0 -212
- package/src/types/chat.ts +0 -86
- package/src/types/config.ts +0 -20
- package/src/types/repo.ts +0 -54
- package/src/utils/addons/loadAddons.ts +0 -34
- package/src/utils/ai.ts +0 -321
- package/src/utils/chat.ts +0 -326
- package/src/utils/chatHistory.ts +0 -121
- package/src/utils/config.ts +0 -61
- package/src/utils/files.ts +0 -105
- package/src/utils/intentClassifier.ts +0 -58
- package/src/utils/lensfile.ts +0 -142
- package/src/utils/llm.ts +0 -81
- package/src/utils/memory.ts +0 -209
- package/src/utils/preview.ts +0 -119
- package/src/utils/stats.ts +0 -174
- package/src/utils/tools/builtins.ts +0 -377
- package/src/utils/tools/registry.ts +0 -105
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import React, { useState, useEffect } from "react";
|
|
2
|
+
import { Box, Text, useStdout } from "ink";
|
|
3
|
+
import Spinner from "ink-spinner";
|
|
4
|
+
import { resolve } from "path";
|
|
5
|
+
import { homedir } from "os";
|
|
6
|
+
import { TextArea } from "./TextArea";
|
|
7
|
+
import { ACCENT, GREEN, RED } from "../../colors";
|
|
8
|
+
|
|
9
|
+
export function AppHeader({
|
|
10
|
+
model,
|
|
11
|
+
repoPath,
|
|
12
|
+
}: {
|
|
13
|
+
model: string;
|
|
14
|
+
repoPath: string;
|
|
15
|
+
}) {
|
|
16
|
+
const cols = process.stdout.columns ?? 80;
|
|
17
|
+
const rule = "─".repeat(Math.max(1, cols));
|
|
18
|
+
const abs = resolve(repoPath);
|
|
19
|
+
const displayPath = abs.startsWith(homedir())
|
|
20
|
+
? "~" + abs.slice(homedir().length)
|
|
21
|
+
: abs;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Box flexDirection="column" marginBottom={1}>
|
|
25
|
+
<Box gap={2}>
|
|
26
|
+
<Text color={ACCENT} bold>
|
|
27
|
+
◆ lens
|
|
28
|
+
</Text>
|
|
29
|
+
<Text color="gray" dimColor>
|
|
30
|
+
·
|
|
31
|
+
</Text>
|
|
32
|
+
<Text color="white" dimColor>
|
|
33
|
+
{model}
|
|
34
|
+
</Text>
|
|
35
|
+
<Text color="gray" dimColor>
|
|
36
|
+
·
|
|
37
|
+
</Text>
|
|
38
|
+
<Text color="gray" dimColor>
|
|
39
|
+
{displayPath}
|
|
40
|
+
</Text>
|
|
41
|
+
</Box>
|
|
42
|
+
<Text color="gray" dimColor>
|
|
43
|
+
{rule}
|
|
44
|
+
</Text>
|
|
45
|
+
</Box>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function InputBox({
|
|
50
|
+
value,
|
|
51
|
+
onChange,
|
|
52
|
+
onSubmit,
|
|
53
|
+
inputKey,
|
|
54
|
+
}: {
|
|
55
|
+
value: string;
|
|
56
|
+
onChange: (v: string) => void;
|
|
57
|
+
onSubmit: (v: string) => void;
|
|
58
|
+
inputKey?: number;
|
|
59
|
+
}) {
|
|
60
|
+
const { stdout } = useStdout();
|
|
61
|
+
const [cols, setCols] = useState(stdout?.columns ?? 80);
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
const handler = () => setCols(stdout?.columns ?? 80);
|
|
65
|
+
stdout?.on("resize", handler);
|
|
66
|
+
return () => {
|
|
67
|
+
stdout?.off("resize", handler);
|
|
68
|
+
};
|
|
69
|
+
}, [stdout]);
|
|
70
|
+
|
|
71
|
+
const rule = "─".repeat(Math.max(1, cols));
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Box flexDirection="column" marginTop={1}>
|
|
75
|
+
<Text color="gray" dimColor>
|
|
76
|
+
{rule}
|
|
77
|
+
</Text>
|
|
78
|
+
<Box gap={1}>
|
|
79
|
+
<Text color={ACCENT}>{">"}</Text>
|
|
80
|
+
<TextArea
|
|
81
|
+
key={inputKey}
|
|
82
|
+
value={value}
|
|
83
|
+
onChange={onChange}
|
|
84
|
+
onSubmit={onSubmit}
|
|
85
|
+
placeholder="ask anything..."
|
|
86
|
+
/>
|
|
87
|
+
</Box>
|
|
88
|
+
<Text color="gray" dimColor>
|
|
89
|
+
{rule}
|
|
90
|
+
</Text>
|
|
91
|
+
</Box>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ── Shortcut bar ──────────────────────────────────────────────────────────────
|
|
96
|
+
|
|
97
|
+
const SHORTCUTS = [
|
|
98
|
+
["↵", "send"],
|
|
99
|
+
["^↵", "line"],
|
|
100
|
+
["^⌫", " word"],
|
|
101
|
+
["^f", "force"],
|
|
102
|
+
["^c", "exit"],
|
|
103
|
+
] as const;
|
|
104
|
+
|
|
105
|
+
export function ShortcutBar({
|
|
106
|
+
autoApprove,
|
|
107
|
+
forceApprove,
|
|
108
|
+
isThinking = false,
|
|
109
|
+
model,
|
|
110
|
+
}: {
|
|
111
|
+
autoApprove?: boolean;
|
|
112
|
+
forceApprove?: boolean;
|
|
113
|
+
isThinking?: boolean;
|
|
114
|
+
model?: string;
|
|
115
|
+
}) {
|
|
116
|
+
const [elapsed, setElapsed] = useState(0);
|
|
117
|
+
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!isThinking) {
|
|
120
|
+
setElapsed(0);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
setElapsed(0);
|
|
124
|
+
const id = setInterval(() => setElapsed((s) => s + 1), 1000);
|
|
125
|
+
return () => clearInterval(id);
|
|
126
|
+
}, [isThinking]);
|
|
127
|
+
|
|
128
|
+
if (isThinking) {
|
|
129
|
+
return (
|
|
130
|
+
<Box marginTop={0} gap={1}>
|
|
131
|
+
<Text color={ACCENT}>
|
|
132
|
+
<Spinner type="dots" />
|
|
133
|
+
</Text>
|
|
134
|
+
{model && <Text color="gray">{model}</Text>}
|
|
135
|
+
<Text color="gray" dimColor>
|
|
136
|
+
({elapsed}s · esc cancel)
|
|
137
|
+
</Text>
|
|
138
|
+
</Box>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<Box marginTop={0} justifyContent="space-between">
|
|
144
|
+
<Box>
|
|
145
|
+
{forceApprove ? (
|
|
146
|
+
<>
|
|
147
|
+
<Text color="gray" dimColor>
|
|
148
|
+
{" "}
|
|
149
|
+
·{" "}
|
|
150
|
+
</Text>
|
|
151
|
+
<Text color={RED} bold>
|
|
152
|
+
force-all
|
|
153
|
+
</Text>
|
|
154
|
+
</>
|
|
155
|
+
) : autoApprove ? (
|
|
156
|
+
<>
|
|
157
|
+
<Text color="gray" dimColor>
|
|
158
|
+
{" "}
|
|
159
|
+
·{" "}
|
|
160
|
+
</Text>
|
|
161
|
+
<Text color={GREEN}>auto</Text>
|
|
162
|
+
</>
|
|
163
|
+
) : null}
|
|
164
|
+
{model && (
|
|
165
|
+
<>
|
|
166
|
+
<Text color={ACCENT}> ● </Text>
|
|
167
|
+
<Text color="gray">{model}</Text>
|
|
168
|
+
</>
|
|
169
|
+
)}
|
|
170
|
+
</Box>
|
|
171
|
+
|
|
172
|
+
<Box>
|
|
173
|
+
{SHORTCUTS.map(([key, desc], i) => (
|
|
174
|
+
<Box key={i}>
|
|
175
|
+
{i > 0 && <Text color="gray"> · </Text>}
|
|
176
|
+
<Text color="gray">{key}</Text>
|
|
177
|
+
<Text color="gray"> {desc}</Text>
|
|
178
|
+
</Box>
|
|
179
|
+
))}
|
|
180
|
+
</Box>
|
|
181
|
+
</Box>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// ── Typewriter text ───────────────────────────────────────────────────────────
|
|
186
|
+
|
|
187
|
+
export function TypewriterText({
|
|
188
|
+
text,
|
|
189
|
+
color = ACCENT,
|
|
190
|
+
speed = 38,
|
|
191
|
+
}: {
|
|
192
|
+
text: string;
|
|
193
|
+
color?: string;
|
|
194
|
+
speed?: number;
|
|
195
|
+
}) {
|
|
196
|
+
const [displayed, setDisplayed] = React.useState("");
|
|
197
|
+
const [target, setTarget] = React.useState(text);
|
|
198
|
+
|
|
199
|
+
React.useEffect(() => {
|
|
200
|
+
setDisplayed("");
|
|
201
|
+
setTarget(text);
|
|
202
|
+
}, [text]);
|
|
203
|
+
|
|
204
|
+
React.useEffect(() => {
|
|
205
|
+
if (displayed.length >= target.length) return;
|
|
206
|
+
const t = setTimeout(
|
|
207
|
+
() => setDisplayed(target.slice(0, displayed.length + 1)),
|
|
208
|
+
speed,
|
|
209
|
+
);
|
|
210
|
+
return () => clearTimeout(t);
|
|
211
|
+
}, [displayed, target, speed]);
|
|
212
|
+
|
|
213
|
+
return <Text color={color}>{displayed}</Text>;
|
|
214
|
+
}
|
|
@@ -1,176 +1,173 @@
|
|
|
1
|
-
import React, { useState
|
|
2
|
-
import { Text, useInput } from "ink";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
|
|
5
|
-
function isWordChar(ch: string): boolean {
|
|
6
|
-
return /[\w]/.test(ch);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function wordBoundaryLeft(text: string, pos: number): number {
|
|
10
|
-
if (pos <= 0) return 0;
|
|
11
|
-
let i = pos - 1;
|
|
12
|
-
|
|
13
|
-
while (i > 0 &&
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return <Text>{rendered}</Text>;
|
|
176
|
-
}
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Text, useInput } from "ink";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
|
|
5
|
+
function isWordChar(ch: string): boolean {
|
|
6
|
+
return /[\w]/.test(ch);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function wordBoundaryLeft(text: string, pos: number): number {
|
|
10
|
+
if (pos <= 0) return 0;
|
|
11
|
+
let i = pos - 1;
|
|
12
|
+
while (i > 0 && !isWordChar(text[i]!)) i--;
|
|
13
|
+
while (i > 0 && isWordChar(text[i - 1]!)) i--;
|
|
14
|
+
return i;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function wordBoundaryRight(text: string, pos: number): number {
|
|
18
|
+
const len = text.length;
|
|
19
|
+
if (pos >= len) return len;
|
|
20
|
+
let i = pos;
|
|
21
|
+
while (i < len && isWordChar(text[i]!)) i++;
|
|
22
|
+
while (i < len && !isWordChar(text[i]!)) i++;
|
|
23
|
+
return i;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface TextAreaProps {
|
|
27
|
+
value: string;
|
|
28
|
+
onChange: (value: string) => void;
|
|
29
|
+
onSubmit: (value: string) => void;
|
|
30
|
+
focus?: boolean;
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function TextArea({
|
|
35
|
+
value,
|
|
36
|
+
onChange,
|
|
37
|
+
onSubmit,
|
|
38
|
+
focus = true,
|
|
39
|
+
placeholder = "",
|
|
40
|
+
}: TextAreaProps) {
|
|
41
|
+
const [cursor, setCursor] = useState(value.length);
|
|
42
|
+
const [prevValue, setPrevValue] = useState(value);
|
|
43
|
+
|
|
44
|
+
if (value !== prevValue) {
|
|
45
|
+
setPrevValue(value);
|
|
46
|
+
const lenDiff = Math.abs(value.length - prevValue.length);
|
|
47
|
+
if (cursor > value.length || lenDiff > 1) {
|
|
48
|
+
setCursor(value.length);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
useInput(
|
|
53
|
+
(input, key) => {
|
|
54
|
+
if (key.upArrow || key.downArrow) return;
|
|
55
|
+
if (key.tab || (key.shift && key.tab)) return;
|
|
56
|
+
if (key.ctrl && input === "c") return;
|
|
57
|
+
|
|
58
|
+
const isShiftEnter =
|
|
59
|
+
(key.return && key.shift) ||
|
|
60
|
+
input === "\x1b[27;2;13~" ||
|
|
61
|
+
input === "\x1b[13;2u";
|
|
62
|
+
|
|
63
|
+
if (key.return && !key.meta && !key.shift && !isShiftEnter) {
|
|
64
|
+
onSubmit(value);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (isShiftEnter) {
|
|
69
|
+
const next = value.slice(0, cursor) + "\n" + value.slice(cursor);
|
|
70
|
+
onChange(next);
|
|
71
|
+
setCursor((c) => c + 1);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (key.leftArrow && key.ctrl) {
|
|
76
|
+
setCursor(wordBoundaryLeft(value, cursor));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (key.rightArrow && key.ctrl) {
|
|
81
|
+
setCursor(wordBoundaryRight(value, cursor));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (key.leftArrow) {
|
|
86
|
+
setCursor((c) => Math.max(0, c - 1));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (key.rightArrow) {
|
|
91
|
+
setCursor((c) => Math.min(value.length, c + 1));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (key.ctrl && input === "a") {
|
|
96
|
+
const lineStart = value.lastIndexOf("\n", cursor - 1) + 1;
|
|
97
|
+
setCursor(lineStart);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (key.ctrl && input === "e") {
|
|
102
|
+
const lineEnd = value.indexOf("\n", cursor);
|
|
103
|
+
setCursor(lineEnd === -1 ? value.length : lineEnd);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (key.ctrl && input === "u") {
|
|
108
|
+
const lineStart = value.lastIndexOf("\n", cursor - 1) + 1;
|
|
109
|
+
onChange(value.slice(0, lineStart) + value.slice(cursor));
|
|
110
|
+
setCursor(lineStart);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (key.ctrl && input === "k") {
|
|
115
|
+
const lineEnd = value.indexOf("\n", cursor);
|
|
116
|
+
onChange(
|
|
117
|
+
value.slice(0, cursor) + (lineEnd === -1 ? "" : value.slice(lineEnd)),
|
|
118
|
+
);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (key.ctrl && input === "f") return;
|
|
123
|
+
|
|
124
|
+
if ((key.ctrl && key.delete) || input === "\x1b[3;5~") {
|
|
125
|
+
const to = wordBoundaryLeft(value, cursor);
|
|
126
|
+
onChange(value.slice(0, to) + value.slice(cursor));
|
|
127
|
+
setCursor(to);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (key.backspace || key.delete) {
|
|
132
|
+
if (cursor > 0) {
|
|
133
|
+
onChange(value.slice(0, cursor - 1) + value.slice(cursor));
|
|
134
|
+
setCursor((c) => c - 1);
|
|
135
|
+
}
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (key.escape) return;
|
|
140
|
+
|
|
141
|
+
if (input) {
|
|
142
|
+
const next = value.slice(0, cursor) + input + value.slice(cursor);
|
|
143
|
+
onChange(next);
|
|
144
|
+
setCursor((c) => c + input.length);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
{ isActive: focus },
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
if (value.length === 0 && placeholder) {
|
|
151
|
+
return (
|
|
152
|
+
<Text>
|
|
153
|
+
{chalk.inverse(placeholder[0] ?? " ")}
|
|
154
|
+
{placeholder.length > 1 ? chalk.gray(placeholder.slice(1)) : ""}
|
|
155
|
+
</Text>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let rendered = "";
|
|
160
|
+
for (let i = 0; i < value.length; i++) {
|
|
161
|
+
const ch = value[i]!;
|
|
162
|
+
if (i === cursor) {
|
|
163
|
+
rendered += ch === "\n" ? chalk.inverse(" ") + "\n" : chalk.inverse(ch);
|
|
164
|
+
} else {
|
|
165
|
+
rendered += ch;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (cursor === value.length) {
|
|
169
|
+
rendered += chalk.inverse(" ");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return <Text>{rendered}</Text>;
|
|
173
|
+
}
|