@runminton/pi-tidy-tools 0.2.1 → 0.2.2

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/README.md CHANGED
@@ -91,6 +91,10 @@ If a shortcut still does nothing on your machine, check:
91
91
 
92
92
  ## Changelog
93
93
 
94
+ ### 0.2.2
95
+
96
+ - Cached collapsed bash output by terminal width to reduce repeated rendering work during TUI redraws with many tool calls
97
+
94
98
  ### 0.2.1
95
99
 
96
100
  - Added per-block fullscreen clicking for bash/edit/write, toggling between compact and full rendering
package/README.zh-CN.md CHANGED
@@ -91,6 +91,10 @@ Pi 会在终端支持时协商 [Kitty 键盘协议](https://sw.kovidgoyal.net/ki
91
91
 
92
92
  ## 更新日志
93
93
 
94
+ ### 0.2.2
95
+
96
+ - 按终端宽度缓存 bash 折叠输出,降低多轮工具调用场景下 TUI 重绘开销
97
+
94
98
  ### 0.2.1
95
99
 
96
100
  - 支持在 Pi fullscreen 模式下点击单个 bash/edit/write 工具块,在紧凑摘要和完整渲染之间切换
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runminton/pi-tidy-tools",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Collapse bash/edit/write into one-line summaries in the pi TUI; expand the official rendering per tool with Ctrl+Alt+B/W/E.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/tidy-tools.ts CHANGED
@@ -133,6 +133,9 @@ class LimitedLinesText implements Component {
133
133
  }
134
134
 
135
135
  class CollapsedBashOutput implements Component {
136
+ private cachedWidth?: number;
137
+ private cachedLines?: string[];
138
+
136
139
  // 首行预览 + 计数后缀合并为 1 行,后缀常显。预览放不下时截断并加省略标记。
137
140
  constructor(
138
141
  private readonly preview: string,
@@ -141,6 +144,16 @@ class CollapsedBashOutput implements Component {
141
144
  ) {}
142
145
 
143
146
  render(width: number): string[] {
147
+ if (this.cachedLines !== undefined && this.cachedWidth === width) {
148
+ return this.cachedLines;
149
+ }
150
+ const lines = this.renderUncached(width);
151
+ this.cachedWidth = width;
152
+ this.cachedLines = lines;
153
+ return lines;
154
+ }
155
+
156
+ private renderUncached(width: number): string[] {
144
157
  if (!this.suffix) {
145
158
  return truncateRows(
146
159
  wrapTextWithAnsi(this.preview, Math.max(1, width)),
@@ -169,7 +182,10 @@ class CollapsedBashOutput implements Component {
169
182
  return [visibleWidth(row) > width ? sliceByColumn(row, 0, width, true) : row];
170
183
  }
171
184
 
172
- invalidate(): void {}
185
+ invalidate(): void {
186
+ this.cachedWidth = undefined;
187
+ this.cachedLines = undefined;
188
+ }
173
189
  }
174
190
 
175
191
  class CollapsedToolShell extends Box {