@narumitw/pi-statusline 0.50.0 → 0.50.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 +29 -209
- package/dist/chunks/{chunk-74QZGJ7L.js → chunk-LARLXEUL.ts} +18 -97
- package/dist/chunks/chunk-LARLXEUL.ts.map +7 -0
- package/dist/chunks/{commands-C2G2G7C6.js → commands-KDWSOSZZ.ts} +14 -58
- package/dist/chunks/commands-KDWSOSZZ.ts.map +7 -0
- package/dist/index.ts +21 -76
- package/dist/index.ts.map +2 -2
- package/docs/configuration.md +194 -0
- package/package.json +51 -51
- package/src/ansi.ts +18 -24
- package/src/command-contract.ts +6 -6
- package/src/commands.ts +759 -818
- package/src/directory.ts +27 -31
- package/src/extension-status.ts +186 -219
- package/src/git-status.ts +103 -111
- package/src/information-profiles.ts +12 -31
- package/src/powerline.ts +120 -127
- package/src/presets/candy.ts +1 -7
- package/src/presets/create-ramp.ts +21 -23
- package/src/presets/custom.ts +7 -7
- package/src/presets/forest.ts +1 -7
- package/src/presets/index.ts +30 -32
- package/src/presets/mono.ts +1 -7
- package/src/presets/neon.ts +1 -7
- package/src/presets/ocean.ts +1 -7
- package/src/presets/sunset.ts +1 -7
- package/src/presets/tokyo-night.ts +9 -9
- package/src/presets/types.ts +5 -5
- package/src/render.ts +277 -306
- package/src/settings.ts +516 -568
- package/src/statusline.ts +347 -372
- package/src/types.ts +34 -42
- package/src/usage.ts +40 -40
- package/dist/chunks/chunk-74QZGJ7L.js.map +0 -7
- package/dist/chunks/commands-C2G2G7C6.js.map +0 -7
package/src/commands.ts
CHANGED
|
@@ -1,937 +1,878 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
DynamicBorder,
|
|
3
|
+
type ExtensionAPI,
|
|
4
|
+
type ExtensionCommandContext,
|
|
5
|
+
type KeybindingsManager,
|
|
6
6
|
} from "@earendil-works/pi-coding-agent";
|
|
7
|
-
import {
|
|
8
|
-
Container,
|
|
9
|
-
Key,
|
|
10
|
-
matchesKey,
|
|
11
|
-
Text,
|
|
12
|
-
truncateToWidth,
|
|
13
|
-
wrapTextWithAnsi,
|
|
14
|
-
} from "@earendil-works/pi-tui";
|
|
7
|
+
import { Container, Key, matchesKey, Text, truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
15
8
|
import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
|
|
16
9
|
import { completeStatuslineArguments } from "./command-contract.js";
|
|
17
10
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
INFORMATION_PROFILE_NAMES,
|
|
12
|
+
INFORMATION_PROFILES,
|
|
13
|
+
type InformationProfileName,
|
|
14
|
+
inferInformationProfile,
|
|
22
15
|
} from "./information-profiles.js";
|
|
23
16
|
import { segmentPaletteForPreset } from "./presets/index.js";
|
|
24
17
|
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
DEFAULT_STATUSLINE_DOCUMENT,
|
|
19
|
+
type LoadedStatuslineSettings,
|
|
20
|
+
removeStatuslineSettingsDocumentIfMatches,
|
|
21
|
+
saveStatuslineSettingsDocument,
|
|
29
22
|
} from "./settings.js";
|
|
30
23
|
import {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
type ConfigSegmentName,
|
|
25
|
+
LINE_BREAK_SEGMENT_NAME,
|
|
26
|
+
PALETTE_NAMES,
|
|
27
|
+
PALETTE_PRESET_NAMES,
|
|
28
|
+
type PaletteName,
|
|
29
|
+
type PalettePreset,
|
|
30
|
+
SEGMENT_NAMES,
|
|
31
|
+
type SegmentName,
|
|
39
32
|
} from "./types.js";
|
|
40
33
|
|
|
41
34
|
const EDIT_SETTINGS_LABEL = "Edit settings JSON";
|
|
42
35
|
const SEGMENT_VIEWPORT_SIZE = 6;
|
|
43
36
|
const NARROW_SEGMENT_VIEWPORT_SIZE = 3;
|
|
44
37
|
const SEGMENT_DESCRIPTIONS: Record<SegmentName, string> = {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
38
|
+
brand: "Pi brand mark",
|
|
39
|
+
provider: "Current model provider",
|
|
40
|
+
model: "Current model name",
|
|
41
|
+
thinking: "Current thinking level",
|
|
42
|
+
cwd: "Current working directory",
|
|
43
|
+
branch: "Git branch, status, and linked pull request",
|
|
44
|
+
tools: "Current tool and streaming activity",
|
|
45
|
+
context: "Current context-window usage",
|
|
46
|
+
tokens: "Session token totals",
|
|
47
|
+
cache: "Prompt-cache reads, writes, and latest hit rate",
|
|
48
|
+
cost: "Session cost",
|
|
49
|
+
time: "Current local time",
|
|
50
|
+
turn: "Current session turn count",
|
|
58
51
|
};
|
|
59
52
|
interface StatuslineMenuOwner {
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
signal: AbortSignal;
|
|
54
|
+
isCurrent(): boolean;
|
|
62
55
|
}
|
|
63
56
|
|
|
64
57
|
export interface StatuslineCommandOptions {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
settingsPath: string;
|
|
59
|
+
getLoaded(): LoadedStatuslineSettings;
|
|
60
|
+
apply(loaded: LoadedStatuslineSettings, ctx: ExtensionCommandContext): void;
|
|
61
|
+
preview?(palettePreset: PalettePreset | undefined, ctx: ExtensionCommandContext): void;
|
|
62
|
+
save?: (settingsPath: string, rawDocument: string) => LoadedStatuslineSettings;
|
|
63
|
+
getMenuOwner?(): StatuslineMenuOwner;
|
|
71
64
|
}
|
|
72
65
|
|
|
73
66
|
export function registerStatuslineCommand(pi: ExtensionAPI, options: StatuslineCommandOptions) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
pi.registerCommand("statusline", {
|
|
68
|
+
description: "Open or inspect the statusline settings",
|
|
69
|
+
getArgumentCompletions: completeStatuslineArguments,
|
|
70
|
+
handler: (args, ctx) => handleStatuslineCommand(args, ctx, options),
|
|
71
|
+
});
|
|
79
72
|
}
|
|
80
73
|
|
|
81
74
|
export async function handleStatuslineCommand(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
args: string,
|
|
76
|
+
ctx: ExtensionCommandContext,
|
|
77
|
+
options: StatuslineCommandOptions,
|
|
85
78
|
) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
79
|
+
const normalized = args.trim();
|
|
80
|
+
if (!normalized) {
|
|
81
|
+
await showMainMenu(ctx, options);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const tokens = normalized.split(/\s+/u);
|
|
86
|
+
const subcommand = tokens[0]?.toLowerCase() ?? "";
|
|
87
|
+
if (tokens.length > 1) {
|
|
88
|
+
if (canNotify(ctx)) {
|
|
89
|
+
ctx.ui.notify(`/statusline ${subcommand} does not accept trailing arguments.`, "warning");
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
switch (subcommand) {
|
|
95
|
+
case "settings":
|
|
96
|
+
await editSettings(ctx, options);
|
|
97
|
+
return;
|
|
98
|
+
case "status":
|
|
99
|
+
showStatus(ctx, options);
|
|
100
|
+
return;
|
|
101
|
+
case "help":
|
|
102
|
+
showHelp(ctx, options.settingsPath);
|
|
103
|
+
return;
|
|
104
|
+
default:
|
|
105
|
+
if (canNotify(ctx)) {
|
|
106
|
+
ctx.ui.notify(`Unknown /statusline subcommand: ${subcommand}`, "warning");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
116
109
|
}
|
|
117
110
|
|
|
118
111
|
async function showMainMenu(ctx: ExtensionCommandContext, options: StatuslineCommandOptions) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
112
|
+
if (ctx.mode !== "tui") {
|
|
113
|
+
if (ctx.hasUI) ctx.ui.notify("/statusline requires an interactive Pi UI in TUI mode.", "error");
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const fallbackController = new AbortController();
|
|
117
|
+
const owner = options.getMenuOwner?.() ?? {
|
|
118
|
+
signal: fallbackController.signal,
|
|
119
|
+
isCurrent: () => !fallbackController.signal.aborted,
|
|
120
|
+
};
|
|
121
|
+
const { defineMenu, runMenu } = await import("@narumitw/pi-tui-kit");
|
|
122
|
+
if (owner.signal.aborted || !owner.isCurrent()) return;
|
|
123
|
+
type Screen = "main" | "advanced" | "information";
|
|
124
|
+
type Action = "appearance" | "setInformation" | "layout" | "edit" | "status" | "help" | "back";
|
|
125
|
+
const menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({
|
|
126
|
+
start: "main",
|
|
127
|
+
screens: {
|
|
128
|
+
main: () => {
|
|
129
|
+
const config = options.getLoaded().config;
|
|
130
|
+
return {
|
|
131
|
+
kind: "actions",
|
|
132
|
+
title: "pi-statusline",
|
|
133
|
+
items: [
|
|
134
|
+
{
|
|
135
|
+
id: "appearance",
|
|
136
|
+
label: `Appearance (${config.palettePreset})`,
|
|
137
|
+
action: "appearance",
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: "information",
|
|
141
|
+
label: `Information (${inferInformationProfile(config.segments)})`,
|
|
142
|
+
to: "information",
|
|
143
|
+
},
|
|
144
|
+
{ id: "advanced", label: "Advanced", to: "advanced" },
|
|
145
|
+
{ id: "status", label: "Status", action: "status" },
|
|
146
|
+
{ id: "help", label: "Help", action: "help" },
|
|
147
|
+
],
|
|
148
|
+
hint: "close",
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
information: () => {
|
|
152
|
+
const current = inferInformationProfile(options.getLoaded().config.segments);
|
|
153
|
+
return {
|
|
154
|
+
kind: "choice",
|
|
155
|
+
title: "Information level",
|
|
156
|
+
lines: [`Current profile: ${current}`],
|
|
157
|
+
items: INFORMATION_PROFILE_NAMES.map((profile) => ({
|
|
158
|
+
id: profile,
|
|
159
|
+
label: `${profile[0]?.toUpperCase() ?? ""}${profile.slice(1)}`,
|
|
160
|
+
description: `${INFORMATION_PROFILES[profile].length} segments`,
|
|
161
|
+
details: [`Segments: ${INFORMATION_PROFILES[profile].join(" · ")}`],
|
|
162
|
+
})),
|
|
163
|
+
action: "setInformation",
|
|
164
|
+
currentItemId: current,
|
|
165
|
+
initialItemId: current === "custom" ? "balanced" : current,
|
|
166
|
+
hint: "close",
|
|
167
|
+
};
|
|
168
|
+
},
|
|
169
|
+
advanced: () => {
|
|
170
|
+
const config = options.getLoaded().config;
|
|
171
|
+
const visibleSegmentCount = config.segments.filter(
|
|
172
|
+
(segment): segment is SegmentName => segment !== LINE_BREAK_SEGMENT_NAME,
|
|
173
|
+
).length;
|
|
174
|
+
return {
|
|
175
|
+
kind: "actions",
|
|
176
|
+
title: "pi-statusline — Advanced",
|
|
177
|
+
items: [
|
|
178
|
+
{
|
|
179
|
+
id: "layout",
|
|
180
|
+
label: `Custom layout (${visibleSegmentCount}/${SEGMENT_NAMES.length} shown)`,
|
|
181
|
+
action: "layout",
|
|
182
|
+
},
|
|
183
|
+
{ id: "edit", label: EDIT_SETTINGS_LABEL, action: "edit" },
|
|
184
|
+
{ id: "back", label: "Back", action: "back" },
|
|
185
|
+
],
|
|
186
|
+
hint: "back",
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
actions: {
|
|
191
|
+
appearance: async () => {
|
|
192
|
+
await choosePalettePreset(ctx, options, owner);
|
|
193
|
+
return { kind: "close" };
|
|
194
|
+
},
|
|
195
|
+
setInformation: async ({ itemId }) => {
|
|
196
|
+
const profile = INFORMATION_PROFILE_NAMES.find((candidate) => candidate === itemId);
|
|
197
|
+
if (!profile) return { kind: "rejected" };
|
|
198
|
+
applyInformationProfile(ctx, options, profile);
|
|
199
|
+
return { kind: "close" };
|
|
200
|
+
},
|
|
201
|
+
layout: async () => {
|
|
202
|
+
await chooseSegments(ctx, options);
|
|
203
|
+
return { kind: "close" };
|
|
204
|
+
},
|
|
205
|
+
edit: async () => {
|
|
206
|
+
await editSettings(ctx, options);
|
|
207
|
+
return { kind: "close" };
|
|
208
|
+
},
|
|
209
|
+
status: async () => {
|
|
210
|
+
showStatus(ctx, options);
|
|
211
|
+
return { kind: "close" };
|
|
212
|
+
},
|
|
213
|
+
help: async () => {
|
|
214
|
+
showHelp(ctx, options.settingsPath);
|
|
215
|
+
return { kind: "close" };
|
|
216
|
+
},
|
|
217
|
+
back: async () => ({ kind: "back" }),
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
try {
|
|
221
|
+
await runMenu(ctx, menu, {
|
|
222
|
+
getState: () => undefined,
|
|
223
|
+
signal: owner.signal,
|
|
224
|
+
isCurrent: owner.isCurrent,
|
|
225
|
+
});
|
|
226
|
+
} finally {
|
|
227
|
+
fallbackController.abort(new DOMException("Statusline menu closed", "AbortError"));
|
|
228
|
+
}
|
|
236
229
|
}
|
|
237
230
|
|
|
238
231
|
async function choosePalettePreset(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
232
|
+
ctx: ExtensionCommandContext,
|
|
233
|
+
options: StatuslineCommandOptions,
|
|
234
|
+
owner: StatuslineMenuOwner,
|
|
242
235
|
) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
236
|
+
if (ctx.mode !== "tui") {
|
|
237
|
+
if (ctx.hasUI) ctx.ui.notify(`Edit palettePreset manually: ${options.settingsPath}`, "info");
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const current = options.getLoaded();
|
|
241
|
+
let selection: PalettePreset | undefined;
|
|
242
|
+
try {
|
|
243
|
+
selection = await showPalettePresetPicker(ctx, current.config.palettePreset, options, owner);
|
|
244
|
+
} finally {
|
|
245
|
+
if (!owner.signal.aborted && owner.isCurrent()) {
|
|
246
|
+
try {
|
|
247
|
+
options.preview?.(undefined, ctx);
|
|
248
|
+
} catch (error) {
|
|
249
|
+
if (canNotify(ctx)) {
|
|
250
|
+
ctx.ui.notify(`Palette preview could not be reset: ${formatError(error)}`, "error");
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (owner.signal.aborted || !owner.isCurrent()) return;
|
|
256
|
+
if (selection === undefined) return;
|
|
257
|
+
|
|
258
|
+
let loaded: LoadedStatuslineSettings;
|
|
259
|
+
try {
|
|
260
|
+
const rawDocument = palettePresetDocument(current, selection);
|
|
261
|
+
loaded = (options.save ?? saveStatuslineSettingsDocument)(options.settingsPath, rawDocument);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
ctx.ui.notify(`Palette preset was not saved: ${formatError(error)}`, "error");
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
options.apply(loaded, ctx);
|
|
268
|
+
} catch (error) {
|
|
269
|
+
const rollbackError = restoreStatuslineSettings(ctx, options, current, loaded);
|
|
270
|
+
ctx.ui.notify(
|
|
271
|
+
rollbackError
|
|
272
|
+
? `Palette preset could not be applied: ${formatError(error)}; rollback failed: ${formatError(rollbackError)}`
|
|
273
|
+
: `Palette preset could not be applied: ${formatError(error)}; previous settings restored.`,
|
|
274
|
+
"error",
|
|
275
|
+
);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const message =
|
|
279
|
+
loaded.config.palettePreset === "custom"
|
|
280
|
+
? "Custom palette applied. Edit colors via /statusline → Advanced → Edit settings JSON."
|
|
281
|
+
: `Palette preset applied: ${loaded.config.palettePreset}.`;
|
|
282
|
+
ctx.ui.notify(message, "info");
|
|
290
283
|
}
|
|
291
284
|
|
|
292
285
|
async function showPalettePresetPicker(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
286
|
+
ctx: ExtensionCommandContext,
|
|
287
|
+
current: PalettePreset,
|
|
288
|
+
options: StatuslineCommandOptions,
|
|
289
|
+
owner: StatuslineMenuOwner,
|
|
297
290
|
): Promise<PalettePreset | undefined> {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
291
|
+
const { runLiveChoice } = await import("@narumitw/pi-tui-kit");
|
|
292
|
+
const result = await runLiveChoice(ctx, {
|
|
293
|
+
title: `Palette preset (current: ${current})`,
|
|
294
|
+
items: PALETTE_PRESET_NAMES.map((palettePreset) => ({
|
|
295
|
+
id: palettePreset,
|
|
296
|
+
label: palettePreset,
|
|
297
|
+
description: palettePreset === "custom" ? "per-segment colors from settings JSON" : undefined,
|
|
298
|
+
})),
|
|
299
|
+
currentItemId: current,
|
|
300
|
+
initialItemId: current,
|
|
301
|
+
viewportSize: Math.min(PALETTE_PRESET_NAMES.length, 10),
|
|
302
|
+
hint: "close",
|
|
303
|
+
navigationLabel: "preview",
|
|
304
|
+
confirmLabel: "apply",
|
|
305
|
+
onSelectionChange: ({ item }) => options.preview?.(item.id, ctx),
|
|
306
|
+
signal: owner.signal,
|
|
307
|
+
isCurrent: owner.isCurrent,
|
|
308
|
+
});
|
|
309
|
+
return result.kind === "selected" ? result.itemId : undefined;
|
|
317
310
|
}
|
|
318
311
|
|
|
319
312
|
function applyInformationProfile(
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
313
|
+
ctx: ExtensionCommandContext,
|
|
314
|
+
options: StatuslineCommandOptions,
|
|
315
|
+
selection: InformationProfileName,
|
|
323
316
|
) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
} catch (error) {
|
|
333
|
-
ctx.ui.notify(`Information level was not saved: ${formatError(error)}`, "error");
|
|
334
|
-
}
|
|
317
|
+
const current = options.getLoaded();
|
|
318
|
+
try {
|
|
319
|
+
const change = informationProfileDocument(current, selection);
|
|
320
|
+
const loaded = applySegmentsDocumentChange(change, ctx, options);
|
|
321
|
+
ctx.ui.notify(`Information level applied: ${inferInformationProfile(loaded.config.segments)}.`, "info");
|
|
322
|
+
} catch (error) {
|
|
323
|
+
ctx.ui.notify(`Information level was not saved: ${formatError(error)}`, "error");
|
|
324
|
+
}
|
|
335
325
|
}
|
|
336
326
|
|
|
337
327
|
async function chooseSegments(ctx: ExtensionCommandContext, options: StatuslineCommandOptions) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
moveSelection(SEGMENT_VIEWPORT_SIZE);
|
|
544
|
-
} else if (moveModeKey) {
|
|
545
|
-
enterMoveMode();
|
|
546
|
-
} else if (lineBreakKey) {
|
|
547
|
-
toggleLineBreakAfterSelected();
|
|
548
|
-
} else if (keybindings.matches(data, "tui.select.confirm") || data === " ") {
|
|
549
|
-
toggleSelected();
|
|
550
|
-
} else if (keybindings.matches(data, "tui.select.cancel")) {
|
|
551
|
-
done(undefined);
|
|
552
|
-
}
|
|
553
|
-
tui.requestRender();
|
|
554
|
-
},
|
|
555
|
-
};
|
|
556
|
-
});
|
|
328
|
+
if (ctx.mode !== "tui") {
|
|
329
|
+
if (ctx.hasUI) ctx.ui.notify(`Edit segments manually: ${options.settingsPath}`, "info");
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
let current = options.getLoaded();
|
|
333
|
+
let names = segmentMenuOrder(current);
|
|
334
|
+
let selectedIndex = 0;
|
|
335
|
+
let moveMode = false;
|
|
336
|
+
let feedback: string | undefined;
|
|
337
|
+
|
|
338
|
+
await ctx.ui.custom((tui, theme, keybindings, done) => {
|
|
339
|
+
const commit = (name: SegmentName, change: { nextDocument: string; previousDocument: string }): boolean => {
|
|
340
|
+
try {
|
|
341
|
+
current = applySegmentsDocumentChange(change, ctx, options);
|
|
342
|
+
names = segmentMenuOrder(current);
|
|
343
|
+
selectedIndex = Math.max(0, names.indexOf(name));
|
|
344
|
+
feedback = undefined;
|
|
345
|
+
return true;
|
|
346
|
+
} catch (error) {
|
|
347
|
+
ctx.ui.notify(`Statusline segments were not saved: ${formatError(error)}`, "error");
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
const toggleSelected = () => {
|
|
353
|
+
const name = names[selectedIndex];
|
|
354
|
+
if (!name) return;
|
|
355
|
+
moveMode = false;
|
|
356
|
+
commit(name, segmentsDocument(current, name, !current.config.segments.includes(name)));
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const toggleLineBreakAfterSelected = () => {
|
|
360
|
+
const name = names[selectedIndex];
|
|
361
|
+
if (!name) return;
|
|
362
|
+
moveMode = false;
|
|
363
|
+
const segmentIndex = current.config.segments.indexOf(name);
|
|
364
|
+
if (segmentIndex < 0) {
|
|
365
|
+
feedback = `Show ${name} before adding a line break.`;
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const hasLineBreak = current.config.segments[segmentIndex + 1] === LINE_BREAK_SEGMENT_NAME;
|
|
369
|
+
const hasFollowingSegment = current.config.segments
|
|
370
|
+
.slice(segmentIndex + 1)
|
|
371
|
+
.some((segment) => segment !== LINE_BREAK_SEGMENT_NAME);
|
|
372
|
+
if (!hasLineBreak && !hasFollowingSegment) {
|
|
373
|
+
feedback = `Add another visible segment after ${name} before adding a line break.`;
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
commit(name, lineBreakAfterDocument(current, name));
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
const reorderSelected = (direction: -1 | 1) => {
|
|
380
|
+
const name = names[selectedIndex];
|
|
381
|
+
if (!name) return;
|
|
382
|
+
const visibleNames = visibleSegmentNames(current);
|
|
383
|
+
const currentIndex = visibleNames.indexOf(name);
|
|
384
|
+
if (currentIndex < 0) {
|
|
385
|
+
feedback = `Show ${name} before moving it.`;
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const targetIndex = currentIndex + direction;
|
|
389
|
+
if (targetIndex < 0 || targetIndex >= visibleNames.length) {
|
|
390
|
+
feedback = `${name} is already the ${direction < 0 ? "first" : "last"} visible segment.`;
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const change = reorderedSegmentsDocument(current, name, direction);
|
|
394
|
+
if (change) commit(name, change);
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
const enterMoveMode = () => {
|
|
398
|
+
const name = names[selectedIndex];
|
|
399
|
+
if (!name) return;
|
|
400
|
+
if (!current.config.segments.includes(name)) {
|
|
401
|
+
feedback = `Show ${name} before moving it.`;
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
moveMode = true;
|
|
405
|
+
feedback = undefined;
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
const moveSelection = (offset: number) => {
|
|
409
|
+
selectedIndex = Math.max(0, Math.min(names.length - 1, selectedIndex + offset));
|
|
410
|
+
feedback = undefined;
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
const renderList = (width: number): string[] => {
|
|
414
|
+
const safeWidth = Math.max(1, width);
|
|
415
|
+
const visibleNames = visibleSegmentNames(current);
|
|
416
|
+
const visible = new Set(visibleNames);
|
|
417
|
+
const placements = segmentPlacements(current.config.segments);
|
|
418
|
+
const viewportSize = safeWidth < 30 ? NARROW_SEGMENT_VIEWPORT_SIZE : SEGMENT_VIEWPORT_SIZE;
|
|
419
|
+
const startIndex = Math.max(
|
|
420
|
+
0,
|
|
421
|
+
Math.min(selectedIndex - Math.floor(viewportSize / 2), Math.max(0, names.length - viewportSize)),
|
|
422
|
+
);
|
|
423
|
+
const endIndex = Math.min(names.length, startIndex + viewportSize);
|
|
424
|
+
const lines: string[] = [];
|
|
425
|
+
let previousSection: "visible" | "hidden" | undefined;
|
|
426
|
+
for (let index = startIndex; index < endIndex; index += 1) {
|
|
427
|
+
const name = names[index];
|
|
428
|
+
if (!name) continue;
|
|
429
|
+
const section = visible.has(name) ? "visible" : "hidden";
|
|
430
|
+
if (section !== previousSection) {
|
|
431
|
+
const heading = section === "visible" ? "Visible — render order" : "Hidden — not rendered";
|
|
432
|
+
lines.push(theme.fg("muted", theme.bold(truncateToWidth(` ${heading}`, safeWidth))));
|
|
433
|
+
previousSection = section;
|
|
434
|
+
}
|
|
435
|
+
const isSelected = index === selectedIndex;
|
|
436
|
+
const prefix = isSelected ? "→ " : " ";
|
|
437
|
+
const placement = placements.get(name);
|
|
438
|
+
const lineBreakLabel = hasLineBreakAfter(current.config.segments, name) ? " · break after" : "";
|
|
439
|
+
const row = placement
|
|
440
|
+
? `${prefix}${`${placement.order}.`.padStart(3)} row ${placement.row} · ${name.padEnd(8)} · visible${lineBreakLabel}`
|
|
441
|
+
: `${prefix} · ${name.padEnd(8)} · hidden`;
|
|
442
|
+
const truncated = truncateToWidth(row, safeWidth);
|
|
443
|
+
if (isSelected) lines.push(theme.fg("accent", truncated));
|
|
444
|
+
else lines.push(section === "visible" ? truncated : theme.fg("muted", truncated));
|
|
445
|
+
}
|
|
446
|
+
if (startIndex > 0 || endIndex < names.length) {
|
|
447
|
+
lines.push(theme.fg("dim", truncateToWidth(` (${startIndex + 1}-${endIndex}/${names.length})`, safeWidth)));
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const selected = names[selectedIndex];
|
|
451
|
+
if (selected) {
|
|
452
|
+
lines.push("");
|
|
453
|
+
const detail = feedback ?? SEGMENT_DESCRIPTIONS[selected];
|
|
454
|
+
const color = feedback ? "warning" : "muted";
|
|
455
|
+
for (const line of wrapTextWithAnsi(detail, Math.max(1, safeWidth - 2))) {
|
|
456
|
+
lines.push(theme.fg(color, truncateToWidth(` ${line}`, safeWidth)));
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
lines.push("");
|
|
461
|
+
const hints = segmentControlHints(safeWidth, moveMode, selected, keybindings);
|
|
462
|
+
for (const hint of hints) {
|
|
463
|
+
lines.push(theme.fg("dim", truncateToWidth(` ${hint}`, safeWidth)));
|
|
464
|
+
}
|
|
465
|
+
return lines;
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
const container = new Container();
|
|
469
|
+
container.addChild(new DynamicBorder((text: string) => theme.fg("accent", text)));
|
|
470
|
+
const title = new Text("", 1, 0);
|
|
471
|
+
container.addChild(title);
|
|
472
|
+
container.addChild({ render: renderList, invalidate() {} });
|
|
473
|
+
container.addChild(new DynamicBorder((text: string) => theme.fg("accent", text)));
|
|
474
|
+
const updateThemedText = () => {
|
|
475
|
+
title.setText(theme.fg("accent", theme.bold("Statusline segments")));
|
|
476
|
+
};
|
|
477
|
+
updateThemedText();
|
|
478
|
+
|
|
479
|
+
return {
|
|
480
|
+
render: (width: number) => container.render(width),
|
|
481
|
+
invalidate() {
|
|
482
|
+
container.invalidate();
|
|
483
|
+
updateThemedText();
|
|
484
|
+
},
|
|
485
|
+
handleInput(data: string) {
|
|
486
|
+
if (matchesKey(data, Key.ctrl("c"))) {
|
|
487
|
+
done(undefined);
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
const moveModeKey = matchesKey(data, "m") || matchesKey(data, Key.shift("m"));
|
|
491
|
+
const lineBreakKey = matchesKey(data, "b") || matchesKey(data, Key.shift("b"));
|
|
492
|
+
if (matchesKey(data, Key.alt("up"))) {
|
|
493
|
+
reorderSelected(-1);
|
|
494
|
+
} else if (matchesKey(data, Key.alt("down"))) {
|
|
495
|
+
reorderSelected(1);
|
|
496
|
+
} else if (moveMode) {
|
|
497
|
+
if (keybindings.matches(data, "tui.select.up")) {
|
|
498
|
+
reorderSelected(-1);
|
|
499
|
+
} else if (keybindings.matches(data, "tui.select.down")) {
|
|
500
|
+
reorderSelected(1);
|
|
501
|
+
} else if (
|
|
502
|
+
moveModeKey ||
|
|
503
|
+
keybindings.matches(data, "tui.select.confirm") ||
|
|
504
|
+
data === " " ||
|
|
505
|
+
keybindings.matches(data, "tui.select.cancel")
|
|
506
|
+
) {
|
|
507
|
+
moveMode = false;
|
|
508
|
+
feedback = undefined;
|
|
509
|
+
}
|
|
510
|
+
} else if (keybindings.matches(data, "tui.select.up")) {
|
|
511
|
+
selectedIndex = selectedIndex === 0 ? names.length - 1 : selectedIndex - 1;
|
|
512
|
+
feedback = undefined;
|
|
513
|
+
} else if (keybindings.matches(data, "tui.select.down")) {
|
|
514
|
+
selectedIndex = selectedIndex === names.length - 1 ? 0 : selectedIndex + 1;
|
|
515
|
+
feedback = undefined;
|
|
516
|
+
} else if (keybindings.matches(data, "tui.select.pageUp")) {
|
|
517
|
+
moveSelection(-SEGMENT_VIEWPORT_SIZE);
|
|
518
|
+
} else if (keybindings.matches(data, "tui.select.pageDown")) {
|
|
519
|
+
moveSelection(SEGMENT_VIEWPORT_SIZE);
|
|
520
|
+
} else if (moveModeKey) {
|
|
521
|
+
enterMoveMode();
|
|
522
|
+
} else if (lineBreakKey) {
|
|
523
|
+
toggleLineBreakAfterSelected();
|
|
524
|
+
} else if (keybindings.matches(data, "tui.select.confirm") || data === " ") {
|
|
525
|
+
toggleSelected();
|
|
526
|
+
} else if (keybindings.matches(data, "tui.select.cancel")) {
|
|
527
|
+
done(undefined);
|
|
528
|
+
}
|
|
529
|
+
tui.requestRender();
|
|
530
|
+
},
|
|
531
|
+
};
|
|
532
|
+
});
|
|
557
533
|
}
|
|
558
534
|
|
|
559
535
|
async function editSettings(ctx: ExtensionCommandContext, options: StatuslineCommandOptions) {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
536
|
+
if (ctx.mode !== "tui") {
|
|
537
|
+
if (ctx.hasUI) ctx.ui.notify(`Edit settings manually: ${options.settingsPath}`, "info");
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
const current = options.getLoaded();
|
|
541
|
+
const edited = await ctx.ui.editor(
|
|
542
|
+
"pi-statusline.json — save and close to apply",
|
|
543
|
+
current.rawDocument ?? DEFAULT_STATUSLINE_DOCUMENT,
|
|
544
|
+
);
|
|
545
|
+
if (edited === undefined) return;
|
|
546
|
+
let loaded: LoadedStatuslineSettings;
|
|
547
|
+
try {
|
|
548
|
+
loaded = (options.save ?? saveStatuslineSettingsDocument)(options.settingsPath, edited);
|
|
549
|
+
} catch (error) {
|
|
550
|
+
ctx.ui.notify(`pi-statusline settings were not saved: ${formatError(error)}`, "error");
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
try {
|
|
554
|
+
options.apply(loaded, ctx);
|
|
555
|
+
} catch (error) {
|
|
556
|
+
const rollbackError = restoreStatuslineSettings(ctx, options, current, loaded);
|
|
557
|
+
ctx.ui.notify(
|
|
558
|
+
rollbackError
|
|
559
|
+
? `pi-statusline settings could not be applied: ${formatError(error)}; rollback failed: ${formatError(rollbackError)}`
|
|
560
|
+
: `pi-statusline settings could not be applied: ${formatError(error)}; previous settings restored.`,
|
|
561
|
+
"error",
|
|
562
|
+
);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
const suffix =
|
|
566
|
+
loaded.diagnostics.length > 0
|
|
567
|
+
? ` (${loaded.diagnostics.length} warning${loaded.diagnostics.length === 1 ? "" : "s"})`
|
|
568
|
+
: "";
|
|
569
|
+
ctx.ui.notify(`pi-statusline settings saved and applied${suffix}.`, "info");
|
|
594
570
|
}
|
|
595
571
|
|
|
596
|
-
function palettePresetDocument(
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
):
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
} else if (palettePreset !== "custom" && typeof parsed.palette === "string") {
|
|
607
|
-
delete parsed.palette;
|
|
608
|
-
}
|
|
609
|
-
parsed.palettePreset = palettePreset;
|
|
610
|
-
return `${JSON.stringify(parsed, null, "\t")}\n`;
|
|
572
|
+
function palettePresetDocument(current: LoadedStatuslineSettings, palettePreset: PalettePreset): string {
|
|
573
|
+
const { parsed } = editableSettings(current, "choosing a palette preset");
|
|
574
|
+
if (palettePreset === "custom" && !isRecord(parsed.palette)) {
|
|
575
|
+
const seedPreset = isPaletteName(current.config.palettePreset) ? current.config.palettePreset : "tokyo-night";
|
|
576
|
+
parsed.palette = segmentPaletteForPreset(seedPreset);
|
|
577
|
+
} else if (palettePreset !== "custom" && typeof parsed.palette === "string") {
|
|
578
|
+
delete parsed.palette;
|
|
579
|
+
}
|
|
580
|
+
parsed.palettePreset = palettePreset;
|
|
581
|
+
return `${JSON.stringify(parsed, null, "\t")}\n`;
|
|
611
582
|
}
|
|
612
583
|
|
|
613
584
|
function informationProfileDocument(
|
|
614
|
-
|
|
615
|
-
|
|
585
|
+
current: LoadedStatuslineSettings,
|
|
586
|
+
profile: InformationProfileName,
|
|
616
587
|
): { nextDocument: string; previousDocument: string } {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
nextDocument: `${JSON.stringify(parsed, null, "\t")}\n`,
|
|
624
|
-
previousDocument,
|
|
625
|
-
};
|
|
588
|
+
const { parsed, rawDocument: previousDocument } = editableSettings(current, "changing information level");
|
|
589
|
+
parsed.segments = [...INFORMATION_PROFILES[profile]];
|
|
590
|
+
return {
|
|
591
|
+
nextDocument: `${JSON.stringify(parsed, null, "\t")}\n`,
|
|
592
|
+
previousDocument,
|
|
593
|
+
};
|
|
626
594
|
}
|
|
627
595
|
|
|
628
596
|
function visibleSegmentNames(current: LoadedStatuslineSettings): SegmentName[] {
|
|
629
|
-
|
|
630
|
-
(segment): segment is SegmentName => segment !== LINE_BREAK_SEGMENT_NAME,
|
|
631
|
-
);
|
|
597
|
+
return current.config.segments.filter((segment): segment is SegmentName => segment !== LINE_BREAK_SEGMENT_NAME);
|
|
632
598
|
}
|
|
633
599
|
|
|
634
600
|
function segmentMenuOrder(current: LoadedStatuslineSettings): SegmentName[] {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
601
|
+
const visible = visibleSegmentNames(current);
|
|
602
|
+
const visibleSet = new Set(visible);
|
|
603
|
+
return [...visible, ...SEGMENT_NAMES.filter((name) => !visibleSet.has(name))];
|
|
638
604
|
}
|
|
639
605
|
|
|
640
606
|
function hasLineBreakAfter(segments: readonly ConfigSegmentName[], name: SegmentName): boolean {
|
|
641
|
-
|
|
642
|
-
|
|
607
|
+
const index = segments.indexOf(name);
|
|
608
|
+
return index >= 0 && segments[index + 1] === LINE_BREAK_SEGMENT_NAME;
|
|
643
609
|
}
|
|
644
610
|
|
|
645
|
-
function segmentPlacements(
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
}
|
|
658
|
-
return placements;
|
|
611
|
+
function segmentPlacements(segments: readonly ConfigSegmentName[]): Map<SegmentName, { order: number; row: number }> {
|
|
612
|
+
const placements = new Map<SegmentName, { order: number; row: number }>();
|
|
613
|
+
let order = 0;
|
|
614
|
+
let row = 1;
|
|
615
|
+
for (const segment of segments) {
|
|
616
|
+
if (segment === LINE_BREAK_SEGMENT_NAME) {
|
|
617
|
+
row += 1;
|
|
618
|
+
continue;
|
|
619
|
+
}
|
|
620
|
+
placements.set(segment, { order: ++order, row });
|
|
621
|
+
}
|
|
622
|
+
return placements;
|
|
659
623
|
}
|
|
660
624
|
|
|
661
625
|
function segmentControlHints(
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
626
|
+
width: number,
|
|
627
|
+
moveMode: boolean,
|
|
628
|
+
selected: SegmentName | undefined,
|
|
629
|
+
keybindings: Pick<KeybindingsManager, "getKeys">,
|
|
666
630
|
): string[] {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
`${closeKeys} close`,
|
|
699
|
-
]
|
|
700
|
-
: [
|
|
701
|
-
"↑↓ navigate · Enter/Space show/hide · M move mode",
|
|
702
|
-
`B add/remove line break after · Alt+↑/↓ quick move · ${closeKeys} close`,
|
|
703
|
-
];
|
|
631
|
+
const configuredCancel = [
|
|
632
|
+
...new Set(
|
|
633
|
+
keybindings
|
|
634
|
+
.getKeys("tui.select.cancel")
|
|
635
|
+
.filter((key) => key !== "ctrl+c")
|
|
636
|
+
.map(displayKey)
|
|
637
|
+
.filter(Boolean),
|
|
638
|
+
),
|
|
639
|
+
];
|
|
640
|
+
const closeKeys = [...new Set([...configuredCancel, "Ctrl+C"])].join("/");
|
|
641
|
+
if (moveMode) {
|
|
642
|
+
const cancellation = [
|
|
643
|
+
...(configuredCancel.length > 0 ? [`${configuredCancel.join("/")} leave move mode`] : []),
|
|
644
|
+
"Ctrl+C close",
|
|
645
|
+
].join(" · ");
|
|
646
|
+
return width < 30
|
|
647
|
+
? [
|
|
648
|
+
`Move mode: ${selected ?? "segment"}`,
|
|
649
|
+
"↑↓ move segment",
|
|
650
|
+
"Enter/Space finish",
|
|
651
|
+
...(configuredCancel.length > 0 ? [`${configuredCancel.join("/")} leave move mode`] : []),
|
|
652
|
+
"Ctrl+C close",
|
|
653
|
+
]
|
|
654
|
+
: [`Move mode — ${selected ?? "segment"}`, "↑↓ move · Enter/Space finish", cancellation];
|
|
655
|
+
}
|
|
656
|
+
return width < 30
|
|
657
|
+
? ["↑↓ navigate", "Enter/Space toggle", "M move · B line break", "Alt+↑/↓ quick move", `${closeKeys} close`]
|
|
658
|
+
: [
|
|
659
|
+
"↑↓ navigate · Enter/Space show/hide · M move mode",
|
|
660
|
+
`B add/remove line break after · Alt+↑/↓ quick move · ${closeKeys} close`,
|
|
661
|
+
];
|
|
704
662
|
}
|
|
705
663
|
|
|
706
664
|
function displayKey(key: string): string {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
665
|
+
return sanitizeTerminalText(key)
|
|
666
|
+
.split("+")
|
|
667
|
+
.map((part) => {
|
|
668
|
+
if (part === "escape") return "Esc";
|
|
669
|
+
if (part === "ctrl") return "Ctrl";
|
|
670
|
+
if (part === "alt") return process.platform === "darwin" ? "Option" : "Alt";
|
|
671
|
+
if (part === "shift") return "Shift";
|
|
672
|
+
return part;
|
|
673
|
+
})
|
|
674
|
+
.join("+");
|
|
717
675
|
}
|
|
718
676
|
|
|
719
677
|
function segmentsDocument(
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
678
|
+
current: LoadedStatuslineSettings,
|
|
679
|
+
name: SegmentName,
|
|
680
|
+
shouldShow: boolean,
|
|
723
681
|
): { nextDocument: string; previousDocument: string } {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
682
|
+
const { parsed, rawDocument: previousDocument } = editableSettings(current, "changing segments");
|
|
683
|
+
const segments = shouldShow
|
|
684
|
+
? [...current.config.segments, ...(current.config.segments.includes(name) ? [] : [name])]
|
|
685
|
+
: current.config.segments.filter((segment) => segment !== name);
|
|
686
|
+
parsed.segments = normalizeLineBreaks(segments);
|
|
687
|
+
return {
|
|
688
|
+
nextDocument: `${JSON.stringify(parsed, null, "\t")}\n`,
|
|
689
|
+
previousDocument,
|
|
690
|
+
};
|
|
733
691
|
}
|
|
734
692
|
|
|
735
693
|
function lineBreakAfterDocument(
|
|
736
|
-
|
|
737
|
-
|
|
694
|
+
current: LoadedStatuslineSettings,
|
|
695
|
+
name: SegmentName,
|
|
738
696
|
): { nextDocument: string; previousDocument: string } {
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
nextDocument: `${JSON.stringify(parsed, null, "\t")}\n`,
|
|
753
|
-
previousDocument,
|
|
754
|
-
};
|
|
697
|
+
const { parsed, rawDocument: previousDocument } = editableSettings(current, "changing line breaks");
|
|
698
|
+
const segments = [...current.config.segments];
|
|
699
|
+
const segmentIndex = segments.indexOf(name);
|
|
700
|
+
if (segments[segmentIndex + 1] === LINE_BREAK_SEGMENT_NAME) {
|
|
701
|
+
segments.splice(segmentIndex + 1, 1);
|
|
702
|
+
} else {
|
|
703
|
+
segments.splice(segmentIndex + 1, 0, LINE_BREAK_SEGMENT_NAME);
|
|
704
|
+
}
|
|
705
|
+
parsed.segments = segments;
|
|
706
|
+
return {
|
|
707
|
+
nextDocument: `${JSON.stringify(parsed, null, "\t")}\n`,
|
|
708
|
+
previousDocument,
|
|
709
|
+
};
|
|
755
710
|
}
|
|
756
711
|
|
|
757
712
|
function reorderedSegmentsDocument(
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
713
|
+
current: LoadedStatuslineSettings,
|
|
714
|
+
name: SegmentName,
|
|
715
|
+
direction: -1 | 1,
|
|
761
716
|
): { nextDocument: string; previousDocument: string } | undefined {
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
parsed.segments = segments;
|
|
782
|
-
return {
|
|
783
|
-
nextDocument: `${JSON.stringify(parsed, null, "\t")}\n`,
|
|
784
|
-
previousDocument,
|
|
785
|
-
};
|
|
717
|
+
const dataIndexes = current.config.segments.flatMap((segment, index) =>
|
|
718
|
+
segment === LINE_BREAK_SEGMENT_NAME ? [] : [index],
|
|
719
|
+
);
|
|
720
|
+
const currentDataIndex = dataIndexes.findIndex((index) => current.config.segments[index] === name);
|
|
721
|
+
const targetDataIndex = currentDataIndex + direction;
|
|
722
|
+
if (currentDataIndex < 0 || targetDataIndex < 0 || targetDataIndex >= dataIndexes.length) {
|
|
723
|
+
return undefined;
|
|
724
|
+
}
|
|
725
|
+
const { parsed, rawDocument: previousDocument } = editableSettings(current, "reordering segments");
|
|
726
|
+
const segments = [...current.config.segments];
|
|
727
|
+
const currentIndex = dataIndexes[currentDataIndex];
|
|
728
|
+
const targetIndex = dataIndexes[targetDataIndex];
|
|
729
|
+
if (currentIndex === undefined || targetIndex === undefined) return undefined;
|
|
730
|
+
[segments[currentIndex], segments[targetIndex]] = [segments[targetIndex], segments[currentIndex]];
|
|
731
|
+
parsed.segments = segments;
|
|
732
|
+
return {
|
|
733
|
+
nextDocument: `${JSON.stringify(parsed, null, "\t")}\n`,
|
|
734
|
+
previousDocument,
|
|
735
|
+
};
|
|
786
736
|
}
|
|
787
737
|
|
|
788
738
|
function applySegmentsDocumentChange(
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
739
|
+
change: { nextDocument: string; previousDocument: string },
|
|
740
|
+
ctx: ExtensionCommandContext,
|
|
741
|
+
options: StatuslineCommandOptions,
|
|
792
742
|
): LoadedStatuslineSettings {
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
743
|
+
const previous = options.getLoaded();
|
|
744
|
+
const save = options.save ?? saveStatuslineSettingsDocument;
|
|
745
|
+
const next = save(options.settingsPath, change.nextDocument);
|
|
746
|
+
try {
|
|
747
|
+
options.apply(next, ctx);
|
|
748
|
+
} catch (applyError) {
|
|
749
|
+
const rollbackError = restoreStatuslineSettings(ctx, options, previous, next);
|
|
750
|
+
if (rollbackError) {
|
|
751
|
+
throw new Error(
|
|
752
|
+
`runtime update failed: ${formatError(applyError)}; rollback failed: ${formatError(rollbackError)}`,
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
throw applyError;
|
|
756
|
+
}
|
|
757
|
+
return next;
|
|
808
758
|
}
|
|
809
759
|
|
|
810
760
|
function restoreStatuslineSettings(
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
761
|
+
ctx: ExtensionCommandContext,
|
|
762
|
+
options: StatuslineCommandOptions,
|
|
763
|
+
previous: LoadedStatuslineSettings,
|
|
764
|
+
saved: LoadedStatuslineSettings,
|
|
815
765
|
): unknown {
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
previous.rawDocument,
|
|
832
|
-
);
|
|
833
|
-
options.apply(restored, ctx);
|
|
834
|
-
return undefined;
|
|
835
|
-
} catch (error) {
|
|
836
|
-
return error;
|
|
837
|
-
}
|
|
766
|
+
try {
|
|
767
|
+
if (saved.rawDocument === undefined || saved.fileIdentity === undefined) {
|
|
768
|
+
throw new Error("The saved settings document identity is unavailable");
|
|
769
|
+
}
|
|
770
|
+
removeStatuslineSettingsDocumentIfMatches(options.settingsPath, saved.rawDocument, saved.fileIdentity);
|
|
771
|
+
if (previous.rawDocument === undefined || previous.settingsPath !== options.settingsPath) {
|
|
772
|
+
options.apply(previous, ctx);
|
|
773
|
+
return undefined;
|
|
774
|
+
}
|
|
775
|
+
const restored = (options.save ?? saveStatuslineSettingsDocument)(options.settingsPath, previous.rawDocument);
|
|
776
|
+
options.apply(restored, ctx);
|
|
777
|
+
return undefined;
|
|
778
|
+
} catch (error) {
|
|
779
|
+
return error;
|
|
780
|
+
}
|
|
838
781
|
}
|
|
839
782
|
|
|
840
783
|
function normalizeLineBreaks(segments: readonly ConfigSegmentName[]): ConfigSegmentName[] {
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
784
|
+
const normalized: ConfigSegmentName[] = [];
|
|
785
|
+
for (const segment of segments) {
|
|
786
|
+
if (
|
|
787
|
+
segment === LINE_BREAK_SEGMENT_NAME &&
|
|
788
|
+
(normalized.length === 0 || normalized.at(-1) === LINE_BREAK_SEGMENT_NAME)
|
|
789
|
+
) {
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
normalized.push(segment);
|
|
793
|
+
}
|
|
794
|
+
if (normalized.at(-1) === LINE_BREAK_SEGMENT_NAME) normalized.pop();
|
|
795
|
+
return normalized;
|
|
853
796
|
}
|
|
854
797
|
|
|
855
798
|
function editableSettings(
|
|
856
|
-
|
|
857
|
-
|
|
799
|
+
current: LoadedStatuslineSettings,
|
|
800
|
+
action: string,
|
|
858
801
|
): { parsed: Record<string, unknown>; rawDocument: string } {
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
if (!isRecord(parsed)) throw new Error("Settings must contain a JSON object");
|
|
872
|
-
return { parsed, rawDocument };
|
|
802
|
+
const rawDocument =
|
|
803
|
+
current.source === "user" && current.rawDocument !== undefined
|
|
804
|
+
? current.rawDocument
|
|
805
|
+
: current.source === "built-in" && current.rawDocument === undefined && current.diagnostics.length === 0
|
|
806
|
+
? DEFAULT_STATUSLINE_DOCUMENT
|
|
807
|
+
: undefined;
|
|
808
|
+
if (rawDocument === undefined || current.diagnostics.some((item) => item.code !== "unknown")) {
|
|
809
|
+
throw new Error(`Fix pi-statusline.json before ${action}`);
|
|
810
|
+
}
|
|
811
|
+
const parsed = JSON.parse(rawDocument) as unknown;
|
|
812
|
+
if (!isRecord(parsed)) throw new Error("Settings must contain a JSON object");
|
|
813
|
+
return { parsed, rawDocument };
|
|
873
814
|
}
|
|
874
815
|
|
|
875
816
|
function showStatus(ctx: ExtensionCommandContext, options: StatuslineCommandOptions) {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
817
|
+
if (!canNotify(ctx)) return;
|
|
818
|
+
const loaded = options.getLoaded();
|
|
819
|
+
const diagnostics = loaded.diagnostics
|
|
820
|
+
.slice(0, 5)
|
|
821
|
+
.map((item) => `${item.path || "root"}: ${item.message}`)
|
|
822
|
+
.join("; ");
|
|
823
|
+
ctx.ui.notify(
|
|
824
|
+
[
|
|
825
|
+
`pi-statusline source: ${loaded.source}`,
|
|
826
|
+
`active path: ${loaded.settingsPath}`,
|
|
827
|
+
`save target: ${options.settingsPath}`,
|
|
828
|
+
`palette preset: ${loaded.config.palettePreset}`,
|
|
829
|
+
`density: ${loaded.config.density}`,
|
|
830
|
+
`separator: ${loaded.config.separator}`,
|
|
831
|
+
`information: ${inferInformationProfile(loaded.config.segments)}`,
|
|
832
|
+
`segments: ${loaded.config.segments.join(", ") || "none"}`,
|
|
833
|
+
diagnostics ? `warnings: ${diagnostics}` : "warnings: none",
|
|
834
|
+
].join("\n"),
|
|
835
|
+
loaded.diagnostics.length > 0 ? "warning" : "info",
|
|
836
|
+
);
|
|
896
837
|
}
|
|
897
838
|
|
|
898
839
|
function showHelp(ctx: ExtensionCommandContext, settingsPath: string) {
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
840
|
+
if (!canNotify(ctx)) return;
|
|
841
|
+
ctx.ui.notify(
|
|
842
|
+
[
|
|
843
|
+
"/statusline — open Appearance, Information, Advanced, Status, and Help",
|
|
844
|
+
"/statusline settings — edit and apply JSON",
|
|
845
|
+
"/statusline status — show source, path, information level, and warnings",
|
|
846
|
+
"/statusline help — show this help",
|
|
847
|
+
"Menu actions: Appearance, Information, Advanced, Status, Help.",
|
|
848
|
+
"Information levels: minimal, balanced, detailed; any other segment array is custom.",
|
|
849
|
+
"Advanced actions: Custom layout, Edit settings JSON, Back.",
|
|
850
|
+
`Settings: ${settingsPath}`,
|
|
851
|
+
"Fields: palettePreset, palette, density, separator, segments, segmentText, extensionStatusIcons",
|
|
852
|
+
"Named presets ignore but preserve palette; custom uses its per-segment fg/bg colors.",
|
|
853
|
+
"Responsive rows retain context, model, location, and active work before decorative data.",
|
|
854
|
+
"Custom layout can show, hide, reorder, or split data segments across rows.",
|
|
855
|
+
"Press M for move mode, Alt+Up/Alt+Down for quick move, and B for a line break.",
|
|
856
|
+
"Line breaks (line_break) may repeat when separated by data segments, but cannot be consecutive.",
|
|
857
|
+
"segmentText supports prefix and suffix strings around Pi-owned dynamic values.",
|
|
858
|
+
"segmentText.model also supports truncationLength, truncationSymbol, and truncationDirection (start, middle, end).",
|
|
859
|
+
].join("\n"),
|
|
860
|
+
"info",
|
|
861
|
+
);
|
|
921
862
|
}
|
|
922
863
|
|
|
923
864
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
924
|
-
|
|
865
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
925
866
|
}
|
|
926
867
|
|
|
927
868
|
function isPaletteName(value: PalettePreset): value is PaletteName {
|
|
928
|
-
|
|
869
|
+
return (PALETTE_NAMES as readonly PalettePreset[]).includes(value);
|
|
929
870
|
}
|
|
930
871
|
|
|
931
872
|
function canNotify(ctx: ExtensionCommandContext): boolean {
|
|
932
|
-
|
|
873
|
+
return ctx.mode === "tui" || ctx.hasUI;
|
|
933
874
|
}
|
|
934
875
|
|
|
935
876
|
function formatError(error: unknown): string {
|
|
936
|
-
|
|
877
|
+
return error instanceof Error ? error.message : String(error);
|
|
937
878
|
}
|