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
package/lib/select.js CHANGED
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  const ansi = require('./ansi.js');
4
-
5
- const { ESC, RESET, THEME, seq, stripAnsi, graphemes, graphemeWidth } = ansi;
6
- const { visibleWidth } = ansi;
4
+ const { ESC, RESET, THEME, seq, fg, bg, stripAnsi, visibleWidth } = ansi;
5
+ const { graphemes, graphemeWidth, firstGrapheme } = ansi;
7
6
 
8
7
  const CSI_FINAL = /[@-~]/;
8
+ const TRUECOLOR = 2;
9
9
 
10
10
  const isRange = (sel) => {
11
11
  if (!sel || !sel.start || !sel.end) return false;
@@ -13,21 +13,16 @@ const isRange = (sel) => {
13
13
  };
14
14
 
15
15
  const ordered = (sel) => {
16
- const start = sel.start;
17
- const end = sel.end;
18
- if (start.y < end.y) return { first: start, last: end };
19
- if (start.y > end.y) return { first: end, last: start };
20
- if (start.x <= end.x) return { first: start, last: end };
21
- return { first: end, last: start };
16
+ const { start, end } = sel;
17
+ const forward = start.y < end.y || (start.y === end.y && start.x <= end.x);
18
+ return forward ? { first: start, last: end } : { first: end, last: start };
22
19
  };
23
20
 
24
21
  const slicePlain = (plain, fromCol, toCol) => {
25
- const parts = graphemes(plain);
26
22
  let col = 0;
27
23
  let out = '';
28
- for (const ch of parts) {
29
- const w = graphemeWidth(ch, col);
30
- const next = col + w;
24
+ for (const ch of graphemes(plain)) {
25
+ const next = col + graphemeWidth(ch, col);
31
26
  if (next > fromCol && col < toCol) out += ch;
32
27
  col = next;
33
28
  if (col >= toCol) break;
@@ -39,10 +34,8 @@ const lineRange = (rowIndex, sel) => {
39
34
  const { first, last } = ordered(sel);
40
35
  const y = rowIndex + 1;
41
36
  if (y < first.y || y > last.y) return null;
42
- let from = 0;
43
- let to = Infinity;
44
- if (y === first.y) from = first.x - 1;
45
- if (y === last.y) to = last.x;
37
+ const from = y === first.y ? first.x - 1 : 0;
38
+ const to = y === last.y ? last.x : Infinity;
46
39
  if (to <= from) return null;
47
40
  return { from, to };
48
41
  };
@@ -61,11 +54,10 @@ const extractText = (rows, sel) => {
61
54
  return lines.join('\n');
62
55
  };
63
56
 
64
- const consumeCsi = (line, i) => {
57
+ const csiEnd = (line, i) => {
65
58
  let j = i + 2;
66
59
  while (j < line.length && !CSI_FINAL.test(line[j])) j += 1;
67
- if (j < line.length) j += 1;
68
- return j;
60
+ return j < line.length ? j + 1 : j;
69
61
  };
70
62
 
71
63
  const parseParams = (body) => {
@@ -74,45 +66,30 @@ const parseParams = (body) => {
74
66
  };
75
67
 
76
68
  const applyRgb = (state, field, params, i) => {
77
- const TRUECOLOR = 2;
78
69
  const isTruecolor = params[i + 1] === TRUECOLOR;
79
- const hasRgb = isTruecolor && i + 4 < params.length;
80
- if (!hasRgb) return 1;
70
+ if (!isTruecolor || i + 4 >= params.length) return 1;
81
71
  state[field] = [params[i + 2], params[i + 3], params[i + 4]];
82
72
  return 5;
83
73
  };
84
74
 
85
- const SGR = {
86
- 0: (state) => {
87
- state.fg = null;
88
- state.bg = null;
89
- return 1;
90
- },
91
- 38: (state, params, i) => applyRgb(state, 'fg', params, i),
92
- 48: (state, params, i) => applyRgb(state, 'bg', params, i),
93
- 39: (state) => {
94
- state.fg = null;
95
- return 1;
96
- },
97
- 49: (state) => {
98
- state.bg = null;
99
- return 1;
100
- },
101
- };
102
-
103
75
  const applySgr = (params, state) => {
104
76
  let i = 0;
105
77
  while (i < params.length) {
106
- const apply = SGR[params[i]];
107
- i += apply ? apply(state, params, i) : 1;
78
+ const code = params[i];
79
+ if (code === 38) {
80
+ i += applyRgb(state, 'fg', params, i);
81
+ continue;
82
+ }
83
+ if (code === 48) {
84
+ i += applyRgb(state, 'bg', params, i);
85
+ continue;
86
+ }
87
+ if (code === 0 || code === 39) state.fg = null;
88
+ if (code === 0 || code === 49) state.bg = null;
89
+ i += 1;
108
90
  }
109
91
  };
110
92
 
111
- const nextGrapheme = (line, index) => {
112
- const parts = graphemes(line.slice(index));
113
- return parts[0] ?? '';
114
- };
115
-
116
93
  const parseCells = (line) => {
117
94
  const cells = [];
118
95
  const state = { fg: null, bg: null };
@@ -120,24 +97,21 @@ const parseCells = (line) => {
120
97
  let i = 0;
121
98
  while (i < line.length) {
122
99
  if (line[i] === ESC && line[i + 1] === '[') {
123
- const n = consumeCsi(line, i);
124
- if (line[n - 1] === 'm') {
125
- const body = line.slice(i + 2, n - 1);
126
- applySgr(parseParams(body), state);
100
+ const end = csiEnd(line, i);
101
+ if (line[end - 1] === 'm') {
102
+ applySgr(parseParams(line.slice(i + 2, end - 1)), state);
127
103
  }
128
- i = n;
104
+ i = end;
129
105
  continue;
130
106
  }
131
107
  if (line[i] === ESC) {
132
108
  i += 1;
133
109
  continue;
134
110
  }
135
- const ch = nextGrapheme(line, i);
111
+ const ch = firstGrapheme(line.slice(i));
136
112
  if (!ch) break;
137
113
  const width = graphemeWidth(ch, col);
138
- const fg = state.fg;
139
- const bg = state.bg;
140
- cells.push({ ch, fg, bg, col, width });
114
+ cells.push({ ch, fg: state.fg, bg: state.bg, col, width });
141
115
  col += width;
142
116
  i += ch.length;
143
117
  }
@@ -146,10 +120,10 @@ const parseCells = (line) => {
146
120
 
147
121
  const rgbKey = (rgb) => (rgb ? `${rgb[0]},${rgb[1]},${rgb[2]}` : '');
148
122
 
149
- const styleSeq = (fg, bg) => {
150
- if (fg && bg) return RESET + seq(fg, bg);
151
- if (fg) return RESET + ansi.fg(fg);
152
- if (bg) return RESET + ansi.bg(bg);
123
+ const styleSeq = (fgRgb, bgRgb) => {
124
+ if (fgRgb && bgRgb) return RESET + seq(fgRgb, bgRgb);
125
+ if (fgRgb) return RESET + fg(fgRgb);
126
+ if (bgRgb) return RESET + bg(bgRgb);
153
127
  return RESET;
154
128
  };
155
129
 
@@ -160,17 +134,15 @@ const overlayRange = (line, fromCol, toCol) => {
160
134
  let out = '';
161
135
  let last = null;
162
136
  for (const cell of cells) {
163
- const next = cell.col + cell.width;
164
- const hit = next > fromCol && cell.col < toCol;
165
- let fg = cell.fg;
166
- let bg = cell.bg;
167
- if (hit) {
168
- fg = cell.bg ?? THEME.ctxBg;
169
- bg = cell.fg ?? THEME.ctxFg;
137
+ let cellFg = cell.fg;
138
+ let cellBg = cell.bg;
139
+ if (cell.col + cell.width > fromCol && cell.col < toCol) {
140
+ cellFg = cell.bg ?? THEME.ctxBg;
141
+ cellBg = cell.fg ?? THEME.ctxFg;
170
142
  }
171
- const key = `${rgbKey(fg)}|${rgbKey(bg)}`;
143
+ const key = `${rgbKey(cellFg)}|${rgbKey(cellBg)}`;
172
144
  if (key !== last) {
173
- out += styleSeq(fg, bg);
145
+ out += styleSeq(cellFg, cellBg);
174
146
  last = key;
175
147
  }
176
148
  out += cell.ch;
@@ -178,35 +150,29 @@ const overlayRange = (line, fromCol, toCol) => {
178
150
  return out;
179
151
  };
180
152
 
181
- const selectionOf = (source) => {
153
+ const editorSelection = (view) => {
154
+ const source = view?.compose || view?.codeOverlay;
182
155
  if (!source || typeof source.anchor !== 'number') return null;
183
156
  const cursor = source.cursor ?? 0;
184
157
  if (source.anchor === cursor) return null;
185
158
  return { anchor: source.anchor, cursor };
186
159
  };
187
160
 
188
- const editorSelection = (view) => {
189
- if (!view) return null;
190
- if (view.compose) return selectionOf(view.compose);
191
- return selectionOf(view.codeOverlay);
192
- };
193
-
194
161
  const spanCols = (hit, lo, hi) => {
195
162
  const start = hit.start ?? 0;
196
163
  const from = Math.max(lo, start);
197
164
  const to = Math.min(hi, hit.limit ?? start);
198
165
  if (to <= from) return null;
199
166
  const text = hit.text ?? '';
200
- const head = Math.max(0, from - start);
201
- const tail = Math.max(0, to - start);
202
- const c0 = visibleWidth(text.slice(0, head));
203
- const c1 = visibleWidth(text.slice(0, tail));
167
+ const c0 = visibleWidth(text.slice(0, Math.max(0, from - start)));
168
+ const c1 = visibleWidth(text.slice(0, Math.max(0, to - start)));
204
169
  const scroll = hit.scroll ?? 0;
205
- const room = Math.max(0, (hit.x1 ?? hit.textX ?? 1) - (hit.textX ?? 1));
170
+ const textX = hit.textX ?? 1;
171
+ const room = Math.max(0, (hit.x1 ?? textX) - textX);
206
172
  const vis0 = Math.max(c0, scroll);
207
173
  const vis1 = Math.min(c1, scroll + room);
208
174
  if (vis1 <= vis0) return null;
209
- const origin = (hit.textX ?? 1) - 1;
175
+ const origin = textX - 1;
210
176
  return { from: origin + vis0 - scroll, to: origin + vis1 - scroll };
211
177
  };
212
178
 
@@ -220,9 +186,8 @@ const markEditorSelection = (rows, view, hits, color) => {
220
186
  for (const hit of hits) {
221
187
  if (!hit.live || !hit.y) continue;
222
188
  const range = spanCols(hit, lo, hi);
223
- if (!range) continue;
224
189
  const i = hit.y - 1;
225
- if (i < 0 || i >= next.length) continue;
190
+ if (!range || i < 0 || i >= next.length) continue;
226
191
  next[i] = overlayRange(next[i], range.from, range.to);
227
192
  }
228
193
  return next;
@@ -230,13 +195,10 @@ const markEditorSelection = (rows, view, hits, color) => {
230
195
 
231
196
  const overlayRows = (rows, sel) => {
232
197
  if (!isRange(sel)) return rows;
233
- const { length } = rows;
234
- const next = new Array(length);
235
- for (let i = 0; i < length; i++) {
198
+ return rows.map((row, i) => {
236
199
  const range = lineRange(i, sel);
237
- next[i] = range ? overlayRange(rows[i], range.from, range.to) : rows[i];
238
- }
239
- return next;
200
+ return range ? overlayRange(row, range.from, range.to) : row;
201
+ });
240
202
  };
241
203
 
242
204
  module.exports = {
@@ -1,33 +1,26 @@
1
1
  'use strict';
2
2
 
3
- const bindAlias = (target, name, get, set) => {
4
- const desc = { configurable: true, enumerable: true, get };
5
- if (set) desc.set = set;
6
- Object.defineProperty(target, name, desc);
7
- };
8
-
9
3
  const bindAccessors = (target, owner, names) => {
10
4
  for (const name of names) {
11
- const get = () => owner[name];
12
- const set = (value) => {
13
- owner[name] = value;
14
- };
15
- bindAlias(target, name, get, set);
5
+ Object.defineProperty(target, name, {
6
+ configurable: true,
7
+ enumerable: true,
8
+ get: () => owner[name],
9
+ set: (value) => {
10
+ owner[name] = value;
11
+ },
12
+ });
16
13
  }
17
14
  };
18
15
 
19
16
  const bindGetters = (target, owner, names) => {
20
17
  for (const name of names) {
21
- bindAlias(target, name, () => owner[name]);
18
+ Object.defineProperty(target, name, {
19
+ configurable: true,
20
+ enumerable: true,
21
+ get: () => owner[name],
22
+ });
22
23
  }
23
24
  };
24
25
 
25
- const stateView = (state, methods, writable = [], readonly = []) => {
26
- const descriptors = Object.getOwnPropertyDescriptors(methods);
27
- const view = Object.defineProperties({}, descriptors);
28
- bindAccessors(view, state, writable);
29
- bindGetters(view, state, readonly);
30
- return view;
31
- };
32
-
33
- module.exports = { bindAccessors, bindGetters, bindAlias, stateView };
26
+ module.exports = { bindAccessors, bindGetters };