git-watchtower 2.3.20 → 2.3.22
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/package.json +1 -1
- package/src/casino/index.js +12 -3
- package/src/state/store.js +35 -3
package/package.json
CHANGED
package/src/casino/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* like hitting the jackpot.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
const { ansi, box } = require('../ui/ansi');
|
|
9
|
+
const { ansi, box, visibleLength } = require('../ui/ansi');
|
|
10
10
|
const sounds = require('./sounds');
|
|
11
11
|
|
|
12
12
|
// ============================================================================
|
|
@@ -537,7 +537,13 @@ function getWinDisplay(width) {
|
|
|
537
537
|
const label = currentWinLevel.label;
|
|
538
538
|
const color = flashOn ? currentWinLevel.color : ansi.dim + currentWinLevel.color;
|
|
539
539
|
|
|
540
|
-
|
|
540
|
+
// Use visibleLength so multi-codepoint emoji clusters (ZWJ family,
|
|
541
|
+
// flag emoji, variation selectors) are counted by display columns
|
|
542
|
+
// rather than UTF-16 code units. The current WIN_LEVELS labels happen
|
|
543
|
+
// to use 2-codepoint emoji whose .length matches column width, but a
|
|
544
|
+
// future label with a flag or family emoji would otherwise center
|
|
545
|
+
// off by one or more columns per glyph.
|
|
546
|
+
const padding = Math.max(0, Math.floor((width - visibleLength(label)) / 2));
|
|
541
547
|
|
|
542
548
|
return color + ' '.repeat(padding) + label + ' '.repeat(padding) + ansi.reset;
|
|
543
549
|
}
|
|
@@ -615,7 +621,10 @@ function getLossDisplay(width) {
|
|
|
615
621
|
const display = `${symbols}${lossMessage}${symbols}`;
|
|
616
622
|
const color = flashOn ? ansi.bgRed + ansi.white : ansi.bgBlack + ansi.red;
|
|
617
623
|
|
|
618
|
-
|
|
624
|
+
// Same reasoning as getWinDisplay: count terminal columns, not UTF-16
|
|
625
|
+
// code units. Untrusted lossMessage strings can also contain wide
|
|
626
|
+
// characters (e.g. CJK in error messages from a localised git build).
|
|
627
|
+
const padding = Math.max(0, Math.floor((width - visibleLength(display)) / 2));
|
|
619
628
|
|
|
620
629
|
return color + ' '.repeat(padding) + display + ' '.repeat(padding) + ansi.reset;
|
|
621
630
|
}
|
package/src/state/store.js
CHANGED
|
@@ -209,15 +209,47 @@ class Store {
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
/**
|
|
212
|
-
* Get a
|
|
212
|
+
* Get a snapshot of the current state.
|
|
213
|
+
*
|
|
214
|
+
* The top-level object is a shallow copy (so adding/removing top-level
|
|
215
|
+
* keys on the returned object does not mutate the store). Map values
|
|
216
|
+
* (sparklineCache, branchPrStatusMap, aheadBehindCache) are also
|
|
217
|
+
* shallow-cloned so that consumers — most importantly the web
|
|
218
|
+
* dashboard's getSerializableState — can iterate or mutate the
|
|
219
|
+
* snapshot without the store's live data shifting underneath them.
|
|
220
|
+
*
|
|
221
|
+
* If you need the live, by-reference Map for in-place mutation
|
|
222
|
+
* followed by setState() (the polling cache-prune pattern), use
|
|
223
|
+
* `get(key)` instead.
|
|
224
|
+
*
|
|
213
225
|
* @returns {State}
|
|
214
226
|
*/
|
|
215
227
|
getState() {
|
|
216
|
-
|
|
228
|
+
const snapshot = { ...this.state };
|
|
229
|
+
if (snapshot.sparklineCache instanceof Map) {
|
|
230
|
+
snapshot.sparklineCache = new Map(snapshot.sparklineCache);
|
|
231
|
+
}
|
|
232
|
+
if (snapshot.branchPrStatusMap instanceof Map) {
|
|
233
|
+
snapshot.branchPrStatusMap = new Map(snapshot.branchPrStatusMap);
|
|
234
|
+
}
|
|
235
|
+
if (snapshot.aheadBehindCache instanceof Map) {
|
|
236
|
+
snapshot.aheadBehindCache = new Map(snapshot.aheadBehindCache);
|
|
237
|
+
}
|
|
238
|
+
return snapshot;
|
|
217
239
|
}
|
|
218
240
|
|
|
219
241
|
/**
|
|
220
|
-
* Get a specific state value
|
|
242
|
+
* Get a specific state value by-reference.
|
|
243
|
+
*
|
|
244
|
+
* IMPORTANT: returns the live value, not a copy. For Map values
|
|
245
|
+
* (sparklineCache, branchPrStatusMap, aheadBehindCache) this is
|
|
246
|
+
* deliberate — the polling layer mutates these in place and then
|
|
247
|
+
* calls setState({key: sameMap}) to notify subscribers. Code that
|
|
248
|
+
* doesn't intend to mutate should treat the result as read-only,
|
|
249
|
+
* or copy it first (e.g. `new Map(store.get('sparklineCache'))`).
|
|
250
|
+
*
|
|
251
|
+
* For an isolation-safe snapshot, prefer `getState()`.
|
|
252
|
+
*
|
|
221
253
|
* @template {keyof State} K
|
|
222
254
|
* @param {K} key - State key
|
|
223
255
|
* @returns {State[K]}
|