pi-path-bar 0.4.1 → 0.5.0

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/src/settings.ts CHANGED
@@ -1,12 +1,89 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import { getSettingsListTheme } from "@earendil-works/pi-coding-agent";
3
- import { Container, SettingsList, Text, type SettingItem } from "@earendil-works/pi-tui";
3
+ import { Container, SettingsList, Text, isKeyRelease, matchesKey, parseKey, truncateToWidth, type SettingItem } from "@earendil-works/pi-tui";
4
4
  import { aliasName, folderPath, setAlias, type Config, type FolderAlias, type PathMode } from "./config.ts";
5
+ import { CLOCK, classifyStatuses, resolveOrder } from "./segments.ts";
5
6
 
6
- type Save = (change: (config: Config) => void) => boolean;
7
+ type Save = (change: (config: Config) => void, reinstall?: boolean) => boolean;
7
8
  const modes: Record<PathMode, string> = { short: "Short", auto: "Auto", full: "Full", native: "Native footer" };
8
9
  const switches = ["On", "Off"];
9
10
 
11
+ /** Keys that move the selected segment: ,< and .> as well as the plain characters. */
12
+ const MOVE = /^(?:shift\+)?([<>,.])$/;
13
+
14
+ async function editOrder(ctx: ExtensionContext, get: () => Config, save: Save, statuses: () => ReadonlyMap<string, string>) {
15
+ const { slots } = classifyStatuses(statuses());
16
+ const hidden = new Set(get().hiddenSegments);
17
+ const visible = new Set<string>([CLOCK, ...slots.keys(), ...hidden]);
18
+ // Preserve offline configured ids in `list` so reordering clock or active slots never drops them.
19
+ const list = resolveOrder(get().segments, new Set([...visible, ...get().segments]));
20
+ const rows = () => list.filter((id) => visible.has(id));
21
+ let cursor = Math.max(0, rows().indexOf(CLOCK));
22
+ const swap = (a: string, b: string) => {
23
+ const [i, j] = [list.indexOf(a), list.indexOf(b)];
24
+ [list[i], list[j]] = [list[j], list[i]];
25
+ };
26
+ // Write without reinstalling: both the standard footer and MinimalEditor re-read config on render.
27
+ const persistOrder = () => save((config) => { config.segments = list; }, false);
28
+ const persistHidden = () => save((config) => { config.hiddenSegments = [...hidden]; }, false);
29
+ await ctx.ui.custom<void>((tui, theme, _kb, done) => {
30
+ const container = new Container();
31
+ const label = (id: string) => {
32
+ const isHidden = hidden.has(id);
33
+ const marker = isHidden ? "○" : "●";
34
+ const entry = slots.get(id);
35
+ const preview = id === CLOCK
36
+ ? "time"
37
+ : entry
38
+ ? truncateToWidth(entry.text, 24, "…")
39
+ : "(inactive)";
40
+ const tags: string[] = [];
41
+ if (entry?.source === "adapted") tags.push("adapted");
42
+ if (isHidden) tags.push("hidden");
43
+ const tagText = tags.length ? ` (${tags.join(", ")})` : "";
44
+ return `${marker} ${id} ${preview}${tagText}`;
45
+ };
46
+ return {
47
+ render: (width: number) => {
48
+ container.clear();
49
+ container.addChild(new Text(theme.fg("accent", theme.bold("Footer order & visibility")), 0, 1));
50
+ for (const [index, id] of rows().entries()) {
51
+ const line = (index === cursor ? "▸ " : " ") + label(id);
52
+ const styled = index === cursor
53
+ ? theme.fg("accent", line)
54
+ : hidden.has(id)
55
+ ? theme.fg("dim", line)
56
+ : line;
57
+ container.addChild(new Text(styled, 1, 0));
58
+ }
59
+ container.addChild(new Text(theme.fg("dim", "< / > move space show/hide enter / esc close"), 0, 1));
60
+ return container.render(width);
61
+ },
62
+ invalidate: () => container.invalidate(),
63
+ handleInput: (input: string) => {
64
+ if (isKeyRelease(input)) return;
65
+ const items = rows();
66
+ const move = MOVE.exec(parseKey(input) ?? "")?.[1];
67
+ if (matchesKey(input, "up")) cursor = Math.max(0, cursor - 1);
68
+ else if (matchesKey(input, "down")) cursor = Math.min(items.length - 1, cursor + 1);
69
+ else if (move === "<" || move === ",") {
70
+ if (cursor > 0) { swap(items[cursor], items[cursor - 1]); cursor--; persistOrder(); }
71
+ } else if (move === ">" || move === ".") {
72
+ if (cursor < items.length - 1) { swap(items[cursor], items[cursor + 1]); cursor++; persistOrder(); }
73
+ } else if (matchesKey(input, "space") || input === " ") {
74
+ const target = items[cursor];
75
+ if (target) {
76
+ if (hidden.has(target)) hidden.delete(target);
77
+ else hidden.add(target);
78
+ persistHidden();
79
+ }
80
+ } else if (matchesKey(input, "enter") || matchesKey(input, "escape")) { done(); return; }
81
+ tui.requestRender();
82
+ },
83
+ };
84
+ });
85
+ }
86
+
10
87
  async function editAlias(ctx: ExtensionContext, save: Save, previous?: FolderAlias) {
11
88
  const pathInput = await ctx.ui.input(previous ? "Folder path (leave blank to keep the current value)" : "Folder path (blank: current directory; or enter an absolute or ~/ path)", previous?.path ?? ctx.sessionManager.getCwd());
12
89
  if (pathInput === undefined) return;
@@ -17,26 +94,37 @@ async function editAlias(ctx: ExtensionContext, save: Save, previous?: FolderAli
17
94
  if (save((config) => setAlias(config, { path, name }, previous?.path))) ctx.ui.notify("Folder alias saved", "info");
18
95
  }
19
96
 
20
- export async function openSettings(ctx: ExtensionContext, get: () => Config, save: Save) {
97
+ export async function openSettings(ctx: ExtensionContext, get: () => Config, save: Save, statuses: () => ReadonlyMap<string, string> = () => new Map()) {
21
98
  let selected = "mode";
22
99
  while (true) {
23
100
  const action = await ctx.ui.custom<string | undefined>((tui, theme, _kb, done) => {
24
101
  const config = get();
102
+ const { slots } = classifyStatuses(statuses());
103
+ const hidden = new Set(config.hiddenSegments);
104
+ const totalSegments = resolveOrder(config.segments, new Set([...slots.keys(), ...hidden])).length;
105
+ const hiddenCount = [...hidden].filter((id) => id === CLOCK || slots.has(id) || hidden.has(id)).length;
106
+ const orderSummary = hiddenCount > 0 ? `${totalSegments} segments (${hiddenCount} hidden)` : `${totalSegments} segments`;
25
107
  const items: SettingItem[] = [
26
108
  { id: "mode", label: "Path display", currentValue: modes[config.mode], values: Object.values(modes), description: "Short: always abbreviate. Auto: abbreviate when needed. Full: never abbreviate." },
109
+ { id: "minimal", label: "Minimal mode", currentValue: config.minimal ? "On" : "Off", values: switches, description: "Hide the footer and show compact status on the editor borders. Unknown extensions appear below only when active." },
27
110
  ...([ ["icon", "Folder icon"], ["branch", "Git status"], ["session", "Session name"] ] as const).map(([id, label]) => ({ id, label, currentValue: config[id] ? "On" : "Off", values: switches })),
28
111
  { id: "timeFormat", label: "Time format", currentValue: config.timeFormat, values: ["24h", "12h"], description: "Local time at the right of the path line. 12h includes AM/PM. Not shown in Native footer mode." },
112
+ { id: "order", label: "Footer order", currentValue: orderSummary, values: ["Open"], description: "Reorder or hide clock and adapted/registered extension segments." },
29
113
  { id: "add", label: "Add folder alias", currentValue: "Open", values: ["Open"], description: "Name any folder. A blank path uses the current directory. Only the display changes." },
30
114
  { id: "manage", label: "Manage folder aliases", currentValue: `${config.aliases.length} aliases`, values: ["Open"], description: "Edit a path or name, or delete an alias." },
31
115
  ];
32
116
  const list = new SettingsList(items, 10, getSettingsListTheme(), (id, value) => {
33
117
  selected = id;
34
- if (id === "add" || id === "manage") { done(id); return; }
35
- const previous = id === "mode" ? modes[get().mode] : id === "timeFormat" ? get().timeFormat : get()[id as "icon" | "branch" | "session"] ? "On" : "Off";
118
+ if (id === "add" || id === "manage" || id === "order") { done(id); return; }
119
+ const previous = id === "mode"
120
+ ? modes[get().mode]
121
+ : id === "timeFormat"
122
+ ? get().timeFormat
123
+ : get()[id as "minimal" | "icon" | "branch" | "session"] ? "On" : "Off";
36
124
  const success = save((next) => {
37
125
  if (id === "mode") next.mode = (Object.keys(modes) as PathMode[]).find((mode) => modes[mode] === value)!;
38
126
  else if (id === "timeFormat") next.timeFormat = value as Config["timeFormat"];
39
- else next[id as "icon" | "branch" | "session"] = value === "On";
127
+ else next[id as "minimal" | "icon" | "branch" | "session"] = value === "On";
40
128
  });
41
129
  if (!success) list.updateValue(id, previous);
42
130
  tui.requestRender();
@@ -54,6 +142,7 @@ export async function openSettings(ctx: ExtensionContext, get: () => Config, sav
54
142
  if (!action) return;
55
143
  try {
56
144
  if (action === "add") { await editAlias(ctx, save); continue; }
145
+ if (action === "order") { await editOrder(ctx, get, save, statuses); continue; }
57
146
  const aliases = get().aliases;
58
147
  if (!aliases.length) { ctx.ui.notify("No folder aliases yet. Add one first.", "info"); continue; }
59
148
  const labels = aliases.map((alias) => `${alias.name} → ${alias.path}`);