@aliou/pi-processes 0.9.1 → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aliou/pi-processes",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "private": false,
@@ -0,0 +1,29 @@
1
+ import { visibleWidth } from "@earendil-works/pi-tui";
2
+ import { describe, expect, it } from "vitest";
3
+ import { renderCollapsedDockLine } from "./log-dock-component";
4
+
5
+ const LONG_LOG_LINE =
6
+ "build-step - 3f7a9c2 pending ↻ https://example.com/pipelines/project/service/123456/workflows/abcdef12-3456-7890-abcd-ef1234567890/jobs/integration-test?token=very-long-unbroken-log-segment-and-query-string";
7
+
8
+ describe("renderCollapsedDockLine", () => {
9
+ it("leaves a spare terminal column for long log lines", () => {
10
+ for (const width of [1, 2, 40, 80, 120]) {
11
+ const rendered = renderCollapsedDockLine(LONG_LOG_LINE, width);
12
+
13
+ expect(visibleWidth(rendered)).toBe(width - 1);
14
+ }
15
+ });
16
+
17
+ it("leaves a spare terminal column for ansi-styled log lines", () => {
18
+ const rendered = renderCollapsedDockLine(
19
+ `\u001b[2m${LONG_LOG_LINE}\u001b[22m`,
20
+ 80,
21
+ );
22
+
23
+ expect(visibleWidth(rendered)).toBe(79);
24
+ });
25
+
26
+ it("renders nothing for zero width", () => {
27
+ expect(renderCollapsedDockLine(LONG_LOG_LINE, 0)).toBe("");
28
+ });
29
+ });
@@ -29,6 +29,24 @@ const PROCESS_COLORS: ThemeColor[] = [
29
29
  "warning",
30
30
  ];
31
31
 
32
+ const COLLAPSED_DOCK_RIGHT_MARGIN = 1;
33
+
34
+ function getCollapsedDockLineWidth(width: number): number {
35
+ return Math.max(0, width - COLLAPSED_DOCK_RIGHT_MARGIN);
36
+ }
37
+
38
+ export function renderCollapsedDockLine(
39
+ content: string,
40
+ width: number,
41
+ ): string {
42
+ const lineWidth = getCollapsedDockLineWidth(width);
43
+ if (lineWidth === 0) return "";
44
+
45
+ const innerWidth = Math.max(0, lineWidth - 2);
46
+ const line = truncateToWidth(content, innerWidth, "", true);
47
+ return ` ${line}${" ".repeat(Math.max(0, lineWidth - 1 - visibleWidth(line)))}`;
48
+ }
49
+
32
50
  interface LogDockOptions {
33
51
  manager: ProcessManager;
34
52
  theme: Theme;
@@ -120,17 +138,12 @@ export class LogDockComponent implements Component {
120
138
  const fg = (color: ThemeColor, s: string) => theme.fg(color, s);
121
139
 
122
140
  const processes = this.manager.list();
123
- const innerWidth = width - 2;
124
- const padLine = (content: string) => {
125
- const line =
126
- visibleWidth(content) > innerWidth
127
- ? truncateToWidth(content, innerWidth, "", true)
128
- : content;
129
- return ` ${line}${" ".repeat(Math.max(0, width - 1 - visibleWidth(line)))}`;
130
- };
141
+ const lineWidth = getCollapsedDockLineWidth(width);
142
+ const padLine = (content: string) =>
143
+ renderCollapsedDockLine(content, width);
131
144
 
132
145
  if (processes.length === 0) {
133
- return [renderPanelRule(width, theme), padLine(dim("No processes"))];
146
+ return [renderPanelRule(lineWidth, theme), padLine(dim("No processes"))];
134
147
  }
135
148
 
136
149
  const running = processes.filter((p) => LIVE_STATUSES.has(p.status));
@@ -146,20 +159,12 @@ export class LogDockComponent implements Component {
146
159
  }
147
160
 
148
161
  const firstLine = parts.join(" | ");
149
- const lines = [
150
- renderPanelRule(width, theme),
151
- padLine(truncateToWidth(firstLine, innerWidth, "", true)),
152
- ];
162
+ const lines = [renderPanelRule(lineWidth, theme), padLine(firstLine)];
153
163
 
154
164
  if (running.length > 0) {
155
165
  const lastLogs = this.manager.getCombinedOutput(running[0].id, 1);
156
166
  if (lastLogs && lastLogs.length > 0) {
157
- const lastLog = truncateToWidth(
158
- stripAnsi(lastLogs[lastLogs.length - 1].text),
159
- innerWidth,
160
- "",
161
- true,
162
- );
167
+ const lastLog = stripAnsi(lastLogs[lastLogs.length - 1].text);
163
168
  lines.push(padLine(dim(lastLog)));
164
169
  }
165
170
  }