git-watchtower 2.3.21 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-watchtower",
3
- "version": "2.3.21",
3
+ "version": "2.3.22",
4
4
  "description": "Terminal-based Git branch monitor with activity sparklines and optional dev server with live reload",
5
5
  "main": "bin/git-watchtower.js",
6
6
  "bin": {
@@ -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
- const padding = Math.max(0, Math.floor((width - label.length) / 2));
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
- const padding = Math.max(0, Math.floor((width - display.length) / 2));
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
  }