reslop 0.2.5 → 0.2.7

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 (114) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/LICENSE +1 -1
  3. package/README.md +11 -11
  4. package/bin/reslop.js +3 -8
  5. package/lib/ansi.js +72 -19
  6. package/lib/api.js +1 -1
  7. package/lib/capabilities.js +8 -8
  8. package/lib/cli.js +61 -75
  9. package/lib/clipboard.js +39 -47
  10. package/lib/dashboard/git.js +128 -0
  11. package/lib/dashboard/model.js +357 -0
  12. package/lib/dashboard/npm.js +290 -0
  13. package/lib/dashboard/tree.js +278 -0
  14. package/lib/deps-diff.js +197 -402
  15. package/lib/deps.js +113 -240
  16. package/lib/detect.js +8 -18
  17. package/lib/diff/align.js +41 -113
  18. package/lib/diff/diff.js +12 -43
  19. package/lib/diff/display.js +25 -36
  20. package/lib/diff/edit.js +6 -20
  21. package/lib/diff/inline.js +76 -144
  22. package/lib/diff/items.js +33 -47
  23. package/lib/diff/parse.js +28 -56
  24. package/lib/diff/patch.js +12 -33
  25. package/lib/diff/unit.js +79 -178
  26. package/lib/editor.js +52 -69
  27. package/lib/files.js +79 -91
  28. package/lib/find.js +61 -0
  29. package/lib/git-branches.js +254 -416
  30. package/lib/git-deps.js +148 -272
  31. package/lib/git-reword-todo.js +5 -13
  32. package/lib/git-worktree.js +161 -214
  33. package/lib/git.js +21 -49
  34. package/lib/github.js +67 -181
  35. package/lib/gitlab.js +40 -90
  36. package/lib/highlight/bash.js +55 -177
  37. package/lib/highlight/core.js +155 -141
  38. package/lib/highlight/css.js +25 -58
  39. package/lib/highlight/csv.js +19 -37
  40. package/lib/highlight/dart.js +72 -213
  41. package/lib/highlight/dot.js +14 -14
  42. package/lib/highlight/html.js +42 -63
  43. package/lib/highlight/js.js +177 -506
  44. package/lib/highlight/json.js +17 -37
  45. package/lib/highlight/log.js +19 -25
  46. package/lib/highlight/txt.js +7 -10
  47. package/lib/highlight.js +17 -46
  48. package/lib/keys.js +75 -83
  49. package/lib/manifest.js +67 -126
  50. package/lib/npm-commands.js +120 -169
  51. package/lib/remote.js +140 -190
  52. package/lib/render/branches.js +63 -61
  53. package/lib/render/chrome.js +412 -347
  54. package/lib/render/commits.js +160 -361
  55. package/lib/render/dash-activity.js +212 -0
  56. package/lib/render/dash-blocks.js +496 -0
  57. package/lib/render/dash-table.js +295 -0
  58. package/lib/render/dashboard.js +62 -0
  59. package/lib/render/diff.js +123 -258
  60. package/lib/render/files.js +60 -86
  61. package/lib/render/frame.js +82 -117
  62. package/lib/render/notes.js +150 -210
  63. package/lib/render/npm.js +213 -177
  64. package/lib/render/packages.js +93 -0
  65. package/lib/render/present.js +4 -11
  66. package/lib/render/primitives.js +77 -172
  67. package/lib/render/render.js +5 -14
  68. package/lib/render/report.js +43 -0
  69. package/lib/render/repos.js +226 -0
  70. package/lib/render/search.js +25 -0
  71. package/lib/render/tiles.js +355 -0
  72. package/lib/render/unit.js +15 -31
  73. package/lib/report-model.js +110 -33
  74. package/lib/report-parse.js +56 -37
  75. package/lib/report-render.js +102 -59
  76. package/lib/report-run.js +87 -77
  77. package/lib/report-test.js +221 -99
  78. package/lib/report-tools.js +96 -154
  79. package/lib/review-merge.js +33 -41
  80. package/lib/review.js +69 -129
  81. package/lib/runs.js +225 -0
  82. package/lib/select.js +53 -91
  83. package/lib/session/accessors.js +14 -21
  84. package/lib/session/actions.js +189 -65
  85. package/lib/session/branches.js +164 -222
  86. package/lib/session/change-actions.js +49 -119
  87. package/lib/session/commit.js +298 -352
  88. package/lib/session/compose.js +572 -715
  89. package/lib/session/dashboard.js +530 -0
  90. package/lib/session/dispatch.js +197 -171
  91. package/lib/session/files-pane.js +92 -45
  92. package/lib/session/find.js +94 -0
  93. package/lib/session/items.js +6 -17
  94. package/lib/session/lifecycle.js +420 -466
  95. package/lib/session/load.js +1 -14
  96. package/lib/session/navigation.js +4 -2
  97. package/lib/session/npm.js +403 -420
  98. package/lib/session/ops.js +5 -13
  99. package/lib/session/packages.js +143 -0
  100. package/lib/session/pointer.js +30 -14
  101. package/lib/session/progress.js +39 -30
  102. package/lib/session/review.js +1 -3
  103. package/lib/session/tasks.js +277 -236
  104. package/lib/session/templates.js +51 -59
  105. package/lib/session/terminal.js +85 -132
  106. package/lib/session/view.js +59 -80
  107. package/lib/session/watch.js +201 -212
  108. package/lib/session/workspace.js +455 -0
  109. package/lib/session.js +95 -161
  110. package/lib/update.js +44 -111
  111. package/lib/utilities.js +46 -88
  112. package/lib/workspace.js +166 -0
  113. package/lib/wrap.js +29 -55
  114. package/package.json +1 -1
@@ -0,0 +1,295 @@
1
+ 'use strict';
2
+
3
+ const metautil = require('metautil');
4
+ const { bytesToSize } = metautil;
5
+ const files = require('../files.js');
6
+ const { relativeAge } = files;
7
+ const ansi = require('../ansi.js');
8
+ const { visibleWidth, graphemes, graphemeWidth } = ansi;
9
+ const tiles = require('./tiles.js');
10
+ const { seg, segmentsWidth, clipSegments, titleSegments } = tiles;
11
+ const tree = require('../dashboard/tree.js');
12
+ const { HEAT_MS } = tree;
13
+
14
+ const MIN_FLEX = 6;
15
+ const SECONDS_AGO = /^\d+s ago$/;
16
+
17
+ const trimmed = (value) =>
18
+ value >= 10 ? `${Math.round(value)}` : `${Math.round(value * 10) / 10}`;
19
+
20
+ const num = (value) => {
21
+ const n = Math.max(0, Math.round(value));
22
+ if (n >= 1e6) return `${trimmed(n / 1e6)}m`;
23
+ if (n >= 1e4) return `${trimmed(n / 1e3)}k`;
24
+ return `${n}`;
25
+ };
26
+
27
+ const size = (bytes) => bytesToSize(bytes > 0 ? bytes : 0);
28
+
29
+ const ago = (at, now) => {
30
+ if (!at) return '';
31
+ const text = relativeAge(at, now);
32
+ return SECONDS_AGO.test(text) ? '<1m ago' : text;
33
+ };
34
+
35
+ const duration = (ms) => {
36
+ const value = Math.max(0, ms);
37
+ if (value < 1000) return `${Math.round(value)}ms`;
38
+ if (value < 60000) return `${(value / 1000).toFixed(1)}s`;
39
+ const minutes = Math.floor(value / 60000);
40
+ const seconds = Math.floor((value % 60000) / 1000);
41
+ return `${minutes}m${`${seconds}`.padStart(2, '0')}s`;
42
+ };
43
+
44
+ const isHot = (at, now) => at > 0 && now - at < HEAT_MS;
45
+
46
+ const delta = (value, now, at) => {
47
+ if (!at || now - at >= HEAT_MS || !value) return null;
48
+ if (value > 0) return seg(`▲+${num(value)}`, 'add', true);
49
+ return seg(`▼${num(-value)}`, 'del', true);
50
+ };
51
+
52
+ const waiting = (text) => ({ badge: [], lines: [[seg(text, 'muted')]] });
53
+
54
+ const cell = (text, tone = 'text', align = 'l', bold = false) => ({
55
+ segs: [seg(text, tone, bold)],
56
+ align,
57
+ flex: false,
58
+ });
59
+
60
+ const cellSegs = (segs, align = 'l') => ({ segs, align, flex: false });
61
+
62
+ const flexCell = (text, tone = 'muted') => ({
63
+ segs: [seg(text, tone)],
64
+ align: 'l',
65
+ flex: true,
66
+ });
67
+
68
+ const blankCell = { segs: [], align: 'l', flex: false };
69
+
70
+ const measuredWidth = (item) => {
71
+ if (typeof item.measure === 'number') return item.measure;
72
+ return segmentsWidth(item.segs);
73
+ };
74
+
75
+ const columnWidths = (rows, count) => {
76
+ const widths = new Array(count).fill(0);
77
+ for (const row of rows) {
78
+ for (let c = 0; c < count; c++) {
79
+ const item = row[c];
80
+ if (!item || (item.flex && !item.keep)) continue;
81
+ widths[c] = Math.max(widths[c], measuredWidth(item));
82
+ }
83
+ }
84
+ return widths;
85
+ };
86
+
87
+ const flexColumn = (rows, count) => {
88
+ for (let c = 0; c < count; c++) {
89
+ if (rows.some((row) => row[c] && row[c].flex)) return c;
90
+ }
91
+ return -1;
92
+ };
93
+
94
+ const usedWidth = (widths, use, gaps) => {
95
+ let total = 0;
96
+ for (let c = 0; c < use; c++) total += widths[c] + gaps[c];
97
+ return total;
98
+ };
99
+
100
+ const columnGaps = (rows, count, fallback) => {
101
+ const gaps = new Array(count).fill(fallback);
102
+ const fixed = new Array(count).fill(false);
103
+ gaps[0] = 0;
104
+ fixed[0] = true;
105
+ for (let c = 1; c < count; c++) {
106
+ const owner = rows.find((row) => row[c] && typeof row[c].gap === 'number');
107
+ if (!owner) continue;
108
+ gaps[c] = owner[c].gap;
109
+ fixed[c] = true;
110
+ }
111
+ return { gaps, fixed };
112
+ };
113
+
114
+ const closeEmpty = (widths, gaps, fixed) => {
115
+ for (let c = 1; c < widths.length; c++) {
116
+ if (widths[c - 1] !== 0) continue;
117
+ gaps[c] = 0;
118
+ fixed[c] = true;
119
+ }
120
+ };
121
+
122
+ const widenGaps = (gaps, fixed, use, room) => {
123
+ if (room <= 0) return;
124
+ const open = [];
125
+ for (let c = 1; c < use; c++) {
126
+ if (!fixed[c]) open.push(c);
127
+ }
128
+ if (!open.length) return;
129
+ const share = Math.floor(room / open.length);
130
+ let extra = room - share * open.length;
131
+ for (const index of open) {
132
+ gaps[index] += share;
133
+ if (extra <= 0) continue;
134
+ gaps[index] += 1;
135
+ extra -= 1;
136
+ }
137
+ };
138
+
139
+ const flexFloor = (rows, index) => {
140
+ let floor = null;
141
+ for (const row of rows) {
142
+ const item = row[index];
143
+ if (!item || !item.flex || typeof item.min !== 'number') continue;
144
+ floor = floor === null ? item.min : Math.min(floor, item.min);
145
+ }
146
+ return floor;
147
+ };
148
+
149
+ const pickColumns = (rows, width, gap, spread) => {
150
+ const count = Math.max(0, ...rows.map((row) => row.length));
151
+ const widths = columnWidths(rows, count);
152
+ const flex = flexColumn(rows, count);
153
+ const keep = flex >= 0 && rows.some((row) => row[flex] && row[flex].keep);
154
+ const floor = flex >= 0 && !keep ? flexFloor(rows, flex) : null;
155
+ const minFlex = floor ?? MIN_FLEX;
156
+ const reserve = floor ?? 0;
157
+ const { gaps, fixed } = columnGaps(rows, count, gap);
158
+ closeEmpty(widths, gaps, fixed);
159
+ let use = count;
160
+ while (use > 1) {
161
+ const shrinks = flex >= 0 && flex < use && !keep;
162
+ const used = usedWidth(widths, use, gaps);
163
+ const need = shrinks ? minFlex : 0;
164
+ if (used + need <= width) break;
165
+ const trailing = shrinks && flex < use - 1;
166
+ if (trailing && used + reserve <= width) break;
167
+ if (keep && flex === use - 1) break;
168
+ use -= 1;
169
+ }
170
+ const room = width - usedWidth(widths, use, gaps);
171
+ if (flex >= 0 && flex < use) widths[flex] = Math.max(0, widths[flex] + room);
172
+ else if (spread) widenGaps(gaps, fixed, use, room);
173
+ return { use, widths, flex, gaps };
174
+ };
175
+
176
+ const flexSegments = (item, room) => {
177
+ const clipped = clipSegments(item.segs, room);
178
+ const pad = Math.max(0, room - segmentsWidth(clipped));
179
+ return [...clipped, seg(' '.repeat(pad))];
180
+ };
181
+
182
+ const renderRow = (row, columns) => {
183
+ const { use, widths, flex, gaps } = columns;
184
+ const line = [];
185
+ for (let c = 0; c < use; c++) {
186
+ const item = row[c] ?? blankCell;
187
+ if (c) line.push(seg(' '.repeat(gaps[c])));
188
+ if (c === flex) {
189
+ line.push(...flexSegments(item, widths[c]));
190
+ continue;
191
+ }
192
+ const pad = ' '.repeat(Math.max(0, widths[c] - segmentsWidth(item.segs)));
193
+ if (item.align === 'r') line.push(seg(pad), ...item.segs);
194
+ else line.push(...item.segs, seg(pad));
195
+ }
196
+ return line;
197
+ };
198
+
199
+ const tableLines = (rows, width, gap = 2, spread = false) => {
200
+ if (!rows.length) return [];
201
+ const columns = pickColumns(rows, width, gap, spread);
202
+ return rows.map((row) => renderRow(row, columns));
203
+ };
204
+
205
+ const tailVisible = (text, skip) => {
206
+ let left = skip;
207
+ let col = 0;
208
+ let out = '';
209
+ for (const ch of graphemes(text)) {
210
+ const w = graphemeWidth(ch, col);
211
+ col += w;
212
+ if (left > 0) left -= w;
213
+ else out += ch;
214
+ }
215
+ return out;
216
+ };
217
+
218
+ const skipSegments = (segs, skip) => {
219
+ const out = [];
220
+ let left = skip;
221
+ for (const part of segs) {
222
+ if (left <= 0) {
223
+ out.push(part);
224
+ continue;
225
+ }
226
+ const w = visibleWidth(part.text);
227
+ if (w <= left) {
228
+ left -= w;
229
+ continue;
230
+ }
231
+ const text = tailVisible(part.text, left);
232
+ left = 0;
233
+ if (text) out.push(seg(text, part.tone, part.bold));
234
+ }
235
+ return out;
236
+ };
237
+
238
+ const captionOver = (tile, line, badge = []) => {
239
+ const caption = titleSegments(tile, badge);
240
+ return [...caption, ...skipSegments(line, segmentsWidth(caption))];
241
+ };
242
+
243
+ const titleAside = (tile, aside, width, badge = []) => {
244
+ const left = titleSegments(tile, badge);
245
+ const gap = width - segmentsWidth(left) - segmentsWidth(aside);
246
+ return [...left, seg(' '.repeat(Math.max(1, gap))), ...aside];
247
+ };
248
+
249
+ const stat = (label, value, tone = 'text', bold = false) => ({
250
+ label,
251
+ value: typeof value === 'string' ? [seg(value, tone, bold)] : value,
252
+ });
253
+
254
+ const pairRows = (items, perRow = 2) => {
255
+ const rows = [];
256
+ for (let i = 0; i < items.length; i += perRow) {
257
+ const row = [];
258
+ for (const item of items.slice(i, i + perRow)) {
259
+ row.push(cell(item.label, 'muted'), cellSegs(item.value));
260
+ }
261
+ rows.push(row);
262
+ }
263
+ return rows;
264
+ };
265
+
266
+ const pickGroups = (folders, exts, rows) => {
267
+ const count = Math.max(0, rows);
268
+ const dirs = folders.slice(0, count);
269
+ return { dirs, exts: exts.slice(0, count - dirs.length) };
270
+ };
271
+
272
+ const labelOf = (key, isDir) => {
273
+ if (isDir) return key === '.' ? '/' : key;
274
+ return key.startsWith('.') ? `*${key}` : key;
275
+ };
276
+
277
+ module.exports = {
278
+ num,
279
+ size,
280
+ ago,
281
+ duration,
282
+ isHot,
283
+ delta,
284
+ waiting,
285
+ cell,
286
+ cellSegs,
287
+ flexCell,
288
+ tableLines,
289
+ stat,
290
+ pairRows,
291
+ pickGroups,
292
+ labelOf,
293
+ titleAside,
294
+ captionOver,
295
+ };
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ const primitives = require('./primitives.js');
4
+ const { paintBodyFill, paneResult } = primitives;
5
+ const tiles = require('./tiles.js');
6
+ const { layoutTiles, paintTile, composeBands, tileHits, pageFill } = tiles;
7
+ const blocks = require('./dash-blocks.js');
8
+ const { filesBlock, diffsBlock, npmBlock, tasksBlock } = blocks;
9
+ const activity = require('./dash-activity.js');
10
+ const { commitsBlock, branchesBlock, runsBlock } = activity;
11
+
12
+ const TILES = [
13
+ { id: 'files', key: 'f', title: 'files', rank: 3, build: filesBlock },
14
+ { id: 'diffs', key: 'd', title: 'diffs', rank: 0, build: diffsBlock },
15
+ { id: 'tasks', key: 't', title: 'tasks', rank: 4, build: tasksBlock },
16
+ {
17
+ id: 'branches',
18
+ key: 'b',
19
+ title: 'branches',
20
+ rank: 5,
21
+ build: branchesBlock,
22
+ },
23
+ { id: 'commits', key: 'c', title: 'commits', rank: 2, build: commitsBlock },
24
+ { id: 'run', key: 'r', title: 'run', rank: 1, build: runsBlock },
25
+ { id: 'npm', key: 'n', title: 'npm', rank: 6, build: npmBlock },
26
+ ];
27
+ const TILE_BY_ID = new Map(TILES.map((tile) => [tile.id, tile]));
28
+ const MARGIN_MIN_H = 12;
29
+
30
+ const paintTiles = (model, bands, color) => {
31
+ const painted = new Map();
32
+ const ctx = { now: model.now, frame: model.frame };
33
+ for (const band of bands) {
34
+ for (const place of band.tiles) {
35
+ const tile = TILE_BY_ID.get(place.id);
36
+ const inner = Math.max(0, place.w - 2);
37
+ const room = Math.max(0, band.h - 1);
38
+ const content = tile.build(model, inner, room, ctx, tile);
39
+ painted.set(place.id, paintTile(tile, content, place.w, band.h, color));
40
+ }
41
+ }
42
+ return painted;
43
+ };
44
+
45
+ const paintBodyDashboard = (view, width, color, bodyH, headerLines) => {
46
+ const model = view.dashboard;
47
+ if (!model) {
48
+ const blank = paintBodyFill(width, color, 'files');
49
+ return paneResult({ body: new Array(bodyH).fill(blank) });
50
+ }
51
+ const margin = bodyH >= MARGIN_MIN_H ? 1 : 0;
52
+ const height = bodyH - margin * 2;
53
+ const bands = layoutTiles(width, height, TILES);
54
+ const painted = paintTiles(model, bands, color);
55
+ const rows = composeBands(bands, painted, width, height, color);
56
+ const pad = new Array(margin).fill(pageFill(width, color));
57
+ const body = [...pad, ...rows, ...pad];
58
+ const fileHits = tileHits(bands, headerLines + margin);
59
+ return paneResult({ body, fileHits });
60
+ };
61
+
62
+ module.exports = { TILES, paintBodyDashboard };