@eliya-oss/agent-diff 0.1.0-alpha.1 → 0.1.0-alpha.3
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/CHANGELOG.md +12 -0
- package/README.md +10 -4
- package/bin/adiff.js +76 -2
- package/dist/main.js +14467 -0
- package/package.json +8 -6
- package/skills/adiff/SKILL.md +14 -0
- 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/render.ts
DELETED
|
@@ -1,897 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BoxRenderable,
|
|
3
|
-
SelectRenderable,
|
|
4
|
-
RGBA,
|
|
5
|
-
TextRenderable,
|
|
6
|
-
type CliRenderer,
|
|
7
|
-
} from "@opentui/core"
|
|
8
|
-
import { ASCIIFontRenderable, bg, fg, StyledText, t } from "@opentui/core"
|
|
9
|
-
import { hintsFor } from "./command.ts"
|
|
10
|
-
import { stickyChain, type RowKind } from "../domain/patch/index.ts"
|
|
11
|
-
import { DiffView, type LinePaint, type Note } from "./diffview.ts"
|
|
12
|
-
import { paletteMatches } from "./reduce.ts"
|
|
13
|
-
import {
|
|
14
|
-
composeTarget,
|
|
15
|
-
commentsOn,
|
|
16
|
-
hiddenLines,
|
|
17
|
-
isReviewed,
|
|
18
|
-
markedRows,
|
|
19
|
-
newLineAt,
|
|
20
|
-
onSteps,
|
|
21
|
-
selectionReadout,
|
|
22
|
-
stepWindow,
|
|
23
|
-
snippetOf,
|
|
24
|
-
reviewedCount,
|
|
25
|
-
selectedBranch,
|
|
26
|
-
selectedPatch,
|
|
27
|
-
selectionRange,
|
|
28
|
-
treeWindow,
|
|
29
|
-
type TuiState,
|
|
30
|
-
WHOLE_FILE,
|
|
31
|
-
type StagedComment,
|
|
32
|
-
} from "./model.ts"
|
|
33
|
-
import type { TreeRow } from "./tree.ts"
|
|
34
|
-
import { marks } from "./marks.ts"
|
|
35
|
-
import { palette } from "./theme.ts"
|
|
36
|
-
|
|
37
|
-
const ROW_HEIGHT = 1
|
|
38
|
-
const COMPOSE_WIDTH = 72
|
|
39
|
-
const GUTTER_X = 2
|
|
40
|
-
const CHIP_GAP = 4
|
|
41
|
-
const FRAME_PAD = 1
|
|
42
|
-
const MODAL_ROOM = 8
|
|
43
|
-
const COMPOSE_CHROME = 3
|
|
44
|
-
const COMPOSE_ACTION_ROWS = 2
|
|
45
|
-
|
|
46
|
-
const reportActions = (): StyledText =>
|
|
47
|
-
t`${fg(palette.accent)("esc")} ${fg(palette.muted)("cancel")} ${fg(palette.accent)("^s")} ${fg(palette.muted)("copy and save")}`
|
|
48
|
-
|
|
49
|
-
const actionsText = (): StyledText =>
|
|
50
|
-
t`${fg(palette.accent)("esc")} ${fg(palette.muted)("cancel")} ${fg(palette.accent)("^a")} ${fg(palette.muted)("add to review")} ${fg(palette.accent)("^s")} ${fg(palette.muted)("comment now")}`
|
|
51
|
-
const SNIPPET_LINES = 4
|
|
52
|
-
const PALETTE_MAX = 18
|
|
53
|
-
const PALETTE_CHROME = 4
|
|
54
|
-
const PENDING_CHROME = 3
|
|
55
|
-
const PALETTE_WIDTH = 76
|
|
56
|
-
const TREE_MAX = 34
|
|
57
|
-
const TREE_MIN = 18
|
|
58
|
-
const TREE_SHARE = 0.3
|
|
59
|
-
const DIFF_MIN = 24
|
|
60
|
-
const BODY_BORDER = 2
|
|
61
|
-
const PANE_CHROME = 3
|
|
62
|
-
const BRANCH_WIDTH = 82
|
|
63
|
-
const BRANCH_NAME = 44
|
|
64
|
-
const BRANCH_NAME_MIN = 12
|
|
65
|
-
const BRANCH_TAIL = 35
|
|
66
|
-
const MODAL_MARGIN = 4
|
|
67
|
-
|
|
68
|
-
const bodyRoom = (width: number): number => Math.max(0, width - FRAME_PAD * 2 - BODY_BORDER)
|
|
69
|
-
|
|
70
|
-
const treeWidth = (width: number): number => {
|
|
71
|
-
const room = bodyRoom(width)
|
|
72
|
-
const wanted = Math.min(TREE_MAX, Math.max(TREE_MIN, Math.floor(room * TREE_SHARE)))
|
|
73
|
-
return Math.max(0, Math.min(wanted, room - DIFF_MIN))
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const homeWidth = (width: number): number =>
|
|
77
|
-
Math.max(0, Math.min(BRANCH_WIDTH, width - FRAME_PAD * 2))
|
|
78
|
-
|
|
79
|
-
const modalWidth = (width: number, wanted: number): number =>
|
|
80
|
-
Math.max(0, Math.min(wanted, width - MODAL_MARGIN))
|
|
81
|
-
|
|
82
|
-
const STICKY_MAX = 4
|
|
83
|
-
|
|
84
|
-
type PaintFlags = { readonly cursor: boolean; readonly selected: boolean }
|
|
85
|
-
|
|
86
|
-
const pickPaint = (view: DiffView, kind: RowKind, flags: PaintFlags): LinePaint | undefined => {
|
|
87
|
-
if (flags.cursor) return { gutter: ACCENT, content: CURSOR }
|
|
88
|
-
if (flags.selected) return { gutter: SELECTION, content: SELECTION }
|
|
89
|
-
return view.washOf(kind)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const SELECTION = RGBA.fromHex(palette.selection)
|
|
93
|
-
const CURSOR = RGBA.fromHex(palette.cursor)
|
|
94
|
-
const ACCENT = RGBA.fromHex(palette.accent)
|
|
95
|
-
|
|
96
|
-
const bar = (renderer: CliRenderer, id: string, color: string): TextRenderable =>
|
|
97
|
-
new TextRenderable(renderer, {
|
|
98
|
-
id,
|
|
99
|
-
content: "",
|
|
100
|
-
fg: color,
|
|
101
|
-
height: ROW_HEIGHT,
|
|
102
|
-
flexShrink: 0,
|
|
103
|
-
marginLeft: GUTTER_X,
|
|
104
|
-
marginRight: GUTTER_X,
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
const makeList = (renderer: CliRenderer): BoxRenderable => {
|
|
108
|
-
const box = new BoxRenderable(renderer, {
|
|
109
|
-
id: "list-pane",
|
|
110
|
-
width: BRANCH_WIDTH,
|
|
111
|
-
flexShrink: 0,
|
|
112
|
-
flexDirection: "column",
|
|
113
|
-
minHeight: 0,
|
|
114
|
-
overflow: "hidden",
|
|
115
|
-
border: ["right"],
|
|
116
|
-
borderColor: palette.rule,
|
|
117
|
-
})
|
|
118
|
-
return box
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const makeDiffPane = (renderer: CliRenderer): BoxRenderable =>
|
|
122
|
-
new BoxRenderable(renderer, {
|
|
123
|
-
id: "diff-pane",
|
|
124
|
-
flexGrow: 1,
|
|
125
|
-
flexDirection: "column",
|
|
126
|
-
minWidth: 0,
|
|
127
|
-
minHeight: 0,
|
|
128
|
-
overflow: "hidden",
|
|
129
|
-
visible: false,
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
const makeListParts = (renderer: CliRenderer): { pane: BoxRenderable; text: TextRenderable } => {
|
|
133
|
-
const pane = makeList(renderer)
|
|
134
|
-
const text = makeListText(renderer)
|
|
135
|
-
pane.add(text)
|
|
136
|
-
return { pane, text }
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const makeListText = (renderer: CliRenderer): TextRenderable =>
|
|
140
|
-
new TextRenderable(renderer, {
|
|
141
|
-
id: "list",
|
|
142
|
-
content: "",
|
|
143
|
-
fg: palette.ink,
|
|
144
|
-
flexGrow: 1,
|
|
145
|
-
wrapMode: "none",
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
const makeGutter = (renderer: CliRenderer): TextRenderable =>
|
|
149
|
-
new TextRenderable(renderer, {
|
|
150
|
-
id: "gutter",
|
|
151
|
-
content: "",
|
|
152
|
-
fg: palette.marker,
|
|
153
|
-
width: 2,
|
|
154
|
-
flexShrink: 0,
|
|
155
|
-
wrapMode: "none",
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
const makeScroller = (
|
|
159
|
-
renderer: CliRenderer,
|
|
160
|
-
gutter: TextRenderable,
|
|
161
|
-
scroll: BoxRenderable,
|
|
162
|
-
): BoxRenderable => {
|
|
163
|
-
const box = new BoxRenderable(renderer, {
|
|
164
|
-
id: "scroller",
|
|
165
|
-
flexGrow: 1,
|
|
166
|
-
flexDirection: "row",
|
|
167
|
-
minHeight: 0,
|
|
168
|
-
})
|
|
169
|
-
box.add(gutter)
|
|
170
|
-
box.add(scroll)
|
|
171
|
-
return box
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const makeScrim = (renderer: CliRenderer): BoxRenderable =>
|
|
175
|
-
new BoxRenderable(renderer, {
|
|
176
|
-
id: "scrim",
|
|
177
|
-
position: "absolute",
|
|
178
|
-
left: 0,
|
|
179
|
-
top: 0,
|
|
180
|
-
width: "100%",
|
|
181
|
-
height: "100%",
|
|
182
|
-
zIndex: 90,
|
|
183
|
-
visible: false,
|
|
184
|
-
backgroundColor: palette.scrim,
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
const makeScroll = (renderer: CliRenderer): BoxRenderable =>
|
|
188
|
-
new BoxRenderable(renderer, {
|
|
189
|
-
id: "diff-scroll",
|
|
190
|
-
flexGrow: 1,
|
|
191
|
-
flexDirection: "column",
|
|
192
|
-
minHeight: 0,
|
|
193
|
-
minWidth: 0,
|
|
194
|
-
overflow: "hidden",
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
const makePalette = (renderer: CliRenderer): BoxRenderable => {
|
|
198
|
-
const box = makeCompose(renderer)
|
|
199
|
-
box.id = "palette"
|
|
200
|
-
box.height = PALETTE_MAX
|
|
201
|
-
box.width = PALETTE_WIDTH
|
|
202
|
-
return box
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
type PaletteParts = {
|
|
206
|
-
readonly box: BoxRenderable
|
|
207
|
-
readonly title: TextRenderable
|
|
208
|
-
readonly query: TextRenderable
|
|
209
|
-
readonly choices: SelectRenderable
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const makePaletteParts = (renderer: CliRenderer): PaletteParts => {
|
|
213
|
-
const box = makePalette(renderer)
|
|
214
|
-
const title = bar(renderer, "palette-title", palette.faint)
|
|
215
|
-
const query = bar(renderer, "palette-query", palette.ink)
|
|
216
|
-
const choices = makeChoices(renderer)
|
|
217
|
-
box.add(title)
|
|
218
|
-
box.add(query)
|
|
219
|
-
box.add(choices)
|
|
220
|
-
return { box, title, query, choices }
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const makePendingParts = (renderer: CliRenderer): PaletteParts => {
|
|
224
|
-
const parts = makePaletteParts(renderer)
|
|
225
|
-
parts.box.id = "pending"
|
|
226
|
-
parts.query.height = 0
|
|
227
|
-
return parts
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const makeChoices = (renderer: CliRenderer): SelectRenderable =>
|
|
231
|
-
new SelectRenderable(renderer, {
|
|
232
|
-
id: "palette-choices",
|
|
233
|
-
flexGrow: 1,
|
|
234
|
-
options: [],
|
|
235
|
-
showDescription: false,
|
|
236
|
-
showScrollIndicator: true,
|
|
237
|
-
showSelectionIndicator: true,
|
|
238
|
-
wrapSelection: false,
|
|
239
|
-
backgroundColor: palette.panel,
|
|
240
|
-
textColor: palette.ink,
|
|
241
|
-
descriptionColor: palette.faint,
|
|
242
|
-
selectedBackgroundColor: palette.selection,
|
|
243
|
-
selectedTextColor: palette.ink,
|
|
244
|
-
selectedDescriptionColor: palette.ink,
|
|
245
|
-
})
|
|
246
|
-
|
|
247
|
-
const stack = (parent: { add: (child: never) => void }, children: ReadonlyArray<unknown>): void => {
|
|
248
|
-
for (const child of children) parent.add(child as never)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const makeBody = (renderer: CliRenderer): BoxRenderable =>
|
|
252
|
-
new BoxRenderable(renderer, {
|
|
253
|
-
id: "body",
|
|
254
|
-
flexGrow: 1,
|
|
255
|
-
flexDirection: "row",
|
|
256
|
-
minHeight: 0,
|
|
257
|
-
minWidth: 0,
|
|
258
|
-
overflow: "hidden",
|
|
259
|
-
})
|
|
260
|
-
|
|
261
|
-
const makeHome = (renderer: CliRenderer) => ({
|
|
262
|
-
logo: makeLogo(renderer),
|
|
263
|
-
path: makeLanding(renderer, "landing", palette.muted, 0),
|
|
264
|
-
keys: makeLanding(renderer, "landing-keys", palette.faint, 2),
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
const makeModals = (renderer: CliRenderer) => ({
|
|
268
|
-
palette: makePaletteParts(renderer),
|
|
269
|
-
staged: makePendingParts(renderer),
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
const FONTS = ["tiny", "block", "shade", "slick", "huge", "grid", "pallet"] as const
|
|
273
|
-
|
|
274
|
-
const logoFont = (): (typeof FONTS)[number] => {
|
|
275
|
-
const wanted = process.env["ADIFF_FONT"] ?? ""
|
|
276
|
-
return FONTS.find((name) => name === wanted) ?? "tiny"
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
const makeLanding = (
|
|
280
|
-
renderer: CliRenderer,
|
|
281
|
-
id: string,
|
|
282
|
-
color: string,
|
|
283
|
-
top: number,
|
|
284
|
-
): TextRenderable =>
|
|
285
|
-
new TextRenderable(renderer, {
|
|
286
|
-
id,
|
|
287
|
-
content: "",
|
|
288
|
-
fg: color,
|
|
289
|
-
alignSelf: "center",
|
|
290
|
-
marginTop: top,
|
|
291
|
-
marginBottom: top === 0 ? 2 : 0,
|
|
292
|
-
flexShrink: 0,
|
|
293
|
-
})
|
|
294
|
-
|
|
295
|
-
const makeLogo = (renderer: CliRenderer): ASCIIFontRenderable =>
|
|
296
|
-
new ASCIIFontRenderable(renderer, {
|
|
297
|
-
id: "logo",
|
|
298
|
-
text: "adiff",
|
|
299
|
-
font: logoFont(),
|
|
300
|
-
color: palette.accent,
|
|
301
|
-
alignSelf: "center",
|
|
302
|
-
marginBottom: 2,
|
|
303
|
-
flexShrink: 0,
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
const makeComposeParts = (
|
|
307
|
-
renderer: CliRenderer,
|
|
308
|
-
): {
|
|
309
|
-
readonly title: TextRenderable
|
|
310
|
-
readonly body: TextRenderable
|
|
311
|
-
readonly actions: TextRenderable
|
|
312
|
-
} => ({
|
|
313
|
-
title: new TextRenderable(renderer, { id: "compose-title", content: "", fg: palette.ink }),
|
|
314
|
-
body: new TextRenderable(renderer, { id: "compose-body", content: "", fg: palette.ink }),
|
|
315
|
-
actions: new TextRenderable(renderer, {
|
|
316
|
-
id: "compose-actions",
|
|
317
|
-
content: "",
|
|
318
|
-
fg: palette.muted,
|
|
319
|
-
marginTop: 1,
|
|
320
|
-
}),
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
const makeCompose = (renderer: CliRenderer): BoxRenderable =>
|
|
324
|
-
new BoxRenderable(renderer, {
|
|
325
|
-
id: "compose",
|
|
326
|
-
position: "absolute",
|
|
327
|
-
width: COMPOSE_WIDTH,
|
|
328
|
-
height: COMPOSE_CHROME,
|
|
329
|
-
zIndex: 100,
|
|
330
|
-
visible: false,
|
|
331
|
-
backgroundColor: palette.panel,
|
|
332
|
-
border: ["left"],
|
|
333
|
-
borderStyle: "heavy",
|
|
334
|
-
borderColor: palette.accent,
|
|
335
|
-
paddingLeft: GUTTER_X,
|
|
336
|
-
paddingRight: GUTTER_X,
|
|
337
|
-
paddingTop: 1,
|
|
338
|
-
paddingBottom: 1,
|
|
339
|
-
flexDirection: "column",
|
|
340
|
-
})
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
const clip = (label: string, room: number): string =>
|
|
344
|
-
label.length > room ? `${label.slice(0, Math.max(0, room - 1))}…` : label
|
|
345
|
-
|
|
346
|
-
const treeLabel = (state: TuiState, row: TreeRow): string => {
|
|
347
|
-
const indent = " ".repeat(row.depth)
|
|
348
|
-
if (row.kind === "file") return `${indent} ${marks().file} ${row.name}`
|
|
349
|
-
const shut = state.closed.includes(row.path)
|
|
350
|
-
return `${indent}${shut ? "▸" : "▾"} ${shut ? marks().folder : marks().folderOpen} ${row.name}`
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
const waitingLabel = (branch: TuiState["branches"][number]): string => {
|
|
354
|
-
if (branch.staged > 0) return `${branch.staged} staged`
|
|
355
|
-
return branch.unread > 0 ? `${branch.unread} unread` : ""
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
const notesOf = (
|
|
359
|
-
comments: ReadonlyArray<StagedComment>,
|
|
360
|
-
path: string,
|
|
361
|
-
sent: boolean,
|
|
362
|
-
): ReadonlyArray<Note> =>
|
|
363
|
-
comments
|
|
364
|
-
.filter((entry) => entry.file === path)
|
|
365
|
-
.map((entry) => ({ side: entry.side, line: entry.end, body: entry.body, sent }))
|
|
366
|
-
|
|
367
|
-
const notesFor = (state: TuiState, path: string): ReadonlyArray<Note> => [
|
|
368
|
-
...notesOf(state.sent, path, true),
|
|
369
|
-
...notesOf(state.pending, path, false),
|
|
370
|
-
]
|
|
371
|
-
|
|
372
|
-
const shortPath = (path: string): string => {
|
|
373
|
-
const home = process.env["HOME"] ?? ""
|
|
374
|
-
return home.length > 0 && path.startsWith(home) ? `~${path.slice(home.length)}` : path
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const contextLabel = (context: number): string => {
|
|
378
|
-
if (context === 3) return ""
|
|
379
|
-
return context >= WHOLE_FILE ? "whole file" : `±${context}`
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
type Cells = {
|
|
383
|
-
readonly name: string
|
|
384
|
-
readonly files: string
|
|
385
|
-
readonly added: string
|
|
386
|
-
readonly gone: string
|
|
387
|
-
readonly state: string
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
const nameRoom = (pane: number): number =>
|
|
391
|
-
Math.max(BRANCH_NAME_MIN, Math.min(BRANCH_NAME, pane - BRANCH_TAIL))
|
|
392
|
-
|
|
393
|
-
const columns = (cells: Cells, room: number): string =>
|
|
394
|
-
`${clip(cells.name, room).padEnd(room)}${cells.files.padStart(5)}${cells.added.padStart(8)}${cells.gone.padStart(8)} ${cells.state}`
|
|
395
|
-
|
|
396
|
-
const branchHeading = (room: number): string =>
|
|
397
|
-
` ${columns({ name: "WORKTREE", files: "FILES", added: "+", gone: "-", state: "STATE" }, room)}`
|
|
398
|
-
|
|
399
|
-
const atHome = (state: TuiState): boolean =>
|
|
400
|
-
state.screen === "branches" || (state.screen === "palette" && state.returnTo === "branches")
|
|
401
|
-
|
|
402
|
-
const branchCells = (branch: TuiState["branches"][number], here: boolean, room: number) => ({
|
|
403
|
-
lead: `${here ? marks().cursor : " "} `,
|
|
404
|
-
name: clip(branch.branch, room).padEnd(room),
|
|
405
|
-
files: `${branch.files}`.padStart(5),
|
|
406
|
-
added: `+${branch.added}`.padStart(8),
|
|
407
|
-
gone: `-${branch.removed}`.padStart(8),
|
|
408
|
-
state: waitingLabel(branch).trim(),
|
|
409
|
-
})
|
|
410
|
-
|
|
411
|
-
const headerParts = (state: TuiState, branch: string, path: string): ReadonlyArray<string> => [
|
|
412
|
-
branch,
|
|
413
|
-
path,
|
|
414
|
-
`${state.patchIndex + 1}/${state.patches.length}`,
|
|
415
|
-
state.vouched.length === 0 ? "" : reviewedCount(state),
|
|
416
|
-
state.staged === 0 ? "" : `${state.staged} staged`,
|
|
417
|
-
contextLabel(state.context),
|
|
418
|
-
hiddenLines(state) === 0 ? "" : `⋯ ${hiddenLines(state)} lines hidden`,
|
|
419
|
-
]
|
|
420
|
-
|
|
421
|
-
const fallbackScope = (state: TuiState, top: number): ReadonlyArray<string> => {
|
|
422
|
-
const found = selectedPatch(state)?.hunks.findLast((hunk) => hunk.startRow < top)
|
|
423
|
-
const scope = found?.scope ?? ""
|
|
424
|
-
return scope.length === 0 ? [] : [scope]
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
const treeMarks = (state: TuiState, row: TreeRow): string => {
|
|
428
|
-
const current = row.fileIndex === state.patchIndex
|
|
429
|
-
const here = current ? (state.focus === "tree" ? "▸" : "·") : " "
|
|
430
|
-
const seen = row.fileIndex !== undefined && isReviewed(state, row.fileIndex) ? marks().reviewed : " "
|
|
431
|
-
return `${here}${seen}`
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
const treeTail = (state: TuiState, row: TreeRow): string => {
|
|
435
|
-
if (row.fileIndex === undefined) return " "
|
|
436
|
-
const comments = commentsOn(state, row.fileIndex)
|
|
437
|
-
return comments > 0 ? `${comments}${marks().tally}`.padStart(3) : " "
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
const treeLine = (state: TuiState, row: TreeRow, pane: number): string => {
|
|
441
|
-
const tail = treeTail(state, row)
|
|
442
|
-
const room = Math.max(4, pane - PANE_CHROME - 2 - tail.length)
|
|
443
|
-
return `${treeMarks(state, row)}${clip(treeLabel(state, row), room).padEnd(room)}${tail}`
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
const STEP_NUMBER = 3
|
|
447
|
-
|
|
448
|
-
const stepLine = (state: TuiState, index: number, pane: number): string => {
|
|
449
|
-
const step = state.steps[index]
|
|
450
|
-
if (step === undefined) return ""
|
|
451
|
-
const here = index === state.stepIndex
|
|
452
|
-
const mark = here ? (state.focus === "tree" ? "▸" : "·") : " "
|
|
453
|
-
const number = `${index + 1}.`.padStart(STEP_NUMBER)
|
|
454
|
-
const tail = `${step.files.length}`
|
|
455
|
-
const room = Math.max(4, pane - PANE_CHROME - STEP_NUMBER - tail.length - 3)
|
|
456
|
-
return `${mark} ${number} ${clip(step.title, room).padEnd(room)}${tail}`
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
export type Mouse = {
|
|
460
|
-
readonly onScroll: (delta: number) => void
|
|
461
|
-
readonly onDrag: (from: number, to: number, done: boolean) => void
|
|
462
|
-
readonly onChip: (key: string) => void
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
export class Screen {
|
|
466
|
-
private readonly header: TextRenderable
|
|
467
|
-
private readonly body: BoxRenderable
|
|
468
|
-
private readonly listPane: BoxRenderable
|
|
469
|
-
private readonly list: TextRenderable
|
|
470
|
-
private readonly diffPane: BoxRenderable
|
|
471
|
-
private readonly scrim: BoxRenderable
|
|
472
|
-
private readonly gutter: TextRenderable
|
|
473
|
-
private readonly diffScroll: BoxRenderable
|
|
474
|
-
private readonly view: DiffView
|
|
475
|
-
private readonly compose: BoxRenderable
|
|
476
|
-
private readonly repo: string
|
|
477
|
-
private readonly logo: ASCIIFontRenderable
|
|
478
|
-
private readonly landing: TextRenderable
|
|
479
|
-
private readonly landingKeys: TextRenderable
|
|
480
|
-
private hovered = -1
|
|
481
|
-
private lead = 0
|
|
482
|
-
private shown: TuiState | undefined
|
|
483
|
-
private chips: ReadonlyArray<{ key: string; hint: string; press: string }> = []
|
|
484
|
-
private readonly composeTitle: TextRenderable
|
|
485
|
-
private readonly composeBody: TextRenderable
|
|
486
|
-
private readonly composeActions: TextRenderable
|
|
487
|
-
private readonly footer: TextRenderable
|
|
488
|
-
private readonly palette: BoxRenderable
|
|
489
|
-
private readonly paletteTitle: TextRenderable
|
|
490
|
-
private readonly paletteQuery: TextRenderable
|
|
491
|
-
private readonly paletteChoices: SelectRenderable
|
|
492
|
-
private readonly pending: BoxRenderable
|
|
493
|
-
private readonly pendingTitle: TextRenderable
|
|
494
|
-
private readonly pendingChoices: SelectRenderable
|
|
495
|
-
|
|
496
|
-
private readonly renderer: CliRenderer
|
|
497
|
-
|
|
498
|
-
private mouse: Mouse | undefined
|
|
499
|
-
private dragFrom: number | undefined
|
|
500
|
-
private lastTop = 0
|
|
501
|
-
|
|
502
|
-
constructor(renderer: CliRenderer, repo = "") {
|
|
503
|
-
this.renderer = renderer
|
|
504
|
-
this.repo = repo
|
|
505
|
-
renderer.root.flexDirection = "column"
|
|
506
|
-
renderer.root.paddingLeft = FRAME_PAD
|
|
507
|
-
renderer.root.paddingRight = FRAME_PAD
|
|
508
|
-
renderer.root.paddingTop = FRAME_PAD
|
|
509
|
-
renderer.root.paddingBottom = FRAME_PAD
|
|
510
|
-
|
|
511
|
-
this.header = bar(renderer, "header", palette.ink)
|
|
512
|
-
this.footer = bar(renderer, "footer", palette.faint)
|
|
513
|
-
this.body = makeBody(renderer)
|
|
514
|
-
const list = makeListParts(renderer)
|
|
515
|
-
this.listPane = list.pane
|
|
516
|
-
this.list = list.text
|
|
517
|
-
const home = makeHome(renderer)
|
|
518
|
-
this.logo = home.logo
|
|
519
|
-
this.landing = home.path
|
|
520
|
-
this.landingKeys = home.keys
|
|
521
|
-
this.diffPane = makeDiffPane(renderer)
|
|
522
|
-
this.diffScroll = makeScroll(renderer)
|
|
523
|
-
this.view = new DiffView(renderer)
|
|
524
|
-
const inside = makeComposeParts(renderer)
|
|
525
|
-
this.compose = makeCompose(renderer)
|
|
526
|
-
this.composeTitle = inside.title
|
|
527
|
-
this.composeBody = inside.body
|
|
528
|
-
this.composeActions = inside.actions
|
|
529
|
-
this.scrim = makeScrim(renderer)
|
|
530
|
-
this.gutter = makeGutter(renderer)
|
|
531
|
-
const modals = makeModals(renderer)
|
|
532
|
-
this.palette = modals.palette.box
|
|
533
|
-
this.paletteTitle = modals.palette.title
|
|
534
|
-
this.paletteQuery = modals.palette.query
|
|
535
|
-
this.paletteChoices = modals.palette.choices
|
|
536
|
-
this.pending = modals.staged.box
|
|
537
|
-
this.pendingTitle = modals.staged.title
|
|
538
|
-
this.pendingChoices = modals.staged.choices
|
|
539
|
-
|
|
540
|
-
this.assemble(renderer)
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
listen(mouse: Mouse): void {
|
|
544
|
-
this.mouse = mouse
|
|
545
|
-
this.view.listenTo({
|
|
546
|
-
scroll: (delta) => this.mouse?.onScroll(delta),
|
|
547
|
-
down: (y) => {
|
|
548
|
-
this.dragFrom = this.rowAtY(y)
|
|
549
|
-
this.mouse?.onDrag(this.dragFrom, this.dragFrom, false)
|
|
550
|
-
},
|
|
551
|
-
drag: (y) => {
|
|
552
|
-
if (this.dragFrom === undefined) return
|
|
553
|
-
this.mouse?.onDrag(this.dragFrom, this.rowAtY(y), false)
|
|
554
|
-
},
|
|
555
|
-
dragEnd: (y) => {
|
|
556
|
-
if (this.dragFrom === undefined) return
|
|
557
|
-
this.mouse?.onDrag(this.dragFrom, this.rowAtY(y), true)
|
|
558
|
-
this.dragFrom = undefined
|
|
559
|
-
},
|
|
560
|
-
})
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
private rowAtY(y: number): number {
|
|
564
|
-
return this.view.rowAt(Math.max(0, y - this.view.screenTop() + this.lastTop))
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
viewportRows(): number {
|
|
568
|
-
return this.diffRows()
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
private diffRows(): number {
|
|
572
|
-
return Math.max(1, this.diffScroll.height)
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
update(state: TuiState): void {
|
|
576
|
-
this.shown = state
|
|
577
|
-
this.chips = hintsFor(state.screen, state.staged)
|
|
578
|
-
this.header.content = this.headerText(state)
|
|
579
|
-
this.footer.content = this.footerText(state)
|
|
580
|
-
this.list.content = this.listText(state)
|
|
581
|
-
const many = state.branches.length === 1 ? "1 worktree" : `${state.branches.length} worktrees`
|
|
582
|
-
this.landing.content = `${shortPath(this.repo)} · ${many}`
|
|
583
|
-
this.landingKeys.content = this.chipRow()
|
|
584
|
-
this.diffPane.visible = state.screen !== "branches" && !(state.screen === "palette" && state.returnTo === "branches")
|
|
585
|
-
if (this.diffPane.visible) this.paintDiff(state)
|
|
586
|
-
this.paintPane(state)
|
|
587
|
-
this.paintCompose(state)
|
|
588
|
-
this.paintPalette(state)
|
|
589
|
-
this.paintPending(state)
|
|
590
|
-
this.paintReport(state)
|
|
591
|
-
this.scrim.visible = state.screen !== "branches" && state.screen !== "review"
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
private paintPalette(state: TuiState): void {
|
|
595
|
-
this.palette.visible = state.screen === "palette"
|
|
596
|
-
if (state.screen !== "palette") {
|
|
597
|
-
this.paletteQuery.content = ""
|
|
598
|
-
this.paletteTitle.content = ""
|
|
599
|
-
this.paletteChoices.options = []
|
|
600
|
-
return
|
|
601
|
-
}
|
|
602
|
-
const matches = paletteMatches(state)
|
|
603
|
-
this.paletteTitle.content = matches.length === 0 ? "No command matches" : "Commands"
|
|
604
|
-
this.paletteQuery.content =
|
|
605
|
-
state.query.length === 0 ? "Type to filter…" : `${state.query}▏`
|
|
606
|
-
this.paletteChoices.options = matches.map((entry) => ({
|
|
607
|
-
name: `${entry.title.padEnd(34)}${entry.category}`,
|
|
608
|
-
description: "",
|
|
609
|
-
value: entry.action,
|
|
610
|
-
}))
|
|
611
|
-
const room = modalWidth(this.renderer.width, PALETTE_WIDTH)
|
|
612
|
-
this.paletteChoices.selectedIndex = Math.min(state.paletteIndex, Math.max(0, matches.length - 1))
|
|
613
|
-
this.palette.height = Math.min(PALETTE_MAX, matches.length + PALETTE_CHROME)
|
|
614
|
-
this.palette.width = room
|
|
615
|
-
this.palette.left = Math.max(FRAME_PAD, Math.floor((this.renderer.width - room) / 2))
|
|
616
|
-
this.palette.top = Math.max(2, Math.floor(this.renderer.height / 4))
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
private headerText(state: TuiState): StyledText {
|
|
620
|
-
const branch = selectedBranch(state)
|
|
621
|
-
if (atHome(state)) {
|
|
622
|
-
return t`${fg(palette.faint)("")}`
|
|
623
|
-
}
|
|
624
|
-
const patch = selectedPatch(state)
|
|
625
|
-
const [name = "", ...rest] = headerParts(state, branch?.branch ?? "", patch?.path ?? "").filter(
|
|
626
|
-
(part) => part.length > 0,
|
|
627
|
-
)
|
|
628
|
-
return t`${fg(palette.ink)(name)} ${fg(palette.muted)(rest.join(" "))}`
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
private footerText(state: TuiState): StyledText {
|
|
632
|
-
const readout = selectionReadout(state)
|
|
633
|
-
this.lead = readout.length === 0 ? 0 : readout.length + 3
|
|
634
|
-
const lead = readout.length === 0 ? [] : [fg(palette.muted)(`${readout} `)]
|
|
635
|
-
const notice = state.notice.length === 0 ? [] : [fg(palette.attention)(` ${state.notice}`)]
|
|
636
|
-
return new StyledText([...lead, ...this.chipRow().chunks, ...notice])
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
private paneRoom(): number {
|
|
640
|
-
return treeWidth(this.renderer.width)
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
private listText(state: TuiState): string | StyledText {
|
|
644
|
-
if (atHome(state)) return this.branchTable(state)
|
|
645
|
-
if (onSteps(state)) return this.stepRail(state)
|
|
646
|
-
const height = Math.max(1, this.listPane.height - 1)
|
|
647
|
-
const pane = this.paneRoom()
|
|
648
|
-
const window = treeWindow(state, height)
|
|
649
|
-
const rows = window.rows.flatMap((row) => [
|
|
650
|
-
fg(row.kind === "file" ? palette.ink : palette.muted)(`${treeLine(state, row, pane)}\n`),
|
|
651
|
-
])
|
|
652
|
-
const more = window.more > 0 ? [fg(palette.faint)(` … ${window.more} more`)] : []
|
|
653
|
-
return new StyledText([...rows, ...more])
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
private stepRail(state: TuiState): StyledText {
|
|
657
|
-
const height = Math.max(1, this.listPane.height - 1)
|
|
658
|
-
const pane = this.paneRoom()
|
|
659
|
-
const window = stepWindow(state, height)
|
|
660
|
-
const rows = window.titles.map((_, offset) => {
|
|
661
|
-
const index = window.first + offset
|
|
662
|
-
const paint = index === state.stepIndex ? palette.ink : palette.muted
|
|
663
|
-
return fg(paint)(`${stepLine(state, index, pane)}\n`)
|
|
664
|
-
})
|
|
665
|
-
const more = window.more > 0 ? [fg(palette.faint)(` … ${window.more} more`)] : []
|
|
666
|
-
return new StyledText([...rows, ...more])
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
private paintDiff(state: TuiState): void {
|
|
670
|
-
const patch = selectedPatch(state)
|
|
671
|
-
if (patch === undefined) return
|
|
672
|
-
this.paintSticky(state, state.top)
|
|
673
|
-
this.view.show(patch, notesFor(state, patch.path))
|
|
674
|
-
this.view.fit(this.diffScroll.height)
|
|
675
|
-
const height = this.view.rows()
|
|
676
|
-
const top = this.view.scrollTo(state.top, state.cursor)
|
|
677
|
-
this.lastTop = top
|
|
678
|
-
this.view.paint(this.linePaint(state), top, height)
|
|
679
|
-
this.paintGutter(state, top, height)
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
private paintPending(state: TuiState): void {
|
|
683
|
-
this.pending.visible = state.screen === "pending"
|
|
684
|
-
if (state.screen !== "pending") {
|
|
685
|
-
this.pendingTitle.content = ""
|
|
686
|
-
this.pendingChoices.options = []
|
|
687
|
-
return
|
|
688
|
-
}
|
|
689
|
-
const count = state.pending.length
|
|
690
|
-
const room = modalWidth(this.renderer.width, PALETTE_WIDTH)
|
|
691
|
-
this.pendingTitle.content = `Review — ${count} comment${count === 1 ? "" : "s"}, one wake-up`
|
|
692
|
-
this.pendingChoices.options = state.pending.map((entry) => ({
|
|
693
|
-
name: clip(
|
|
694
|
-
`${entry.file}:${entry.start}-${entry.end} ${entry.body.split("\n")[0] ?? ""}`,
|
|
695
|
-
Math.max(1, room - MODAL_ROOM),
|
|
696
|
-
),
|
|
697
|
-
description: "",
|
|
698
|
-
value: entry.file,
|
|
699
|
-
}))
|
|
700
|
-
this.pendingChoices.selectedIndex = state.pendingIndex
|
|
701
|
-
this.pending.height = Math.min(PALETTE_MAX, state.pending.length + PENDING_CHROME)
|
|
702
|
-
this.pending.width = room
|
|
703
|
-
this.pending.left = Math.max(FRAME_PAD, Math.floor((this.renderer.width - room) / 2))
|
|
704
|
-
this.pending.top = Math.max(2, Math.floor(this.renderer.height / 4))
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
private assemble(renderer: CliRenderer): void {
|
|
708
|
-
this.diffScroll.add(this.view.node())
|
|
709
|
-
this.diffPane.add(this.view.pinNode())
|
|
710
|
-
this.diffPane.add(makeScroller(renderer, this.gutter, this.diffScroll))
|
|
711
|
-
this.listPane.insertBefore(this.landing, this.list)
|
|
712
|
-
this.listPane.insertBefore(this.logo, this.landing)
|
|
713
|
-
this.listPane.add(this.landingKeys)
|
|
714
|
-
this.watchChips()
|
|
715
|
-
this.body.add(this.listPane)
|
|
716
|
-
this.body.add(this.diffPane)
|
|
717
|
-
stack(this.compose, [this.composeTitle, this.composeBody, this.composeActions])
|
|
718
|
-
stack(renderer.root, [
|
|
719
|
-
this.header,
|
|
720
|
-
this.body,
|
|
721
|
-
this.footer,
|
|
722
|
-
this.scrim,
|
|
723
|
-
this.compose,
|
|
724
|
-
this.palette,
|
|
725
|
-
this.pending,
|
|
726
|
-
])
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
private watchChips(): void {
|
|
730
|
-
const strip = this.footer
|
|
731
|
-
strip.onMouseMove = (event: { x: number }) => this.hover(event.x - strip.x - this.lead)
|
|
732
|
-
strip.onMouseOut = () => this.hover(-1)
|
|
733
|
-
strip.onMouseDown = (event: { x: number }) => {
|
|
734
|
-
this.hover(event.x - strip.x - this.lead)
|
|
735
|
-
const chip = this.chips[this.hovered]
|
|
736
|
-
if (chip !== undefined) this.mouse?.onChip(chip.press)
|
|
737
|
-
}
|
|
738
|
-
const row = this.landingKeys
|
|
739
|
-
row.onMouseMove = (event: { x: number }) => this.hover(event.x - row.x)
|
|
740
|
-
row.onMouseOut = () => this.hover(-1)
|
|
741
|
-
row.onMouseDown = (event: { x: number }) => {
|
|
742
|
-
this.hover(event.x - row.x)
|
|
743
|
-
const chip = this.chips[this.hovered]
|
|
744
|
-
if (chip !== undefined) this.mouse?.onChip(chip.press)
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
private branchTable(state: TuiState): StyledText {
|
|
749
|
-
const room = nameRoom(homeWidth(this.renderer.width))
|
|
750
|
-
const heading = [fg(palette.faint)(`${branchHeading(room)}\n\n`)]
|
|
751
|
-
const rows = state.branches.flatMap((branch, index) => {
|
|
752
|
-
const here = index === state.branchIndex
|
|
753
|
-
const cells = branchCells(branch, here, room)
|
|
754
|
-
return [
|
|
755
|
-
fg(palette.accent)(cells.lead),
|
|
756
|
-
fg(here ? palette.ink : palette.muted)(cells.name),
|
|
757
|
-
fg(palette.faint)(cells.files),
|
|
758
|
-
fg(palette.added)(cells.added),
|
|
759
|
-
fg(palette.removed)(cells.gone),
|
|
760
|
-
fg(palette.attention)(` ${cells.state}\n`),
|
|
761
|
-
]
|
|
762
|
-
})
|
|
763
|
-
return new StyledText([...heading, ...rows])
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
private hover(x: number): void {
|
|
767
|
-
let at = 0
|
|
768
|
-
const found = this.chips.findIndex((chip) => {
|
|
769
|
-
const width = `${chip.key} ${chip.hint}`.length + CHIP_GAP
|
|
770
|
-
const here = x >= at && x < at + width
|
|
771
|
-
at += width
|
|
772
|
-
return here
|
|
773
|
-
})
|
|
774
|
-
if (found === this.hovered) return
|
|
775
|
-
this.hovered = found
|
|
776
|
-
this.landingKeys.content = this.chipRow()
|
|
777
|
-
if (this.shown !== undefined) this.footer.content = this.footerText(this.shown)
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
private chipRow(): StyledText {
|
|
781
|
-
return new StyledText(
|
|
782
|
-
this.chips.flatMap((chip, index) => {
|
|
783
|
-
const paint = index === this.hovered ? bg(palette.cursor) : fg(palette.faint)
|
|
784
|
-
return [
|
|
785
|
-
index === this.hovered ? paint(` ${chip.key} ${chip.hint} `) : fg(palette.ink)(chip.key),
|
|
786
|
-
index === this.hovered ? fg(palette.faint)(" ") : fg(palette.faint)(` ${chip.hint} `),
|
|
787
|
-
]
|
|
788
|
-
}),
|
|
789
|
-
)
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
private paintPane(state: TuiState): void {
|
|
793
|
-
const onBranches = atHome(state)
|
|
794
|
-
const inset = onBranches ? 0 : 1
|
|
795
|
-
this.listPane.width = onBranches ? homeWidth(this.renderer.width) : this.paneRoom()
|
|
796
|
-
this.listPane.visible = onBranches || state.navOpen
|
|
797
|
-
this.listPane.border = onBranches ? [] : ["right"]
|
|
798
|
-
this.listPane.paddingLeft = inset
|
|
799
|
-
this.listPane.paddingRight = inset
|
|
800
|
-
this.listPane.paddingTop = inset
|
|
801
|
-
this.listPane.marginRight = 0
|
|
802
|
-
this.diffPane.paddingLeft = inset
|
|
803
|
-
this.list.flexGrow = inset
|
|
804
|
-
this.paintChrome(onBranches)
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
private paintChrome(onBranches: boolean): void {
|
|
808
|
-
const place = onBranches ? "center" : "flex-start"
|
|
809
|
-
this.body.border = onBranches ? [] : true
|
|
810
|
-
this.body.borderStyle = "rounded"
|
|
811
|
-
this.body.borderColor = palette.rule
|
|
812
|
-
this.listPane.borderColor = palette.rule
|
|
813
|
-
this.listPane.backgroundColor = "transparent"
|
|
814
|
-
this.logo.visible = onBranches
|
|
815
|
-
this.landing.visible = onBranches
|
|
816
|
-
this.landingKeys.visible = onBranches
|
|
817
|
-
this.footer.visible = !onBranches
|
|
818
|
-
this.body.justifyContent = place
|
|
819
|
-
this.listPane.justifyContent = place
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
private paintReport(state: TuiState): void {
|
|
823
|
-
this.compose.visible = state.screen === "compose" || state.screen === "report"
|
|
824
|
-
if (state.screen !== "report") return
|
|
825
|
-
const lines = [
|
|
826
|
-
"What went wrong? Everything on screen is attached for you.",
|
|
827
|
-
"",
|
|
828
|
-
`${state.draft}▌`,
|
|
829
|
-
]
|
|
830
|
-
this.composeTitle.content = "Report a bug"
|
|
831
|
-
this.composeBody.content = lines.join("\n")
|
|
832
|
-
this.composeActions.content = reportActions()
|
|
833
|
-
const room = modalWidth(this.renderer.width, COMPOSE_WIDTH)
|
|
834
|
-
this.compose.height = lines.length + COMPOSE_ACTION_ROWS + COMPOSE_CHROME
|
|
835
|
-
this.compose.width = room
|
|
836
|
-
this.compose.left = Math.max(FRAME_PAD, Math.floor((this.renderer.width - room) / 2))
|
|
837
|
-
this.compose.top = Math.max(2, Math.floor(this.renderer.height / 4))
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
private paintGutter(state: TuiState, top: number, height: number): void {
|
|
841
|
-
const [from, to] = selectionRange(state)
|
|
842
|
-
const marked = markedRows(state)
|
|
843
|
-
const rows = Array.from({ length: height }, (_, index) => {
|
|
844
|
-
if (this.view.isComment(top + index)) return ` `
|
|
845
|
-
const row = this.view.rowAt(top + index)
|
|
846
|
-
const here = row === state.cursor || (state.selecting && row >= from && row <= to)
|
|
847
|
-
return `${here ? marks().cursor : " "}${marked.has(row) ? marks().comment : " "}`
|
|
848
|
-
})
|
|
849
|
-
this.gutter.content = rows.join("\n")
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
private paintSticky(state: TuiState, top: number): void {
|
|
853
|
-
const line = newLineAt(state, top)
|
|
854
|
-
const chain =
|
|
855
|
-
line === undefined || state.source.length === 0
|
|
856
|
-
? fallbackScope(state, top)
|
|
857
|
-
: stickyChain(state.source, line, STICKY_MAX)
|
|
858
|
-
this.view.pin(chain)
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
private linePaint(state: TuiState): (row: number) => LinePaint | undefined {
|
|
862
|
-
const [from, to] = selectionRange(state)
|
|
863
|
-
const selecting = state.selecting || state.screen === "compose"
|
|
864
|
-
const rows = selectedPatch(state)?.rows ?? []
|
|
865
|
-
return (row) => {
|
|
866
|
-
const kind = rows[row]?.kind
|
|
867
|
-
if (kind === undefined) return undefined
|
|
868
|
-
return pickPaint(this.view, kind, {
|
|
869
|
-
cursor: row === state.cursor,
|
|
870
|
-
selected: selecting && row >= from && row <= to,
|
|
871
|
-
})
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
private paintCompose(state: TuiState): void {
|
|
877
|
-
this.compose.visible = state.screen === "compose"
|
|
878
|
-
if (state.screen !== "compose") {
|
|
879
|
-
this.composeBody.content = ""
|
|
880
|
-
return
|
|
881
|
-
}
|
|
882
|
-
const snippet = snippetOf(state, SNIPPET_LINES)
|
|
883
|
-
const more = selectionRange(state)[1] - selectionRange(state)[0] + 1 - snippet.length
|
|
884
|
-
const tail = more > 0 ? [` … ${more} more lines`] : []
|
|
885
|
-
const written = `${state.draft}▌`.split("\n")
|
|
886
|
-
const lines = [...snippet, ...tail, "", ...written]
|
|
887
|
-
this.composeTitle.content = composeTarget(state)
|
|
888
|
-
this.composeBody.content = lines.join("\n")
|
|
889
|
-
this.composeActions.content = actionsText()
|
|
890
|
-
const height = lines.length + COMPOSE_ACTION_ROWS + COMPOSE_CHROME
|
|
891
|
-
const room = modalWidth(this.renderer.width, COMPOSE_WIDTH)
|
|
892
|
-
this.compose.height = height
|
|
893
|
-
this.compose.width = room
|
|
894
|
-
this.compose.left = Math.max(FRAME_PAD, Math.floor((this.renderer.width - room) / 2))
|
|
895
|
-
this.compose.top = Math.max(2, Math.floor((this.renderer.height - height) / 2))
|
|
896
|
-
}
|
|
897
|
-
}
|