pi-cc-extensions 0.9.5 → 0.9.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.
@@ -45,3 +45,32 @@ export function stripLeadingStatusIcon(line: string): string {
45
45
  "$1",
46
46
  );
47
47
  }
48
+
49
+ /** 终端序列零宽(不计入 plain 下标),与 stripAnsi/stripTerminalSequencesPreservingLayout 一致。 */
50
+ const ANY_SEQUENCE_RE = new RegExp(`${CSI_SEQUENCE_RE.source}|${OSC_SEQUENCE_RE.source}`, "g");
51
+
52
+ /** 只保留 [start, end) 之外的字符(base 为 text 首字符在 plain 串中的下标)。 */
53
+ function keepOutsideRange(text: string, base: number, start: number, end: number): string {
54
+ if (base + text.length <= start || base >= end) return text;
55
+ return text.slice(0, Math.max(0, start - base)) + text.slice(Math.max(0, end - base));
56
+ }
57
+
58
+ /**
59
+ * 删除 plain 区间 [start, end) 的字符,保留其余字符的 ANSI 样式。
60
+ * 区间内的终端序列原样保留,因此区间后的字符(如收尾括号)沿用前文颜色,
61
+ * 不会像截断后拼纯文本那样掉回终端默认前景色。
62
+ */
63
+ export function removeStyledRange(styled: string, start: number, end: number): string {
64
+ if (end <= start) return styled;
65
+ let plain = 0;
66
+ let cursor = 0;
67
+ let out = "";
68
+ for (const match of styled.matchAll(ANY_SEQUENCE_RE)) {
69
+ const text = styled.slice(cursor, match.index);
70
+ out += keepOutsideRange(text, plain, start, end);
71
+ plain += text.length;
72
+ out += match[0];
73
+ cursor = match.index + match[0].length;
74
+ }
75
+ return out + keepOutsideRange(styled.slice(cursor), plain, start, end);
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-cc-extensions",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
4
4
  "license": "MIT",
5
5
  "description": "Claude Code-style TUI output with some personal touches and handy utilities.",
6
6
  "type": "module",
@@ -38,6 +38,7 @@
38
38
  },
39
39
  "scripts": {
40
40
  "test": "node --test tests/**/*.test.ts",
41
+ "coverage": "node --test --experimental-test-coverage --test-coverage-include=extensions/**/*.ts tests/**/*.test.ts",
41
42
  "typecheck": "tsc --noEmit",
42
43
  "format": "biome format --write .",
43
44
  "format:check": "biome format .",