@eliya-oss/agent-diff 0.1.0-alpha.1 → 0.1.0-alpha.100
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/.agents/adr/README.md +3 -0
- package/.agents/prd/README.md +2 -2
- package/CHANGELOG.md +666 -0
- package/README.md +37 -79
- package/bin/adiff.js +80 -2
- package/dist/main.js +17611 -0
- package/package.json +14 -10
- package/skills/adiff/SKILL.md +140 -26
- package/src/cli/catalog.ts +0 -178
- package/src/cli/commands.ts +0 -335
- package/src/cli/error.ts +0 -44
- package/src/cli/index.ts +0 -24
- package/src/cli/parse.ts +0 -31
- package/src/cli/report.ts +0 -96
- package/src/cli/story.ts +0 -223
- package/src/domain/narrative/coverage.ts +0 -54
- package/src/domain/narrative/index.ts +0 -4
- package/src/domain/narrative/model.ts +0 -46
- package/src/domain/narrative/version.ts +0 -63
- package/src/domain/patch/anchor.ts +0 -40
- package/src/domain/patch/index.ts +0 -7
- package/src/domain/patch/model.ts +0 -54
- package/src/domain/patch/parse.ts +0 -106
- package/src/domain/patch/render.ts +0 -48
- package/src/domain/patch/sticky.ts +0 -39
- package/src/domain/review/index.ts +0 -4
- package/src/domain/review/lifecycle.ts +0 -45
- package/src/domain/review/model.ts +0 -23
- package/src/domain/review/vouch.ts +0 -15
- package/src/main.ts +0 -186
- package/src/service/git/error.ts +0 -16
- package/src/service/git/index.ts +0 -3
- package/src/service/git/model.ts +0 -13
- package/src/service/git/run.ts +0 -27
- package/src/service/git/service.ts +0 -133
- package/src/service/store/error.ts +0 -11
- package/src/service/store/index.ts +0 -5
- package/src/service/store/model.ts +0 -33
- package/src/service/store/paths.ts +0 -25
- package/src/service/store/service.ts +0 -154
- package/src/testing/agent-surface.test.ts +0 -92
- package/src/testing/batch.test.ts +0 -93
- package/src/testing/branch-state.test.ts +0 -99
- package/src/testing/chrome-tone.test.ts +0 -57
- package/src/testing/comment-block.test.ts +0 -84
- package/src/testing/comment-walk.test.ts +0 -96
- package/src/testing/compose-box.test.ts +0 -97
- package/src/testing/compose.test.ts +0 -67
- package/src/testing/context.test.ts +0 -77
- package/src/testing/cursor.test.ts +0 -49
- package/src/testing/delivery.test.ts +0 -94
- package/src/testing/domains/agent/driver.ts +0 -50
- package/src/testing/domains/agent/index.ts +0 -2
- package/src/testing/domains/app/driver.ts +0 -168
- package/src/testing/domains/app/index.ts +0 -2
- package/src/testing/domains/branch/driver.ts +0 -51
- package/src/testing/domains/branch/index.ts +0 -3
- package/src/testing/domains/branch/model.ts +0 -39
- package/src/testing/domains/screen/driver.ts +0 -241
- package/src/testing/domains/screen/index.ts +0 -2
- package/src/testing/driver.ts +0 -31
- package/src/testing/escape.test.ts +0 -56
- package/src/testing/focus.test.ts +0 -104
- package/src/testing/footer-chips.test.ts +0 -65
- package/src/testing/footer.test.ts +0 -64
- package/src/testing/gaps.test.ts +0 -47
- package/src/testing/highlight.test.ts +0 -49
- package/src/testing/home-screen.test.ts +0 -51
- package/src/testing/index.ts +0 -4
- package/src/testing/inline-comments.test.ts +0 -131
- package/src/testing/marks.test.ts +0 -49
- package/src/testing/mouse.test.ts +0 -87
- package/src/testing/navigate.test.ts +0 -73
- package/src/testing/palette.test.ts +0 -68
- package/src/testing/pending.test.ts +0 -70
- package/src/testing/pin-align.test.ts +0 -37
- package/src/testing/progress.test.ts +0 -88
- package/src/testing/report.test.ts +0 -83
- package/src/testing/resume.test.ts +0 -39
- package/src/testing/review.test.ts +0 -181
- package/src/testing/roundtrip.test.ts +0 -70
- package/src/testing/scale.test.ts +0 -55
- package/src/testing/scroll-feel.test.ts +0 -81
- package/src/testing/sent-comments.test.ts +0 -106
- package/src/testing/state.ts +0 -55
- package/src/testing/sticky-removed.test.ts +0 -67
- package/src/testing/sticky.test.ts +0 -90
- package/src/testing/story-rail.test.ts +0 -122
- package/src/testing/story.test.ts +0 -183
- package/src/testing/stress.test.ts +0 -74
- package/src/testing/tree-collapse.test.ts +0 -108
- package/src/testing/tree-rows.test.ts +0 -66
- package/src/testing/tree.test.ts +0 -91
- package/src/testing/tui.test.ts +0 -73
- package/src/testing/typing.test.ts +0 -65
- package/src/testing/vouch-next.test.ts +0 -65
- package/src/testing/vouch-tui.test.ts +0 -77
- package/src/testing/wash.test.ts +0 -32
- package/src/testing/width.test.ts +0 -62
- package/src/tui/app.ts +0 -467
- package/src/tui/command.ts +0 -390
- package/src/tui/diffview.ts +0 -333
- package/src/tui/index.ts +0 -9
- package/src/tui/marks.ts +0 -102
- package/src/tui/match.ts +0 -34
- package/src/tui/model.ts +0 -310
- package/src/tui/reduce.ts +0 -305
- package/src/tui/render.ts +0 -897
- package/src/tui/report.ts +0 -74
- package/src/tui/session.ts +0 -32
- package/src/tui/theme.ts +0 -61
- package/src/tui/tree.ts +0 -149
package/src/tui/command.ts
DELETED
|
@@ -1,390 +0,0 @@
|
|
|
1
|
-
import type { Screen } from "./model.ts"
|
|
2
|
-
|
|
3
|
-
export type Action =
|
|
4
|
-
| "branch.next"
|
|
5
|
-
| "branch.prev"
|
|
6
|
-
| "branch.open"
|
|
7
|
-
| "cursor.next"
|
|
8
|
-
| "cursor.top"
|
|
9
|
-
| "cursor.bottom"
|
|
10
|
-
| "cursor.pageDown"
|
|
11
|
-
| "cursor.pageUp"
|
|
12
|
-
| "context.more"
|
|
13
|
-
| "context.less"
|
|
14
|
-
| "comment.next"
|
|
15
|
-
| "comment.prev"
|
|
16
|
-
| "hunk.next"
|
|
17
|
-
| "hunk.prev"
|
|
18
|
-
| "cursor.prev"
|
|
19
|
-
| "file.next"
|
|
20
|
-
| "file.prev"
|
|
21
|
-
| "focus.toggle"
|
|
22
|
-
| "nav.zoom"
|
|
23
|
-
| "rail.toggle"
|
|
24
|
-
| "tree.collapse"
|
|
25
|
-
| "tree.expand"
|
|
26
|
-
| "file.vouch"
|
|
27
|
-
| "file.vouch.next"
|
|
28
|
-
| "select.start"
|
|
29
|
-
| "compose.open"
|
|
30
|
-
| "compose.submit"
|
|
31
|
-
| "compose.stage"
|
|
32
|
-
| "pending.open"
|
|
33
|
-
| "pending.submit"
|
|
34
|
-
| "pending.next"
|
|
35
|
-
| "pending.prev"
|
|
36
|
-
| "compose.newline"
|
|
37
|
-
| "palette.open"
|
|
38
|
-
| "report.open"
|
|
39
|
-
| "report.send"
|
|
40
|
-
| "palette.run"
|
|
41
|
-
| "back"
|
|
42
|
-
| "quit"
|
|
43
|
-
|
|
44
|
-
export type Command = {
|
|
45
|
-
readonly action: Action
|
|
46
|
-
readonly title: string
|
|
47
|
-
readonly category: string
|
|
48
|
-
readonly keys: ReadonlyArray<string>
|
|
49
|
-
readonly screens: ReadonlyArray<Screen>
|
|
50
|
-
readonly hint: string
|
|
51
|
-
readonly listed: boolean
|
|
52
|
-
readonly whenStaged: boolean
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const command = (input: Partial<Command> & Pick<Command, "action" | "title" | "keys" | "screens">): Command => ({
|
|
56
|
-
category: "Review",
|
|
57
|
-
hint: "",
|
|
58
|
-
listed: true,
|
|
59
|
-
whenStaged: false,
|
|
60
|
-
...input,
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
export const commands: ReadonlyArray<Command> = [
|
|
64
|
-
command({
|
|
65
|
-
action: "branch.next",
|
|
66
|
-
title: "Next branch",
|
|
67
|
-
category: "Branches",
|
|
68
|
-
keys: ["down", "j"],
|
|
69
|
-
screens: ["branches"],
|
|
70
|
-
hint: "move",
|
|
71
|
-
}),
|
|
72
|
-
command({
|
|
73
|
-
action: "branch.prev",
|
|
74
|
-
title: "Previous branch",
|
|
75
|
-
category: "Branches",
|
|
76
|
-
keys: ["up", "k"],
|
|
77
|
-
screens: ["branches"],
|
|
78
|
-
}),
|
|
79
|
-
command({
|
|
80
|
-
action: "branch.open",
|
|
81
|
-
title: "Open branch for review",
|
|
82
|
-
category: "Branches",
|
|
83
|
-
keys: ["return"],
|
|
84
|
-
screens: ["branches"],
|
|
85
|
-
hint: "review",
|
|
86
|
-
}),
|
|
87
|
-
command({
|
|
88
|
-
action: "cursor.next",
|
|
89
|
-
title: "Next line",
|
|
90
|
-
keys: ["down", "j"],
|
|
91
|
-
screens: ["review"],
|
|
92
|
-
hint: "line",
|
|
93
|
-
}),
|
|
94
|
-
command({
|
|
95
|
-
action: "cursor.prev",
|
|
96
|
-
title: "Previous line",
|
|
97
|
-
keys: ["up", "k"],
|
|
98
|
-
screens: ["review"],
|
|
99
|
-
}),
|
|
100
|
-
command({
|
|
101
|
-
action: "cursor.top",
|
|
102
|
-
title: "Go to first line",
|
|
103
|
-
keys: ["g"],
|
|
104
|
-
screens: ["review"],
|
|
105
|
-
}),
|
|
106
|
-
command({
|
|
107
|
-
action: "cursor.bottom",
|
|
108
|
-
title: "Go to last line",
|
|
109
|
-
keys: ["G"],
|
|
110
|
-
screens: ["review"],
|
|
111
|
-
}),
|
|
112
|
-
command({
|
|
113
|
-
action: "cursor.pageDown",
|
|
114
|
-
title: "Half page down",
|
|
115
|
-
keys: ["ctrl+d"],
|
|
116
|
-
screens: ["review"],
|
|
117
|
-
}),
|
|
118
|
-
command({
|
|
119
|
-
action: "cursor.pageUp",
|
|
120
|
-
title: "Half page up",
|
|
121
|
-
keys: ["ctrl+u"],
|
|
122
|
-
screens: ["review"],
|
|
123
|
-
}),
|
|
124
|
-
command({
|
|
125
|
-
action: "context.more",
|
|
126
|
-
title: "Show more context",
|
|
127
|
-
keys: ["+", "="],
|
|
128
|
-
screens: ["review"],
|
|
129
|
-
}),
|
|
130
|
-
command({
|
|
131
|
-
action: "context.less",
|
|
132
|
-
title: "Show less context",
|
|
133
|
-
keys: ["-", "_"],
|
|
134
|
-
screens: ["review"],
|
|
135
|
-
}),
|
|
136
|
-
command({
|
|
137
|
-
action: "comment.next",
|
|
138
|
-
title: "Next comment",
|
|
139
|
-
keys: ["n"],
|
|
140
|
-
screens: ["review"],
|
|
141
|
-
hint: "next comment",
|
|
142
|
-
whenStaged: true,
|
|
143
|
-
}),
|
|
144
|
-
command({
|
|
145
|
-
action: "comment.prev",
|
|
146
|
-
title: "Previous comment",
|
|
147
|
-
keys: ["N"],
|
|
148
|
-
screens: ["review"],
|
|
149
|
-
}),
|
|
150
|
-
command({
|
|
151
|
-
action: "hunk.next",
|
|
152
|
-
title: "Next change",
|
|
153
|
-
keys: ["}"],
|
|
154
|
-
screens: ["review"],
|
|
155
|
-
}),
|
|
156
|
-
command({
|
|
157
|
-
action: "hunk.prev",
|
|
158
|
-
title: "Previous change",
|
|
159
|
-
keys: ["{"],
|
|
160
|
-
screens: ["review"],
|
|
161
|
-
}),
|
|
162
|
-
command({
|
|
163
|
-
action: "file.next",
|
|
164
|
-
title: "Next file",
|
|
165
|
-
category: "Files",
|
|
166
|
-
keys: ["]"],
|
|
167
|
-
screens: ["review"],
|
|
168
|
-
hint: "file",
|
|
169
|
-
}),
|
|
170
|
-
command({
|
|
171
|
-
action: "file.prev",
|
|
172
|
-
title: "Previous file",
|
|
173
|
-
category: "Files",
|
|
174
|
-
keys: ["["],
|
|
175
|
-
screens: ["review"],
|
|
176
|
-
}),
|
|
177
|
-
command({
|
|
178
|
-
action: "focus.toggle",
|
|
179
|
-
title: "Switch pane",
|
|
180
|
-
category: "General",
|
|
181
|
-
keys: ["tab"],
|
|
182
|
-
screens: ["review"],
|
|
183
|
-
}),
|
|
184
|
-
command({
|
|
185
|
-
action: "nav.zoom",
|
|
186
|
-
title: "Hide the file list",
|
|
187
|
-
category: "General",
|
|
188
|
-
keys: ["z", "\\"],
|
|
189
|
-
screens: ["review"],
|
|
190
|
-
hint: "zoom",
|
|
191
|
-
}),
|
|
192
|
-
command({
|
|
193
|
-
action: "rail.toggle",
|
|
194
|
-
title: "Switch between steps and files",
|
|
195
|
-
category: "Files",
|
|
196
|
-
keys: ["s"],
|
|
197
|
-
screens: ["review"],
|
|
198
|
-
}),
|
|
199
|
-
command({
|
|
200
|
-
action: "tree.collapse",
|
|
201
|
-
title: "Collapse the file tree",
|
|
202
|
-
category: "Files",
|
|
203
|
-
keys: ["h"],
|
|
204
|
-
screens: ["review"],
|
|
205
|
-
}),
|
|
206
|
-
command({
|
|
207
|
-
action: "tree.expand",
|
|
208
|
-
title: "Expand the file tree",
|
|
209
|
-
category: "Files",
|
|
210
|
-
keys: ["l"],
|
|
211
|
-
screens: ["review"],
|
|
212
|
-
}),
|
|
213
|
-
command({
|
|
214
|
-
action: "file.vouch",
|
|
215
|
-
title: "Mark reviewed",
|
|
216
|
-
category: "Files",
|
|
217
|
-
keys: ["m"],
|
|
218
|
-
screens: ["review"],
|
|
219
|
-
hint: "reviewed",
|
|
220
|
-
}),
|
|
221
|
-
command({
|
|
222
|
-
action: "file.vouch.next",
|
|
223
|
-
title: "Mark reviewed and go to next",
|
|
224
|
-
category: "Files",
|
|
225
|
-
keys: ["M"],
|
|
226
|
-
screens: ["review"],
|
|
227
|
-
}),
|
|
228
|
-
command({
|
|
229
|
-
action: "select.start",
|
|
230
|
-
title: "Start a selection",
|
|
231
|
-
keys: ["v"],
|
|
232
|
-
screens: ["review"],
|
|
233
|
-
hint: "select",
|
|
234
|
-
}),
|
|
235
|
-
command({
|
|
236
|
-
action: "compose.open",
|
|
237
|
-
title: "Comment on the selection",
|
|
238
|
-
keys: ["c", "return"],
|
|
239
|
-
screens: ["review"],
|
|
240
|
-
hint: "comment",
|
|
241
|
-
}),
|
|
242
|
-
command({
|
|
243
|
-
action: "report.open",
|
|
244
|
-
title: "Report a bug",
|
|
245
|
-
category: "General",
|
|
246
|
-
keys: ["ctrl+b"],
|
|
247
|
-
screens: ["branches", "review"],
|
|
248
|
-
}),
|
|
249
|
-
command({
|
|
250
|
-
action: "report.send",
|
|
251
|
-
title: "Send the report",
|
|
252
|
-
keys: ["ctrl+s"],
|
|
253
|
-
screens: ["report"],
|
|
254
|
-
hint: "copy",
|
|
255
|
-
listed: false,
|
|
256
|
-
}),
|
|
257
|
-
command({
|
|
258
|
-
action: "palette.open",
|
|
259
|
-
title: "Find a command",
|
|
260
|
-
category: "General",
|
|
261
|
-
keys: ["ctrl+p"],
|
|
262
|
-
screens: ["review"],
|
|
263
|
-
hint: "commands",
|
|
264
|
-
listed: false,
|
|
265
|
-
}),
|
|
266
|
-
command({
|
|
267
|
-
action: "compose.submit",
|
|
268
|
-
title: "Send the comment",
|
|
269
|
-
keys: ["ctrl+s"],
|
|
270
|
-
screens: ["compose"],
|
|
271
|
-
hint: "send",
|
|
272
|
-
listed: false,
|
|
273
|
-
}),
|
|
274
|
-
command({
|
|
275
|
-
action: "pending.open",
|
|
276
|
-
title: "Review what is staged",
|
|
277
|
-
keys: ["S"],
|
|
278
|
-
screens: ["review"],
|
|
279
|
-
hint: "review",
|
|
280
|
-
whenStaged: true,
|
|
281
|
-
}),
|
|
282
|
-
command({
|
|
283
|
-
action: "pending.submit",
|
|
284
|
-
title: "Send the review",
|
|
285
|
-
keys: ["ctrl+s"],
|
|
286
|
-
screens: ["pending"],
|
|
287
|
-
hint: "send",
|
|
288
|
-
listed: false,
|
|
289
|
-
}),
|
|
290
|
-
command({
|
|
291
|
-
action: "pending.next",
|
|
292
|
-
title: "Next staged comment",
|
|
293
|
-
keys: ["down", "j"],
|
|
294
|
-
screens: ["pending"],
|
|
295
|
-
listed: false,
|
|
296
|
-
}),
|
|
297
|
-
command({
|
|
298
|
-
action: "pending.prev",
|
|
299
|
-
title: "Previous staged comment",
|
|
300
|
-
keys: ["up", "k"],
|
|
301
|
-
screens: ["pending"],
|
|
302
|
-
listed: false,
|
|
303
|
-
}),
|
|
304
|
-
command({
|
|
305
|
-
action: "compose.stage",
|
|
306
|
-
title: "Add to review",
|
|
307
|
-
keys: ["ctrl+a"],
|
|
308
|
-
screens: ["compose"],
|
|
309
|
-
hint: "stage",
|
|
310
|
-
listed: false,
|
|
311
|
-
}),
|
|
312
|
-
command({
|
|
313
|
-
action: "compose.newline",
|
|
314
|
-
title: "New line",
|
|
315
|
-
keys: ["return"],
|
|
316
|
-
screens: ["compose"],
|
|
317
|
-
listed: false,
|
|
318
|
-
}),
|
|
319
|
-
command({
|
|
320
|
-
action: "palette.run",
|
|
321
|
-
title: "Run the highlighted command",
|
|
322
|
-
keys: ["return"],
|
|
323
|
-
screens: ["palette"],
|
|
324
|
-
hint: "run",
|
|
325
|
-
listed: false,
|
|
326
|
-
}),
|
|
327
|
-
command({
|
|
328
|
-
action: "back",
|
|
329
|
-
title: "Go back",
|
|
330
|
-
category: "General",
|
|
331
|
-
keys: ["escape", "q"],
|
|
332
|
-
screens: ["review", "compose", "palette", "pending", "report"],
|
|
333
|
-
hint: "back",
|
|
334
|
-
listed: false,
|
|
335
|
-
}),
|
|
336
|
-
command({
|
|
337
|
-
action: "quit",
|
|
338
|
-
title: "Quit",
|
|
339
|
-
category: "General",
|
|
340
|
-
keys: ["q"],
|
|
341
|
-
screens: ["branches"],
|
|
342
|
-
hint: "quit",
|
|
343
|
-
listed: false,
|
|
344
|
-
}),
|
|
345
|
-
]
|
|
346
|
-
|
|
347
|
-
const TEXT_SCREENS: ReadonlySet<Screen> = new Set<Screen>(["compose", "palette", "report"])
|
|
348
|
-
|
|
349
|
-
const PRINTABLE_KEY = /^[\S ]$/
|
|
350
|
-
|
|
351
|
-
export const takesText = (screen: Screen): boolean => TEXT_SCREENS.has(screen)
|
|
352
|
-
|
|
353
|
-
export const commandsFor = (screen: Screen): ReadonlyArray<Command> =>
|
|
354
|
-
commands.filter((entry) => entry.screens.includes(screen))
|
|
355
|
-
|
|
356
|
-
export const listableFor = (screen: Screen): ReadonlyArray<Command> =>
|
|
357
|
-
commandsFor(screen).filter((entry) => entry.listed)
|
|
358
|
-
|
|
359
|
-
export const actionFor = (screen: Screen, key: string): Action | undefined => {
|
|
360
|
-
if (takesText(screen) && PRINTABLE_KEY.test(key)) return undefined
|
|
361
|
-
return commandsFor(screen).find((entry) => entry.keys.includes(key))?.action
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
export const keyFor = (screen: Screen, action: Action): string =>
|
|
365
|
-
commandsFor(screen).find((entry) => entry.action === action)?.keys[0] ?? ""
|
|
366
|
-
|
|
367
|
-
const GLYPHS: Readonly<Record<string, string>> = {
|
|
368
|
-
up: "↑",
|
|
369
|
-
down: "↓",
|
|
370
|
-
left: "←",
|
|
371
|
-
right: "→",
|
|
372
|
-
return: "↵",
|
|
373
|
-
escape: "esc",
|
|
374
|
-
space: "␣",
|
|
375
|
-
backspace: "⌫",
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
export const displayKey = (key: string): string => {
|
|
379
|
-
if (key.startsWith("ctrl+")) return `^${key.slice(5)}`
|
|
380
|
-
return GLYPHS[key] ?? key
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
export const hintsFor = (
|
|
384
|
-
screen: Screen,
|
|
385
|
-
staged: number,
|
|
386
|
-
): ReadonlyArray<{ key: string; hint: string; press: string }> =>
|
|
387
|
-
commandsFor(screen)
|
|
388
|
-
.filter((entry) => entry.hint.length > 0)
|
|
389
|
-
.filter((entry) => !entry.whenStaged || staged > 0)
|
|
390
|
-
.map((entry) => ({ key: displayKey(entry.keys[0] ?? ""), hint: entry.hint, press: entry.keys[0] ?? "" }))
|
package/src/tui/diffview.ts
DELETED
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BoxRenderable,
|
|
3
|
-
CodeRenderable,
|
|
4
|
-
LineNumberRenderable,
|
|
5
|
-
RGBA,
|
|
6
|
-
SyntaxStyle,
|
|
7
|
-
getTreeSitterClient,
|
|
8
|
-
pathToFiletype,
|
|
9
|
-
type CliRenderer,
|
|
10
|
-
} from "@opentui/core"
|
|
11
|
-
import { Option } from "effect"
|
|
12
|
-
import { lineOn, type Patch, type Row, type RowKind } from "../domain/patch/index.ts"
|
|
13
|
-
import { marks } from "./marks.ts"
|
|
14
|
-
import { palette, syntaxTheme } from "./theme.ts"
|
|
15
|
-
|
|
16
|
-
export type LinePaint = { readonly gutter: RGBA; readonly content: RGBA }
|
|
17
|
-
|
|
18
|
-
export type Note = {
|
|
19
|
-
readonly side: "old" | "new"
|
|
20
|
-
readonly line: number
|
|
21
|
-
readonly body: string
|
|
22
|
-
readonly sent: boolean
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type Display = {
|
|
26
|
-
readonly text: string
|
|
27
|
-
readonly row: number
|
|
28
|
-
readonly comment: boolean
|
|
29
|
-
readonly sent: boolean
|
|
30
|
-
readonly label: boolean
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const WASH: Partial<Record<RowKind, LinePaint>> = {
|
|
34
|
-
added: { gutter: RGBA.fromHex(palette.addedGutter), content: RGBA.fromHex(palette.addedBg) },
|
|
35
|
-
removed: {
|
|
36
|
-
gutter: RGBA.fromHex(palette.removedGutter),
|
|
37
|
-
content: RGBA.fromHex(palette.removedBg),
|
|
38
|
-
},
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const NOTE_MIN = 24
|
|
42
|
-
const OVERSCAN = 2
|
|
43
|
-
const SIGN_WIDTH = 2
|
|
44
|
-
const SCROLL_ROWS = 3
|
|
45
|
-
|
|
46
|
-
const SIGNS: Readonly<Record<RowKind, { text: string; color: string }>> = {
|
|
47
|
-
added: { text: " +", color: palette.added },
|
|
48
|
-
removed: { text: " -", color: palette.removed },
|
|
49
|
-
context: { text: " ", color: palette.faint },
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const numberFor = (row: Row): number | undefined =>
|
|
53
|
-
Option.getOrUndefined(row.newLine) ?? Option.getOrUndefined(row.oldLine)
|
|
54
|
-
|
|
55
|
-
export class DiffView {
|
|
56
|
-
private readonly code: CodeRenderable
|
|
57
|
-
private readonly numbers: LineNumberRenderable
|
|
58
|
-
private readonly pinned: CodeRenderable
|
|
59
|
-
private readonly pinBox: BoxRenderable
|
|
60
|
-
private pinnedText = ""
|
|
61
|
-
private shown: Patch | undefined
|
|
62
|
-
private noted = ""
|
|
63
|
-
private display: ReadonlyArray<Display> = []
|
|
64
|
-
private starts = new Map<number, number>()
|
|
65
|
-
private fitted = 1
|
|
66
|
-
|
|
67
|
-
constructor(renderer: CliRenderer) {
|
|
68
|
-
this.code = new CodeRenderable(renderer, {
|
|
69
|
-
id: "diff-code",
|
|
70
|
-
content: "",
|
|
71
|
-
syntaxStyle: SyntaxStyle.fromStyles(syntaxTheme),
|
|
72
|
-
treeSitterClient: getTreeSitterClient(),
|
|
73
|
-
drawUnstyledText: true,
|
|
74
|
-
conceal: false,
|
|
75
|
-
wrapMode: "none",
|
|
76
|
-
width: "100%",
|
|
77
|
-
})
|
|
78
|
-
this.numbers = new LineNumberRenderable(renderer, {
|
|
79
|
-
id: "diff-lines",
|
|
80
|
-
target: this.code,
|
|
81
|
-
fg: palette.faint,
|
|
82
|
-
minWidth: 4,
|
|
83
|
-
paddingRight: 1,
|
|
84
|
-
flexGrow: 1,
|
|
85
|
-
minHeight: 0,
|
|
86
|
-
showLineNumbers: true,
|
|
87
|
-
})
|
|
88
|
-
this.numbers.add(this.code)
|
|
89
|
-
this.pinned = new CodeRenderable(renderer, {
|
|
90
|
-
id: "diff-pin",
|
|
91
|
-
content: "",
|
|
92
|
-
syntaxStyle: SyntaxStyle.fromStyles(syntaxTheme),
|
|
93
|
-
treeSitterClient: getTreeSitterClient(),
|
|
94
|
-
drawUnstyledText: true,
|
|
95
|
-
conceal: false,
|
|
96
|
-
wrapMode: "none",
|
|
97
|
-
bg: palette.overlay,
|
|
98
|
-
flexGrow: 1,
|
|
99
|
-
})
|
|
100
|
-
this.pinBox = new BoxRenderable(renderer, {
|
|
101
|
-
id: "diff-pin-box",
|
|
102
|
-
height: 0,
|
|
103
|
-
flexShrink: 0,
|
|
104
|
-
flexDirection: "row",
|
|
105
|
-
backgroundColor: palette.overlay,
|
|
106
|
-
})
|
|
107
|
-
this.pinBox.add(this.pinned)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
pinNode(): BoxRenderable {
|
|
111
|
-
return this.pinBox
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
private noteRoom(): number {
|
|
115
|
-
return Math.max(NOTE_MIN, this.code.width - this.gutterWidth() - 3)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
gutterWidth(): number {
|
|
119
|
-
return Math.max(0, this.code.x - this.numbers.x) + SIGN_WIDTH
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
pin(lines: ReadonlyArray<string>): void {
|
|
123
|
-
const indent = this.gutterWidth()
|
|
124
|
-
if (this.pinBox.paddingLeft !== indent) this.pinBox.paddingLeft = indent
|
|
125
|
-
const text = lines.join("\n")
|
|
126
|
-
if (text === this.pinnedText) return
|
|
127
|
-
this.pinnedText = text
|
|
128
|
-
this.pinned.filetype = this.code.filetype
|
|
129
|
-
this.pinned.content = text
|
|
130
|
-
this.pinned.height = lines.length
|
|
131
|
-
this.pinBox.height = lines.length
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
node(): LineNumberRenderable {
|
|
135
|
-
return this.numbers
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
listenTo(handlers: {
|
|
139
|
-
readonly scroll: (delta: number) => void
|
|
140
|
-
readonly down: (y: number) => void
|
|
141
|
-
readonly drag: (y: number) => void
|
|
142
|
-
readonly dragEnd: (y: number) => void
|
|
143
|
-
}): void {
|
|
144
|
-
this.numbers.onMouseScroll = (event: { scroll?: { direction?: string; delta?: number } }) => {
|
|
145
|
-
const notches = Math.max(1, event.scroll?.delta ?? 1)
|
|
146
|
-
const size = notches * SCROLL_ROWS
|
|
147
|
-
handlers.scroll(event.scroll?.direction === "up" ? -size : size)
|
|
148
|
-
}
|
|
149
|
-
this.numbers.onMouseDown = (event: { y: number }) => handlers.down(event.y)
|
|
150
|
-
this.numbers.onMouseDrag = (event: { y: number }) => handlers.drag(event.y)
|
|
151
|
-
this.numbers.onMouseDragEnd = (event: { y: number }) => handlers.dragEnd(event.y)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
refresh(): void {
|
|
155
|
-
this.shown = undefined
|
|
156
|
-
this.code.requestRender()
|
|
157
|
-
this.numbers.requestRender()
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
screenTop(): number {
|
|
161
|
-
return this.code.y
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
fit(height: number): void {
|
|
165
|
-
const rows = Math.max(1, height)
|
|
166
|
-
if (rows !== this.fitted) {
|
|
167
|
-
this.fitted = rows
|
|
168
|
-
this.numbers.height = rows
|
|
169
|
-
this.code.height = rows
|
|
170
|
-
this.code.requestRender()
|
|
171
|
-
this.numbers.requestRender()
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
rows(): number {
|
|
176
|
-
return this.fitted
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
show(patch: Patch, notes: ReadonlyArray<Note>): void {
|
|
180
|
-
const room = notes.length === 0 ? NOTE_MIN : this.noteRoom()
|
|
181
|
-
const key = [room, ...notes.map((note) => `${note.side}${note.line}:${note.body}`)].join("\u0000")
|
|
182
|
-
if (patch === this.shown && key === this.noted) return
|
|
183
|
-
this.pinnedText = ""
|
|
184
|
-
this.shown = patch
|
|
185
|
-
this.noted = key
|
|
186
|
-
this.display = layout(patch, notes, room)
|
|
187
|
-
this.starts = new Map()
|
|
188
|
-
for (const [index, entry] of this.display.entries()) {
|
|
189
|
-
if (!entry.comment && !this.starts.has(entry.row)) this.starts.set(entry.row, index)
|
|
190
|
-
}
|
|
191
|
-
this.code.filetype = pathToFiletype(patch.path) ?? "text"
|
|
192
|
-
this.code.content = this.display.map((entry) => entry.text).join("\n")
|
|
193
|
-
this.numbers.setLineNumbers(lineNumbers(patch, this.display))
|
|
194
|
-
this.numbers.setHideLineNumbers(
|
|
195
|
-
new Set(this.display.flatMap((entry, index) => (entry.comment ? [index] : []))),
|
|
196
|
-
)
|
|
197
|
-
this.numbers.setLineSigns(lineSigns(patch, this.display))
|
|
198
|
-
this.numbers.setLineColors(new Map())
|
|
199
|
-
const spans = noteSpans(this.display)
|
|
200
|
-
this.code.onHighlight = (highlights) => [
|
|
201
|
-
...highlights.filter((highlight) => !spans.some(([from, to]) => highlight[0] < to && highlight[1] > from)),
|
|
202
|
-
...spans,
|
|
203
|
-
]
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
rowAt(display: number): number {
|
|
207
|
-
const at = Math.max(0, Math.min(this.display.length - 1, display))
|
|
208
|
-
return this.display[at]?.row ?? 0
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
isComment(display: number): boolean {
|
|
212
|
-
return this.display[display]?.comment === true
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
scrollTo(row: number, cursor: number): number {
|
|
216
|
-
const highest = Math.max(0, this.display.length - this.rows())
|
|
217
|
-
const wanted = this.starts.get(row) ?? row
|
|
218
|
-
const at = this.starts.get(cursor)
|
|
219
|
-
const expected = cursor >= row && cursor < row + this.rows()
|
|
220
|
-
const kept = expected && at !== undefined ? Math.max(wanted, at - this.rows() + 1) : wanted
|
|
221
|
-
const clamped = Math.max(0, Math.min(highest, kept))
|
|
222
|
-
if (this.code.scrollY !== clamped) this.code.scrollY = clamped
|
|
223
|
-
return clamped
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
paint(paintOf: (row: number) => LinePaint | undefined, from: number, rows: number): void {
|
|
227
|
-
const colors = new Map<number, LinePaint>()
|
|
228
|
-
const last = Math.min(this.display.length, from + rows + OVERSCAN)
|
|
229
|
-
for (let index = Math.max(0, from - OVERSCAN); index < last; index++) {
|
|
230
|
-
const entry = this.display[index]
|
|
231
|
-
if (entry === undefined) continue
|
|
232
|
-
const paint = entry.comment ? NOTE_PAINT : paintOf(entry.row)
|
|
233
|
-
if (paint !== undefined) colors.set(index, paint)
|
|
234
|
-
}
|
|
235
|
-
this.numbers.setLineColors(colors)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
washOf(kind: RowKind): LinePaint | undefined {
|
|
239
|
-
return WASH[kind]
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const noteSpans = (display: ReadonlyArray<Display>): ReadonlyArray<[number, number, string]> => {
|
|
244
|
-
const spans: Array<[number, number, string]> = []
|
|
245
|
-
let at = 0
|
|
246
|
-
for (const entry of display) {
|
|
247
|
-
if (entry.comment) {
|
|
248
|
-
const group = entry.label ? "note.label" : entry.sent ? "note.sent" : "note"
|
|
249
|
-
spans.push([at, at + entry.text.length, group])
|
|
250
|
-
}
|
|
251
|
-
at += entry.text.length + 1
|
|
252
|
-
}
|
|
253
|
-
return spans
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const NOTE_PAINT: LinePaint = {
|
|
257
|
-
gutter: RGBA.fromHex(palette.overlay),
|
|
258
|
-
content: RGBA.fromHex(palette.overlay),
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const wrap = (text: string, room: number): ReadonlyArray<string> => {
|
|
262
|
-
const words = text.split(/\s+/).filter((word) => word.length > 0)
|
|
263
|
-
if (words.length === 0) return [""]
|
|
264
|
-
const lines: Array<string> = []
|
|
265
|
-
for (const word of words) {
|
|
266
|
-
const last = lines.at(-1)
|
|
267
|
-
if (last === undefined || `${last} ${word}`.length > room) lines.push(word)
|
|
268
|
-
else lines[lines.length - 1] = `${last} ${word}`
|
|
269
|
-
}
|
|
270
|
-
return lines
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
const noteLines = (note: Note, room: number): ReadonlyArray<string> => [
|
|
274
|
-
note.sent ? `${marks().sent} sent` : `${marks().staged} staged`,
|
|
275
|
-
...note.body.split("\n").flatMap((line) => wrap(line, room)),
|
|
276
|
-
]
|
|
277
|
-
|
|
278
|
-
const noteRows = (note: Note, row: number, room: number): ReadonlyArray<Display> =>
|
|
279
|
-
noteLines(note, room).map((line, index) => ({
|
|
280
|
-
text: `${marks().rule} ${line}`,
|
|
281
|
-
row,
|
|
282
|
-
comment: true,
|
|
283
|
-
sent: note.sent,
|
|
284
|
-
label: index === 0,
|
|
285
|
-
}))
|
|
286
|
-
|
|
287
|
-
const layout = (
|
|
288
|
-
patch: Patch,
|
|
289
|
-
notes: ReadonlyArray<Note>,
|
|
290
|
-
room: number,
|
|
291
|
-
): ReadonlyArray<Display> => {
|
|
292
|
-
const display: Array<Display> = []
|
|
293
|
-
for (const row of patch.rows) {
|
|
294
|
-
display.push({ text: row.text, row: row.index, comment: false, sent: false, label: false })
|
|
295
|
-
for (const note of notes) {
|
|
296
|
-
if (sideLineOf(row, note.side) === note.line) {
|
|
297
|
-
display.push(...noteRows(note, row.index, room))
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return display
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const lineNumbers = (patch: Patch, display: ReadonlyArray<Display>): Map<number, number> => {
|
|
305
|
-
const numbers = new Map<number, number>()
|
|
306
|
-
const rows = new Map(patch.rows.map((row) => [row.index, row]))
|
|
307
|
-
for (const [index, entry] of display.entries()) {
|
|
308
|
-
const row = entry.comment ? undefined : rows.get(entry.row)
|
|
309
|
-
const line = row === undefined ? undefined : numberFor(row)
|
|
310
|
-
if (line !== undefined) numbers.set(index, line)
|
|
311
|
-
}
|
|
312
|
-
return numbers
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
const lineSigns = (
|
|
316
|
-
patch: Patch,
|
|
317
|
-
display: ReadonlyArray<Display>,
|
|
318
|
-
): Map<number, { after: string; afterColor: string }> => {
|
|
319
|
-
const signs = new Map<number, { after: string; afterColor: string }>()
|
|
320
|
-
const rows = new Map(patch.rows.map((row) => [row.index, row]))
|
|
321
|
-
for (const [index, entry] of display.entries()) {
|
|
322
|
-
const row = rows.get(entry.row)
|
|
323
|
-
const sign = entry.comment || row === undefined ? undefined : SIGNS[row.kind]
|
|
324
|
-
signs.set(index, {
|
|
325
|
-
after: sign?.text ?? " ",
|
|
326
|
-
afterColor: sign?.color ?? palette.accent,
|
|
327
|
-
})
|
|
328
|
-
}
|
|
329
|
-
return signs
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
export const sideLineOf = (row: Row, side: "old" | "new"): number | undefined =>
|
|
333
|
-
Option.getOrUndefined(lineOn(row, side))
|