git-watchtower 2.3.24 → 2.3.25
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/ui/ansi.js +62 -8
package/package.json
CHANGED
package/src/ui/ansi.js
CHANGED
|
@@ -602,25 +602,79 @@ function style(text, ...styles) {
|
|
|
602
602
|
}
|
|
603
603
|
|
|
604
604
|
/**
|
|
605
|
-
*
|
|
605
|
+
* Walk graphemes up to a column budget, returning the longest prefix
|
|
606
|
+
* whose visible width does not exceed `maxCols`. Drops one grapheme
|
|
607
|
+
* past the budget (mirrors how truncate() consumes — never mid-cut
|
|
608
|
+
* a wide char or surrogate pair).
|
|
609
|
+
* @param {string} str
|
|
610
|
+
* @param {number} maxCols
|
|
611
|
+
* @returns {string}
|
|
612
|
+
* @private
|
|
613
|
+
*/
|
|
614
|
+
function _sliceByColumns(str, maxCols) {
|
|
615
|
+
if (maxCols <= 0) return '';
|
|
616
|
+
let acc = '';
|
|
617
|
+
let used = 0;
|
|
618
|
+
if (_graphemeSegmenter) {
|
|
619
|
+
for (const { segment } of _graphemeSegmenter.segment(str)) {
|
|
620
|
+
const w = visibleLength(segment);
|
|
621
|
+
if (used + w > maxCols) break;
|
|
622
|
+
acc += segment;
|
|
623
|
+
used += w;
|
|
624
|
+
}
|
|
625
|
+
} else {
|
|
626
|
+
for (const ch of str) {
|
|
627
|
+
const w = _codePointWidth(ch.codePointAt(0));
|
|
628
|
+
if (used + w > maxCols) break;
|
|
629
|
+
acc += ch;
|
|
630
|
+
used += w;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return acc;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Pad a string on the right to a target visible-column width.
|
|
638
|
+
* Truncates (without adding an ellipsis) when the input already
|
|
639
|
+
* exceeds the budget.
|
|
640
|
+
*
|
|
641
|
+
* Width is measured in display columns via visibleLength, NOT UTF-16
|
|
642
|
+
* `.length`. ASCII-only inputs keep their previous behaviour because
|
|
643
|
+
* `.length === visibleLength` for them. CJK / wide emoji / ZWJ
|
|
644
|
+
* clusters now pad by the columns they actually render in, and the
|
|
645
|
+
* truncate path slices on grapheme boundaries so a wide character
|
|
646
|
+
* isn't cut mid-byte.
|
|
647
|
+
*
|
|
648
|
+
* SGR-styled strings (e.g. `\x1b[31mhi\x1b[0m`) previously had their
|
|
649
|
+
* raw-byte length compared against `len`, so the colour wrapper made
|
|
650
|
+
* the string look "too long" and `substring(0, len)` cut the escape
|
|
651
|
+
* sequence in half — leaving the terminal in a stuck colour state.
|
|
652
|
+
* Now the width comparison uses visibleLength which strips ANSI
|
|
653
|
+
* before measuring, and the slice helper preserves SGR runs because
|
|
654
|
+
* they have width 0.
|
|
655
|
+
*
|
|
606
656
|
* @param {string} str - String to pad
|
|
607
|
-
* @param {number} len - Target
|
|
657
|
+
* @param {number} len - Target visible-column width
|
|
608
658
|
* @returns {string}
|
|
609
659
|
*/
|
|
610
660
|
function padRight(str, len) {
|
|
611
|
-
|
|
612
|
-
|
|
661
|
+
const cols = visibleLength(str);
|
|
662
|
+
if (cols >= len) return _sliceByColumns(str, len);
|
|
663
|
+
return str + ' '.repeat(len - cols);
|
|
613
664
|
}
|
|
614
665
|
|
|
615
666
|
/**
|
|
616
|
-
* Pad a string on the left
|
|
667
|
+
* Pad a string on the left to a target visible-column width.
|
|
668
|
+
* Same column-vs-codeunit semantics as {@link padRight}.
|
|
669
|
+
*
|
|
617
670
|
* @param {string} str - String to pad
|
|
618
|
-
* @param {number} len - Target
|
|
671
|
+
* @param {number} len - Target visible-column width
|
|
619
672
|
* @returns {string}
|
|
620
673
|
*/
|
|
621
674
|
function padLeft(str, len) {
|
|
622
|
-
|
|
623
|
-
|
|
675
|
+
const cols = visibleLength(str);
|
|
676
|
+
if (cols >= len) return _sliceByColumns(str, len);
|
|
677
|
+
return ' '.repeat(len - cols) + str;
|
|
624
678
|
}
|
|
625
679
|
|
|
626
680
|
/**
|