reslop 0.1.9 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/README.md +3 -1
  3. package/bin/reslop.js +2 -2
  4. package/lib/ansi.js +148 -5
  5. package/lib/api.js +4 -2
  6. package/lib/capabilities.js +13 -14
  7. package/lib/cli.js +38 -49
  8. package/lib/clipboard.js +1 -1
  9. package/lib/{deps/changes.js → deps-diff.js} +309 -19
  10. package/lib/deps.js +498 -29
  11. package/lib/detect.js +1 -7
  12. package/lib/diff/align.js +7 -10
  13. package/lib/diff/diff.js +53 -0
  14. package/lib/diff/display.js +5 -4
  15. package/lib/diff/inline.js +26 -21
  16. package/lib/diff/items.js +6 -4
  17. package/lib/diff/patch.js +1 -3
  18. package/lib/diff/unit.js +392 -0
  19. package/lib/files.js +5 -8
  20. package/lib/{git/branches.js → git-branches.js} +191 -11
  21. package/lib/{git/dependencies.js → git-deps.js} +111 -38
  22. package/lib/git-reword-todo.js +20 -0
  23. package/lib/git.js +606 -68
  24. package/lib/github.js +28 -197
  25. package/lib/gitlab.js +24 -195
  26. package/lib/highlight/bash.js +1 -3
  27. package/lib/highlight/css.js +1 -3
  28. package/lib/highlight/js.js +11 -14
  29. package/lib/highlight.js +6 -9
  30. package/lib/keys.js +14 -8
  31. package/lib/manifest.js +330 -0
  32. package/lib/remote.js +374 -0
  33. package/lib/render/branches.js +18 -100
  34. package/lib/render/chrome.js +71 -14
  35. package/lib/render/commits.js +69 -60
  36. package/lib/render/diff.js +20 -20
  37. package/lib/render/files.js +6 -34
  38. package/lib/render/frame.js +36 -13
  39. package/lib/render/notes.js +26 -8
  40. package/lib/render/primitives.js +99 -11
  41. package/lib/{render.js → render/render.js} +8 -8
  42. package/lib/render/unit.js +41 -0
  43. package/lib/review-merge.js +270 -0
  44. package/lib/review.js +782 -14
  45. package/lib/select.js +5 -10
  46. package/lib/session/accessors.js +9 -1
  47. package/lib/session/actions.js +61 -18
  48. package/lib/session/branches.js +116 -128
  49. package/lib/session/change-actions.js +202 -123
  50. package/lib/session/commit.js +201 -115
  51. package/lib/session/compose.js +181 -15
  52. package/lib/session/dispatch.js +110 -60
  53. package/lib/session/files-pane.js +156 -148
  54. package/lib/session/items.js +22 -30
  55. package/lib/session/lifecycle.js +151 -54
  56. package/lib/session/load.js +19 -33
  57. package/lib/session/navigation.js +12 -1
  58. package/lib/session/ops.js +28 -41
  59. package/lib/session/pointer.js +57 -57
  60. package/lib/session/review.js +23 -37
  61. package/lib/session/terminal.js +6 -12
  62. package/lib/session/todos.js +37 -13
  63. package/lib/session/unit.js +208 -0
  64. package/lib/session/update.js +33 -46
  65. package/lib/session/view.js +78 -9
  66. package/lib/session/watch.js +128 -24
  67. package/lib/session.js +22 -246
  68. package/lib/source.js +3 -3
  69. package/lib/update.js +40 -75
  70. package/lib/{git/proc.js → utilities.js} +75 -11
  71. package/lib/wrap.js +1 -3
  72. package/package.json +2 -2
  73. package/lib/deps/items.js +0 -134
  74. package/lib/deps/manifest.js +0 -152
  75. package/lib/deps/merge.js +0 -120
  76. package/lib/deps/proposals.js +0 -164
  77. package/lib/deps/reports.js +0 -180
  78. package/lib/deps/rows.js +0 -176
  79. package/lib/deps/scan.js +0 -138
  80. package/lib/deps/usage.js +0 -68
  81. package/lib/deps/versions.js +0 -119
  82. package/lib/diff.js +0 -33
  83. package/lib/git/changes.js +0 -164
  84. package/lib/git/read.js +0 -253
  85. package/lib/git/run.js +0 -100
  86. package/lib/npm/commands.js +0 -100
  87. package/lib/remote/changes.js +0 -37
  88. package/lib/remote/headers.js +0 -36
  89. package/lib/remote/http.js +0 -122
  90. package/lib/remote/notes.js +0 -94
  91. package/lib/review/format.js +0 -434
  92. package/lib/review/storage.js +0 -150
  93. package/lib/review/store.js +0 -178
  94. package/lib/review/templates.js +0 -49
  95. package/lib/session/origins.js +0 -7
  96. package/lib/sys.js +0 -84
package/lib/remote.js ADDED
@@ -0,0 +1,374 @@
1
+ 'use strict';
2
+
3
+ const { delay, jsonParse, isHashObject } = require('metautil');
4
+ const { oneLine } = require('./utilities.js');
5
+ const { itemPath, isPathInScope } = require('./files.js');
6
+ const { parseDiff, itemsFromFiles, isCtxType } = require('./diff/diff.js');
7
+ const { foldDepItems } = require('./deps.js');
8
+
9
+ const RETRY_ATTEMPTS = 3;
10
+ const RETRY_DELAY_MS = 200;
11
+ const TRANSIENT_STATUS = [429, 502, 503, 504];
12
+
13
+ const isRecord = isHashObject;
14
+
15
+ const abortError = (signal) => {
16
+ if (signal && signal.reason !== undefined) return signal.reason;
17
+ const error = new Error('This operation was aborted');
18
+ error.name = 'AbortError';
19
+ return error;
20
+ };
21
+
22
+ const isAbortError = (error, signal) => {
23
+ if (signal && signal.aborted) return true;
24
+ if (!error || typeof error !== 'object') return false;
25
+ if (error.name === 'AbortError') return true;
26
+ if (error.code === 'ABORT') return true;
27
+ return false;
28
+ };
29
+
30
+ const throwIfAborted = (signal) => {
31
+ if (signal && signal.aborted) throw abortError(signal);
32
+ };
33
+
34
+ const wait = async (ms, abortSignal) => {
35
+ try {
36
+ await delay(ms, abortSignal);
37
+ } catch (error) {
38
+ throwIfAborted(abortSignal);
39
+ throw error;
40
+ }
41
+ };
42
+
43
+ const createTransport = (deps = {}) => {
44
+ const fetchImpl = deps.fetch;
45
+ const signal = deps.signal;
46
+
47
+ const retry = async (run, options = {}) => {
48
+ const attempts = options.attempts ?? RETRY_ATTEMPTS;
49
+ const delayMs = options.delayMs ?? RETRY_DELAY_MS;
50
+ const isRetryable = options.isRetryable;
51
+ for (let i = 0; ; i++) {
52
+ try {
53
+ return await run();
54
+ } catch (error) {
55
+ if (isAbortError(error, signal)) throw error;
56
+ const isLast = i === attempts - 1;
57
+ if (isLast || !isRetryable(error)) throw error;
58
+ throwIfAborted(signal);
59
+ await wait(delayMs * (i + 1), signal);
60
+ }
61
+ }
62
+ };
63
+
64
+ const request = async (url, options = {}) => {
65
+ throwIfAborted(signal);
66
+ if (typeof fetchImpl !== 'function') {
67
+ throw options.missingFetch();
68
+ }
69
+ const headers = options.headers;
70
+ const method = options.method || 'GET';
71
+ const body = options.body;
72
+ const wrapNetwork = options.wrapNetwork;
73
+ const toHttpError = options.toHttpError;
74
+ const retryOpts = options.retry ?? {};
75
+ return retry(
76
+ async () => {
77
+ let response;
78
+ try {
79
+ const init = { method, headers };
80
+ if (body !== undefined) init.body = body;
81
+ if (signal) init.signal = signal;
82
+ response = await fetchImpl(url, init);
83
+ } catch (error) {
84
+ if (isAbortError(error, signal)) throw error;
85
+ throw wrapNetwork(error);
86
+ }
87
+ const text = await response.text();
88
+ if (!response.ok) throw toHttpError(response.status, text);
89
+ return { body: text, headers: response.headers };
90
+ },
91
+ { ...retryOpts, isRetryable: options.isRetryable },
92
+ );
93
+ };
94
+
95
+ const listPages = async (url, options = {}) => {
96
+ const items = [];
97
+ let next = url;
98
+ const parsePage = options.parsePage;
99
+ const nextPage = options.nextPage;
100
+ while (next) {
101
+ const page = await request(next, options);
102
+ const entries = parsePage(page.body);
103
+ for (const entry of entries) items.push(entry);
104
+ next = nextPage(page.headers, next);
105
+ }
106
+ return items;
107
+ };
108
+
109
+ return { retry, request, listPages };
110
+ };
111
+
112
+ const headerValue = (headers, name) => {
113
+ if (!headers) return '';
114
+ if (typeof headers.get === 'function') {
115
+ return headers.get(name) || '';
116
+ }
117
+ const wanted = name.toLowerCase();
118
+ for (const key of Object.keys(headers)) {
119
+ const value = headers[key];
120
+ if (key.toLowerCase() === wanted) return `${value}`;
121
+ }
122
+ return '';
123
+ };
124
+
125
+ const parseLinkNext = (headers) => {
126
+ const link = headerValue(headers, 'link');
127
+ if (!link) return '';
128
+ for (const part of link.split(',')) {
129
+ const match = /<([^>]+)>\s*;\s*rel="?next"?/i.exec(part.trim());
130
+ if (match) return match[1];
131
+ }
132
+ return '';
133
+ };
134
+
135
+ const parseNextPage = (headers, currentUrl) => {
136
+ const fromLink = parseLinkNext(headers);
137
+ if (fromLink) return fromLink;
138
+ const page = headerValue(headers, 'x-next-page');
139
+ if (!page) return '';
140
+ const url = new URL(currentUrl);
141
+ url.searchParams.set('page', page);
142
+ return url.toString();
143
+ };
144
+
145
+ const listUrl = (base) => {
146
+ const url = new URL(base);
147
+ url.searchParams.set('per_page', '100');
148
+ return url.toString();
149
+ };
150
+
151
+ const createClient = ({ name, subject, headers, nextPage }) => {
152
+ const prefix = name.toUpperCase();
153
+ const error = (code, message, extra = {}) =>
154
+ Object.assign(new Error(message), { code: `${prefix}_${code}`, ...extra });
155
+
156
+ const parseJson = (text, label, validate = isHashObject) => {
157
+ const data = jsonParse(text ?? '');
158
+ if (!validate(data)) throw error('PARSE', `${name} API: invalid ${label}`);
159
+ return data;
160
+ };
161
+
162
+ const httpError = (status, body, token) => {
163
+ const text = `${body ?? ''}`.trim();
164
+ const parsed = jsonParse(text);
165
+ const fields = name === 'GitLab' ? ['message', 'error'] : ['message'];
166
+ const field = fields.find((key) => typeof parsed?.[key] === 'string');
167
+ const message =
168
+ isHashObject(parsed) && field ? parsed[field] : oneLine(text);
169
+ if (status === 404) {
170
+ const hint = token
171
+ ? ''
172
+ : ` (set ${prefix}_TOKEN for private repositories)`;
173
+ return error('NOT_FOUND', `${name} ${subject} not found${hint}`, {
174
+ status,
175
+ });
176
+ }
177
+ if (status === 401) {
178
+ return error('AUTH', `${name} authentication failed`, { status });
179
+ }
180
+ const rateLimit = status === 403 && /rate limit/i.test(message);
181
+ if (rateLimit || (name === 'GitLab' && status === 429)) {
182
+ return error('RATE_LIMIT', `${name} API rate limit exceeded`, { status });
183
+ }
184
+ const detail = message ? `: ${oneLine(message)}` : ` HTTP ${status}`;
185
+ return error('HTTP', `${name} API${detail}`, { status });
186
+ };
187
+
188
+ const policy = (options) => ({
189
+ retry: options.retry ?? {},
190
+ isRetryable: (err) =>
191
+ err.code === `${prefix}_NETWORK` || TRANSIENT_STATUS.includes(err.status),
192
+ missingFetch: () => error('FETCH', 'fetch is not available'),
193
+ toHttpError: (status, body) => httpError(status, body, options.token),
194
+ wrapNetwork: (cause) => {
195
+ const detail = oneLine(cause && cause.message);
196
+ const suffix = detail ? `: ${detail}` : '';
197
+ return error('NETWORK', `${name} request failed${suffix}`, { cause });
198
+ },
199
+ method: options.method || 'GET',
200
+ headers: headers(options.token || '', options.accept),
201
+ });
202
+
203
+ const request = (url, options) => {
204
+ const init = policy(options);
205
+ if (options.contentType) init.headers['Content-Type'] = options.contentType;
206
+ return createTransport(options).request(url, {
207
+ ...init,
208
+ body: options.body,
209
+ });
210
+ };
211
+
212
+ const list = (url, options) =>
213
+ createTransport(options).listPages(url, {
214
+ ...policy(options),
215
+ method: 'GET',
216
+ parsePage: (text) => parseJson(text, 'list payload', Array.isArray),
217
+ nextPage,
218
+ });
219
+
220
+ return { parseJson, request, list, subject };
221
+ };
222
+
223
+ const sideLineNumber = (type, oldNo, newNo, side) => {
224
+ if (side === 'LEFT') {
225
+ if (type === 'add') return 0;
226
+ return oldNo;
227
+ }
228
+ if (type === 'del') return 0;
229
+ return newNo;
230
+ };
231
+
232
+ const locateLineInItem = (item, rel, line, side) => {
233
+ const path = itemPath(item);
234
+ if (path !== rel) return null;
235
+ const hunk = item.hunk;
236
+ if (!hunk || !line) return null;
237
+ let oldNo = hunk.oldStart;
238
+ let newNo = hunk.newStart;
239
+ for (const entry of hunk.lines) {
240
+ const at = sideLineNumber(entry.type, oldNo, newNo, side);
241
+ if (at === line) {
242
+ const inBlock = entry.blockId === item.blockId;
243
+ return { inBlock };
244
+ }
245
+ if (isCtxType(entry.type) || entry.type === 'del') {
246
+ oldNo += 1;
247
+ }
248
+ if (isCtxType(entry.type) || entry.type === 'add') {
249
+ newNo += 1;
250
+ }
251
+ }
252
+ return null;
253
+ };
254
+
255
+ const findItemForLine = (items, rel, line, side) => {
256
+ let fallback = null;
257
+ for (const item of items) {
258
+ const hit = locateLineInItem(item, rel, line, side);
259
+ if (!hit) continue;
260
+ if (hit.inBlock) return item;
261
+ if (!fallback) fallback = item;
262
+ }
263
+ return fallback;
264
+ };
265
+
266
+ const importedText = (entry, host) => {
267
+ const reviewer = entry.reviewer || 'unknown';
268
+ const body = `${entry.body ?? ''}`.trim();
269
+ return `@${reviewer} review at ${host}: ${body}`;
270
+ };
271
+
272
+ const importedTodo = (file, entry, host) => ({
273
+ kind: 'todo',
274
+ file,
275
+ text: importedText(entry, host),
276
+ done: entry.resolved === true,
277
+ });
278
+
279
+ const importedFeedback = (item, path, entry, host) => {
280
+ const hunk = item.hunk;
281
+ return {
282
+ kind: 'feedback',
283
+ file: itemPath(item) || path,
284
+ oldStart: hunk ? hunk.oldStart : 0,
285
+ newStart: hunk ? hunk.newStart : 0,
286
+ blockId: item.blockId ?? 0,
287
+ origin: item.origin ?? 'pr',
288
+ header: hunk ? hunk.header : '',
289
+ text: importedText(entry, host),
290
+ done: entry.resolved === true,
291
+ };
292
+ };
293
+
294
+ const noteFromLocation = (items, loc, entry, host, fallbackFile) => {
295
+ const path = loc.path || '';
296
+ const line = loc.line;
297
+ const side = loc.side;
298
+ if (line && path) {
299
+ const item = findItemForLine(items, path, line, side);
300
+ if (item) return importedFeedback(item, path, entry, host);
301
+ }
302
+ if (path) return importedTodo(path, entry, host);
303
+ return importedTodo(fallbackFile, entry, host);
304
+ };
305
+
306
+ const changePath = (file) => file.newPath || file.oldPath || '';
307
+
308
+ const filterChangeFiles = (files, paths) => {
309
+ if (!paths.length) return files;
310
+ return files.filter((file) => isPathInScope(changePath(file), paths));
311
+ };
312
+
313
+ const changeFiles = (items) => {
314
+ const files = new Set();
315
+ for (const item of items) {
316
+ const paths = item.dep ? item.dep.files : [itemPath(item)];
317
+ for (const rel of paths ?? []) {
318
+ if (rel) files.add(rel);
319
+ }
320
+ }
321
+ return [...files];
322
+ };
323
+
324
+ const loadChange = async (ref, options, source) => {
325
+ const { client, url, diffUrl = url, diffAccept } = source;
326
+ const paths = options.paths ?? [];
327
+ const request = {
328
+ fetch: options.fetch ?? globalThis.fetch,
329
+ token: options.token ?? '',
330
+ retry: options.retry ?? {},
331
+ signal: options.signal,
332
+ };
333
+ const jsonPage = await client.request(url, request);
334
+ const data = client.parseJson(jsonPage.body, `${client.subject} payload`);
335
+ const diffPage = await client.request(diffUrl, {
336
+ ...request,
337
+ accept: diffAccept,
338
+ });
339
+ const files = filterChangeFiles(parseDiff(diffPage.body), paths);
340
+ const items = foldDepItems(itemsFromFiles(files, 'pr'));
341
+ const change = source.toChange(ref, data, items);
342
+ const sourceLabel = `${source.prefix}${change.number}`;
343
+ let imported = { feedback: [], todos: [] };
344
+ try {
345
+ const discussion = await source.loadDiscussion(ref, request);
346
+ imported = source.discussionToNotes(discussion, items, paths);
347
+ } catch (error) {
348
+ if (isAbortError(error, request.signal)) throw error;
349
+ // Discussion import is optional.
350
+ }
351
+ return { top: options.cwd, items, sourceLabel, change, imported };
352
+ };
353
+
354
+ module.exports = {
355
+ RETRY_ATTEMPTS,
356
+ RETRY_DELAY_MS,
357
+ TRANSIENT_STATUS,
358
+ isRecord,
359
+ isAbortError,
360
+ createTransport,
361
+ headerValue,
362
+ parseLinkNext,
363
+ parseNextPage,
364
+ createClient,
365
+ listUrl,
366
+ findItemForLine,
367
+ importedText,
368
+ importedTodo,
369
+ noteFromLocation,
370
+ changePath,
371
+ filterChangeFiles,
372
+ changeFiles,
373
+ loadChange,
374
+ };
@@ -2,12 +2,12 @@
2
2
 
3
3
  const ansi = require('../ansi.js');
4
4
  const primitives = require('./primitives.js');
5
+ const { measureColumns, padColumns, joinColumns, paintColumns } = primitives;
5
6
 
6
7
  const { THEME, paint, visibleWidth, truncateVisible, seq, EL } = ansi;
7
- const { fill, padVisible, FILE_MARK, paneResult } = primitives;
8
- const { paintCursorList, branchLabel, paintBracketName } = primitives;
9
-
10
- const BRANCH_COL_KEYS = ['sha', 'ahead', 'behind', 'gone', 'date'];
8
+ const { fill, FILE_MARK, paneResult } = primitives;
9
+ const { paintCursorList, paintListEdit } = primitives;
10
+ const { branchLabel, paintBracketName } = primitives;
11
11
 
12
12
  const BRANCH_COL_ALIGN = {
13
13
  sha: 'end',
@@ -33,11 +33,6 @@ const BRANCH_CURRENT_COL_FG = {
33
33
  const BRANCH_NAME_MAX = 24;
34
34
  const BRANCH_EDGE = 2;
35
35
  const BRANCH_TAIL = 1;
36
- const BRANCH_GAP = ' ';
37
- const BRANCH_DATE_GAP = ' ';
38
-
39
- const colGap = (key) => (key === 'date' ? BRANCH_DATE_GAP : BRANCH_GAP);
40
-
41
36
  const branchNameChip = (entry, rowBg) => {
42
37
  if (entry.current) {
43
38
  return {
@@ -77,68 +72,12 @@ const branchRowFields = (entry) => {
77
72
  return { sha, ahead, behind, gone, date };
78
73
  };
79
74
 
80
- const branchColumns = (branches) => {
81
- const widths = { name: 0 };
82
- for (const key of BRANCH_COL_KEYS) widths[key] = 0;
83
- for (const entry of branches) {
84
- const nameW = visibleWidth(branchLabel(entry.name));
85
- if (nameW > widths.name) widths.name = nameW;
86
- const fields = branchRowFields(entry);
87
- for (const key of BRANCH_COL_KEYS) {
88
- const w = visibleWidth(fields[key]);
89
- if (w > widths[key]) widths[key] = w;
90
- }
91
- }
92
- widths.name = Math.min(BRANCH_NAME_MAX, widths.name);
93
- return widths;
94
- };
95
-
96
- const branchRowParts = (entry, cols) => {
97
- const fields = branchRowFields(entry);
98
- const parts = {};
99
- for (const key of BRANCH_COL_KEYS) {
100
- const width = cols?.[key] ?? visibleWidth(fields[key]);
101
- const align = BRANCH_COL_ALIGN[key];
102
- parts[key] = padVisible(fields[key], width, align);
103
- }
104
- return parts;
105
- };
106
-
107
- const joinBranchSuffix = (parts, cols) => {
108
- const bits = [];
109
- for (const key of BRANCH_COL_KEYS) {
110
- if (!cols[key]) continue;
111
- bits.push(colGap(key) + parts[key]);
112
- }
113
- if (!bits.length) return '';
114
- return bits.join('');
115
- };
116
-
117
- const branchColFg = (key, current) => {
118
- if (current && Object.hasOwn(BRANCH_CURRENT_COL_FG, key)) {
119
- return BRANCH_CURRENT_COL_FG[key];
120
- }
121
- return BRANCH_COL_FG[key];
122
- };
123
-
124
- const paintBranchSuffix = (parts, cols, fgRgb, bgRgb, color, current) => {
125
- const bits = [];
126
- for (const key of BRANCH_COL_KEYS) {
127
- if (!cols[key]) continue;
128
- const tone = branchColFg(key, current) ?? fgRgb;
129
- const gap = paint(colGap(key), fgRgb, bgRgb, color);
130
- bits.push(gap + paint(parts[key], tone, bgRgb, color));
131
- }
132
- if (!bits.length) return '';
133
- return bits.join('');
134
- };
135
-
136
75
  const paintBranchRow = (entry, width, color, selected, cols) => {
137
76
  const inner = Math.max(1, width - BRANCH_EDGE - BRANCH_TAIL);
138
77
  const mark = selected ? FILE_MARK : ' ';
139
78
  const prefix = ` ${mark} `;
140
- const parts = branchRowParts(entry, cols);
141
- const suffix = joinBranchSuffix(parts, cols);
79
+ const parts = padColumns(branchRowFields(entry), cols, BRANCH_COL_ALIGN);
80
+ const suffix = joinColumns(parts, cols);
142
81
  const rest = Math.max(1, inner - visibleWidth(prefix + suffix));
143
82
  const nameW = Math.min(cols.name, rest);
144
83
  const label = truncateVisible(branchLabel(entry.name), nameW);
@@ -170,46 +109,25 @@ const paintBranchRow = (entry, width, color, selected, cols) => {
170
109
  chip.nameBold,
171
110
  );
172
111
  out += paint(after, markFg, markBg, color);
173
- out += paintBranchSuffix(parts, cols, markFg, markBg, color, entry.current);
112
+ const tones = entry.current
113
+ ? { ...BRANCH_COL_FG, ...BRANCH_CURRENT_COL_FG }
114
+ : BRANCH_COL_FG;
115
+ out += paintColumns(parts, cols, markFg, markBg, color, tones);
174
116
  out += paint(tail, markFg, markBg, color);
175
117
  return out + edge;
176
118
  };
177
119
 
178
- const paintBranchEdit = (compose, width, color) => {
179
- const inner = Math.max(1, width - BRANCH_EDGE);
180
- const prefix = ` ${FILE_MARK} `;
181
- const prefixW = visibleWidth(prefix);
182
- const rest = Math.max(1, inner - prefixW);
183
- const text = compose.text ?? '';
184
- const label = `[${text}]`;
185
- const clipped = truncateVisible(label, rest);
186
- const pad = Math.max(0, rest - visibleWidth(clipped));
187
- const left = `${prefix}${clipped}${' '.repeat(pad)}`;
188
- const fgRgb = THEME.chromeFg;
189
- const bgRgb = THEME.buttonBg;
190
- const edge = fill(BRANCH_EDGE, fgRgb, THEME.ctxBg, color);
191
- let row = `${left}${edge}`;
192
- if (color) {
193
- const gap = ' '.repeat(pad);
194
- row = `${seq(fgRgb, bgRgb)}${EL}`;
195
- row += paint(prefix, fgRgb, bgRgb, color);
196
- row += paintBracketName(
197
- clipped,
198
- THEME.buttonHotFg,
199
- THEME.mutedFg,
200
- bgRgb,
201
- color,
202
- );
203
- row += paint(gap, fgRgb, bgRgb, color);
204
- row += edge;
205
- }
206
- const col = Math.min((compose.cursor ?? 0) + 1, visibleWidth(clipped));
207
- return { row, cursor: { x: prefixW + col + 1 } };
208
- };
120
+ const paintBranchEdit = (compose, width, color) =>
121
+ paintListEdit(compose, width, color, BRANCH_EDGE);
209
122
 
210
123
  const paintBodyBranches = (view, width, color, bodyH, headerLines) => {
211
124
  const branches = view.branches ?? [];
212
- const cols = branchColumns(branches);
125
+ const cols = measureColumns(branches, branchRowFields, BRANCH_COL_ALIGN);
126
+ cols.name = 0;
127
+ for (const entry of branches) {
128
+ cols.name = Math.max(cols.name, visibleWidth(branchLabel(entry.name)));
129
+ }
130
+ cols.name = Math.min(BRANCH_NAME_MAX, cols.name);
213
131
  const cursor = view.branchCursor ?? 0;
214
132
  const compose = view.compose;
215
133
  const editing = compose && compose.kind === 'branch';