@xynogen/pix-pretty 1.37.1 → 1.37.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 +1 -1
- package/src/command-preview.ts +58 -23
package/package.json
CHANGED
package/src/command-preview.ts
CHANGED
|
@@ -40,32 +40,53 @@ export function commandPreview(
|
|
|
40
40
|
}
|
|
41
41
|
const current = slot;
|
|
42
42
|
let replacement: string | undefined;
|
|
43
|
+
const text = new Text("", 0, 0);
|
|
44
|
+
let memo:
|
|
45
|
+
| { width: number; styled: string; replacement: string | undefined; lines: string[] }
|
|
46
|
+
| undefined;
|
|
47
|
+
const layout = (width: number): string[] => {
|
|
48
|
+
if (replacement !== undefined) {
|
|
49
|
+
text.setText(replacement);
|
|
50
|
+
return replacement ? text.render(width) : [];
|
|
51
|
+
}
|
|
52
|
+
const separator = theme.fg("muted", " · ");
|
|
53
|
+
if (!code.includes("\n") && visibleWidth(header) + 3 + visibleWidth(code) <= width) {
|
|
54
|
+
text.setText(`${header}${separator}${current.styled}`);
|
|
55
|
+
return text.render(width);
|
|
56
|
+
}
|
|
57
|
+
// ponytail: preserve shell syntax with native wrapping; use a parser only for semantic formatting.
|
|
58
|
+
const padding = " ".repeat(indent);
|
|
59
|
+
const lines = wrapTextWithAnsi(current.styled, Math.max(1, width - indent));
|
|
60
|
+
const shown = expanded ? lines : fadeRowsOf(lines.slice(0, 17), theme, 16);
|
|
61
|
+
return [
|
|
62
|
+
truncateToWidth(`${header}${separator}`, width, "…"),
|
|
63
|
+
...shown.map((line) => `${padding}${line}`),
|
|
64
|
+
...(shown.length < lines.length
|
|
65
|
+
? [
|
|
66
|
+
`${theme.fg("muted", `${padding}… +${lines.length - shown.length} lines `)}${expandHint(theme, ctx)}`,
|
|
67
|
+
]
|
|
68
|
+
: []),
|
|
69
|
+
];
|
|
70
|
+
};
|
|
43
71
|
return {
|
|
44
72
|
setText(value: string) {
|
|
45
73
|
replacement = value;
|
|
46
74
|
},
|
|
47
75
|
getText: () => replacement ?? `${header}${theme.fg("muted", " · ")}${current.styled}`,
|
|
48
|
-
invalidate() {
|
|
76
|
+
invalidate() {
|
|
77
|
+
memo = undefined;
|
|
78
|
+
text.invalidate();
|
|
79
|
+
},
|
|
49
80
|
render(width: number): string[] {
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const shown = expanded ? lines : fadeRowsOf(lines.slice(0, 17), theme, 16);
|
|
60
|
-
return [
|
|
61
|
-
truncateToWidth(`${header}${separator}`, width, "…"),
|
|
62
|
-
...shown.map((line) => `${padding}${line}`),
|
|
63
|
-
...(shown.length < lines.length
|
|
64
|
-
? [
|
|
65
|
-
`${theme.fg("muted", `${padding}… +${lines.length - shown.length} lines `)}${expandHint(theme, ctx)}`,
|
|
66
|
-
]
|
|
67
|
-
: []),
|
|
68
|
-
];
|
|
81
|
+
if (
|
|
82
|
+
memo?.width === width &&
|
|
83
|
+
memo.styled === current.styled &&
|
|
84
|
+
memo.replacement === replacement
|
|
85
|
+
)
|
|
86
|
+
return memo.lines;
|
|
87
|
+
const lines = layout(width);
|
|
88
|
+
memo = { width, styled: current.styled, replacement, lines };
|
|
89
|
+
return lines;
|
|
69
90
|
},
|
|
70
91
|
};
|
|
71
92
|
}
|
|
@@ -80,21 +101,35 @@ export function collapsedCommandRow(
|
|
|
80
101
|
const prefix = `${header}${theme.fg("muted", " · ")}`;
|
|
81
102
|
let text = `${prefix}${theme.fg("dim", plain)}`;
|
|
82
103
|
let replaced = false;
|
|
104
|
+
const replacementText = new Text("", 0, 0);
|
|
105
|
+
let memo: { width: number; text: string; replaced: boolean; lines: string[] } | undefined;
|
|
83
106
|
return {
|
|
84
107
|
setText(value: string) {
|
|
85
108
|
text = value;
|
|
86
109
|
replaced = true;
|
|
87
110
|
},
|
|
88
111
|
getText: () => text,
|
|
89
|
-
invalidate() {
|
|
112
|
+
invalidate() {
|
|
113
|
+
memo = undefined;
|
|
114
|
+
replacementText.invalidate();
|
|
115
|
+
},
|
|
90
116
|
render(width: number): string[] {
|
|
91
|
-
if (
|
|
117
|
+
if (memo?.width === width && memo.text === text && memo.replaced === replaced)
|
|
118
|
+
return memo.lines;
|
|
119
|
+
if (replaced) {
|
|
120
|
+
replacementText.setText(text);
|
|
121
|
+
const lines = text ? replacementText.render(width) : [];
|
|
122
|
+
memo = { width, text, replaced, lines };
|
|
123
|
+
return lines;
|
|
124
|
+
}
|
|
92
125
|
const room = width - visibleWidth(prefix);
|
|
93
|
-
|
|
126
|
+
const lines = [
|
|
94
127
|
room > 0
|
|
95
128
|
? `${prefix}${fadeText(plain, room, fadePaint(theme))}`
|
|
96
129
|
: truncateToWidth(prefix, width, "…"),
|
|
97
130
|
];
|
|
131
|
+
memo = { width, text, replaced, lines };
|
|
132
|
+
return lines;
|
|
98
133
|
},
|
|
99
134
|
};
|
|
100
135
|
}
|