@pify/pretty 0.3.0 → 0.3.1
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/extensions/pretty.ts +6 -6
- package/package.json +1 -1
- package/src/summary.ts +49 -12
package/extensions/pretty.ts
CHANGED
|
@@ -126,7 +126,7 @@ export default function pretty(pi: ExtensionAPI) {
|
|
|
126
126
|
case "read":
|
|
127
127
|
return {
|
|
128
128
|
renderCall: (args: { path?: string; offset?: number; limit?: number }, theme: ThemeLike) =>
|
|
129
|
-
new Text(readCall(theme, args ?? {}), 0, 0),
|
|
129
|
+
new Text(readCall(theme, args ?? {}, settings.summaryClip), 0, 0),
|
|
130
130
|
renderResult: (
|
|
131
131
|
result: unknown,
|
|
132
132
|
options: { expanded?: boolean; isPartial?: boolean },
|
|
@@ -158,7 +158,7 @@ export default function pretty(pi: ExtensionAPI) {
|
|
|
158
158
|
case "bash":
|
|
159
159
|
return {
|
|
160
160
|
renderCall: (args: { command?: string }, theme: ThemeLike, context: { expanded?: boolean }) =>
|
|
161
|
-
new Text(bashCall(theme, args?.command ?? "", context?.expanded === true), 0, 0),
|
|
161
|
+
new Text(bashCall(theme, args?.command ?? "", context?.expanded === true, settings.summaryClip), 0, 0),
|
|
162
162
|
renderResult: (
|
|
163
163
|
result: unknown,
|
|
164
164
|
options: { expanded?: boolean; isPartial?: boolean },
|
|
@@ -176,7 +176,7 @@ export default function pretty(pi: ExtensionAPI) {
|
|
|
176
176
|
};
|
|
177
177
|
case "edit":
|
|
178
178
|
return {
|
|
179
|
-
renderCall: (args: { path?: string }, theme: ThemeLike) => new Text(editCall(theme, args ?? {}), 0, 0),
|
|
179
|
+
renderCall: (args: { path?: string }, theme: ThemeLike) => new Text(editCall(theme, args ?? {}, settings.summaryClip), 0, 0),
|
|
180
180
|
renderResult: (
|
|
181
181
|
result: unknown,
|
|
182
182
|
options: { expanded?: boolean; isPartial?: boolean },
|
|
@@ -198,7 +198,7 @@ export default function pretty(pi: ExtensionAPI) {
|
|
|
198
198
|
case "write":
|
|
199
199
|
return {
|
|
200
200
|
renderCall: (args: { path?: string; content?: string }, theme: ThemeLike) =>
|
|
201
|
-
new Text(writeCall(theme, args ?? {}), 0, 0),
|
|
201
|
+
new Text(writeCall(theme, args ?? {}, settings.summaryClip), 0, 0),
|
|
202
202
|
renderResult: (
|
|
203
203
|
result: unknown,
|
|
204
204
|
options: { expanded?: boolean; isPartial?: boolean },
|
|
@@ -217,7 +217,7 @@ export default function pretty(pi: ExtensionAPI) {
|
|
|
217
217
|
renderCall: (
|
|
218
218
|
args: { pattern?: string; path?: string; glob?: string },
|
|
219
219
|
theme: ThemeLike,
|
|
220
|
-
) => new Text(searchCall(theme, tool === "grep" ? "Grep" : "Find", args ?? {}), 0, 0),
|
|
220
|
+
) => new Text(searchCall(theme, tool === "grep" ? "Grep" : "Find", args ?? {}, settings.summaryClip), 0, 0),
|
|
221
221
|
renderResult: (
|
|
222
222
|
result: unknown,
|
|
223
223
|
options: { expanded?: boolean; isPartial?: boolean },
|
|
@@ -238,7 +238,7 @@ export default function pretty(pi: ExtensionAPI) {
|
|
|
238
238
|
};
|
|
239
239
|
case "ls":
|
|
240
240
|
return {
|
|
241
|
-
renderCall: (args: { path?: string }, theme: ThemeLike) => new Text(listCall(theme, args ?? {}), 0, 0),
|
|
241
|
+
renderCall: (args: { path?: string }, theme: ThemeLike) => new Text(listCall(theme, args ?? {}, settings.summaryClip), 0, 0),
|
|
242
242
|
renderResult: (
|
|
243
243
|
result: unknown,
|
|
244
244
|
options: { expanded?: boolean; isPartial?: boolean },
|
package/package.json
CHANGED
package/src/summary.ts
CHANGED
|
@@ -10,12 +10,32 @@ function title(theme: ThemeLike, name: string): string {
|
|
|
10
10
|
return theme.fg("toolTitle", theme.bold(name)) + " ";
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/** Default summary clip; overridable through settings (v0.3). */
|
|
14
|
+
export const DEFAULT_CLIP = 100;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Keep a one-line summary one line. A deeply nested path or a long command
|
|
18
|
+
* is clipped in the middle: the start says what it is, the end says which
|
|
19
|
+
* file, and the part nobody reads is what goes.
|
|
20
|
+
*/
|
|
21
|
+
export function clip(text: string, max: number = DEFAULT_CLIP): string {
|
|
22
|
+
if (max <= 0 || text.length <= max) return text;
|
|
23
|
+
if (max <= 4) return text.slice(0, max);
|
|
24
|
+
const head = Math.ceil((max - 1) / 2);
|
|
25
|
+
const tail = max - 1 - head;
|
|
26
|
+
return `${text.slice(0, head)}…${text.slice(text.length - tail)}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function readCall(
|
|
30
|
+
theme: ThemeLike,
|
|
31
|
+
args: { path?: string; offset?: number; limit?: number },
|
|
32
|
+
max: number = DEFAULT_CLIP,
|
|
33
|
+
): string {
|
|
14
34
|
const range =
|
|
15
35
|
args.offset || args.limit
|
|
16
36
|
? theme.fg("dim", ` · lines ${args.offset ?? 1}${args.limit ? `–${(args.offset ?? 1) + args.limit - 1}` : "+"}`)
|
|
17
37
|
: "";
|
|
18
|
-
return title(theme, "Read") + theme.fg("accent", args.path ?? "") + range;
|
|
38
|
+
return title(theme, "Read") + theme.fg("accent", clip(args.path ?? "", max)) + range;
|
|
19
39
|
}
|
|
20
40
|
|
|
21
41
|
export function readSummary(theme: ThemeLike, output: string, truncated: boolean, failed: boolean): string {
|
|
@@ -24,11 +44,19 @@ export function readSummary(theme: ThemeLike, output: string, truncated: boolean
|
|
|
24
44
|
return theme.fg("dim", `${lines} ${lines === 1 ? "line" : "lines"}${truncated ? " · truncated" : ""}`);
|
|
25
45
|
}
|
|
26
46
|
|
|
27
|
-
export function bashCall(
|
|
47
|
+
export function bashCall(
|
|
48
|
+
theme: ThemeLike,
|
|
49
|
+
command: string,
|
|
50
|
+
expanded: boolean,
|
|
51
|
+
max: number = DEFAULT_CLIP,
|
|
52
|
+
): string {
|
|
28
53
|
const lines = command.split(/\r\n|\r|\n/);
|
|
29
54
|
const head = lines[0] ?? "";
|
|
30
55
|
const omitted = lines.length - 1;
|
|
31
|
-
const shown =
|
|
56
|
+
const shown =
|
|
57
|
+
expanded || omitted === 0
|
|
58
|
+
? clip(command, expanded ? Number.MAX_SAFE_INTEGER : max)
|
|
59
|
+
: `${clip(head, max)} ${theme.fg("dim", `… (+${omitted} ${omitted === 1 ? "line" : "lines"})`)}`;
|
|
32
60
|
return title(theme, "Bash") + theme.fg("accent", shown);
|
|
33
61
|
}
|
|
34
62
|
|
|
@@ -41,27 +69,36 @@ export function bashSummary(theme: ThemeLike, output: string, failed: boolean):
|
|
|
41
69
|
return theme.fg("success", "✓") + theme.fg("dim", lines > 0 ? ` ${lines} output ${lines === 1 ? "line" : "lines"}` : " done");
|
|
42
70
|
}
|
|
43
71
|
|
|
44
|
-
export function editCall(theme: ThemeLike, args: { path?: string }): string {
|
|
45
|
-
return title(theme, "Edit") + theme.fg("accent", args.path ?? "");
|
|
72
|
+
export function editCall(theme: ThemeLike, args: { path?: string }, max: number = DEFAULT_CLIP): string {
|
|
73
|
+
return title(theme, "Edit") + theme.fg("accent", clip(args.path ?? "", max));
|
|
46
74
|
}
|
|
47
75
|
|
|
48
|
-
export function writeCall(
|
|
76
|
+
export function writeCall(
|
|
77
|
+
theme: ThemeLike,
|
|
78
|
+
args: { path?: string; content?: string },
|
|
79
|
+
max: number = DEFAULT_CLIP,
|
|
80
|
+
): string {
|
|
49
81
|
const lines = typeof args.content === "string" ? args.content.split("\n").length : 0;
|
|
50
|
-
return
|
|
82
|
+
return (
|
|
83
|
+
title(theme, "Write") +
|
|
84
|
+
theme.fg("accent", clip(args.path ?? "", max)) +
|
|
85
|
+
theme.fg("dim", ` · ${lines} ${lines === 1 ? "line" : "lines"}`)
|
|
86
|
+
);
|
|
51
87
|
}
|
|
52
88
|
|
|
53
89
|
export function searchCall(
|
|
54
90
|
theme: ThemeLike,
|
|
55
91
|
name: string,
|
|
56
92
|
args: { pattern?: string; path?: string; glob?: string },
|
|
93
|
+
max: number = DEFAULT_CLIP,
|
|
57
94
|
): string {
|
|
58
|
-
const pattern = args.pattern ?? args.glob ?? "";
|
|
59
|
-
const where = args.path ? theme.fg("dim", ` in ${args.path}`) : "";
|
|
95
|
+
const pattern = clip(args.pattern ?? args.glob ?? "", max);
|
|
96
|
+
const where = args.path ? theme.fg("dim", ` in ${clip(args.path, max)}`) : "";
|
|
60
97
|
return title(theme, name) + theme.fg("accent", pattern) + where;
|
|
61
98
|
}
|
|
62
99
|
|
|
63
|
-
export function listCall(theme: ThemeLike, args: { path?: string }): string {
|
|
64
|
-
return title(theme, "List") + theme.fg("accent", args.path ?? ".");
|
|
100
|
+
export function listCall(theme: ThemeLike, args: { path?: string }, max: number = DEFAULT_CLIP): string {
|
|
101
|
+
return title(theme, "List") + theme.fg("accent", clip(args.path ?? ".", max));
|
|
65
102
|
}
|
|
66
103
|
|
|
67
104
|
export function matchSummary(
|