@lune_99/pi-dock 0.1.0 → 0.2.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.
@@ -4,10 +4,12 @@ import type { LuneDockDisplayMode } from "@lune_99/pi-lune-extensions-core/dock"
4
4
  import { DockView, type VisibleDockItem } from "./dock-renderer.ts";
5
5
  import {
6
6
  CELL_SEPARATOR,
7
+ modelSegmentVariants,
7
8
  renderContextCell,
8
9
  renderInfoRow,
9
10
  renderModelSegment,
10
11
  renderStatusRow,
12
+ statColumns,
11
13
  type DockStatus,
12
14
  } from "./dock-status.ts";
13
15
 
@@ -51,6 +53,14 @@ interface Rows {
51
53
  statuses: string | undefined;
52
54
  }
53
55
 
56
+ /** What the dock row draws on its right; `width` is the span it occupies, at least the text's own. */
57
+ interface RightSegment {
58
+ text: string;
59
+ width: number;
60
+ }
61
+
62
+ const SEPARATOR_WIDTH = visibleWidth(CELL_SEPARATOR);
63
+
54
64
  /**
55
65
  * Takes over Pi's footer: the module cells beside the model, then the working directory beside
56
66
  * the usage statistics, framed according to the chosen style.
@@ -95,7 +105,10 @@ export class DockFooter {
95
105
  const lines = [rule];
96
106
  // The rule under the dock row carries the key hints and doubles as the closing rule.
97
107
  if (rows.dock !== undefined) {
98
- lines.push(rows.dock, input.selectedId === undefined ? rule : this.renderHintRule(width, theme));
108
+ lines.push(
109
+ rows.dock,
110
+ input.selectedId === undefined ? rule : this.renderHintRule(width, theme),
111
+ );
99
112
  }
100
113
  if (rows.info !== undefined) lines.push(rows.info);
101
114
  if (rows.statuses !== undefined) lines.push(rows.statuses);
@@ -107,11 +120,17 @@ export class DockFooter {
107
120
  // "│ " before and " │" after leave 4 columns, 1 of which the rows already spend on their gutter.
108
121
  const rows = this.renderRows(width - 3, theme, input, false);
109
122
  const border = (text: string) => theme.fg("borderMuted", text);
110
- const frame = (left: string, fill: string, right: string) => border(left) + fill + border(right);
123
+ const frame = (left: string, fill: string, right: string) =>
124
+ border(left) + fill + border(right);
111
125
  const wrap = (row: string) =>
112
- border("│") + row + " ".repeat(Math.max(0, width - 3 - visibleWidth(row))) + " " + border("│");
126
+ border("│") +
127
+ row +
128
+ " ".repeat(Math.max(0, width - 3 - visibleWidth(row))) +
129
+ " " +
130
+ border("│");
113
131
  const plain = border("─".repeat(width - 2));
114
- const hinted = input.selectedId === undefined ? plain : this.renderHintRule(width - 2, theme);
132
+ const hinted =
133
+ input.selectedId === undefined ? plain : this.renderHintRule(width - 2, theme);
115
134
 
116
135
  const more = rows.info !== undefined || rows.statuses !== undefined;
117
136
  const lines: string[] = [];
@@ -131,7 +150,12 @@ export class DockFooter {
131
150
  return [rows.dock, rows.info, rows.statuses].filter((row) => row !== undefined);
132
151
  }
133
152
 
134
- private renderRows(width: number, theme: Theme, input: DockFooterInput, inlineHints: boolean): Rows {
153
+ private renderRows(
154
+ width: number,
155
+ theme: Theme,
156
+ input: DockFooterInput,
157
+ inlineHints: boolean,
158
+ ): Rows {
135
159
  const { status, layout } = input;
136
160
  const showInfo = status !== undefined && layout.style !== "minimal";
137
161
  return {
@@ -155,13 +179,23 @@ export class DockFooter {
155
179
  ): string | undefined {
156
180
  const hasCells = input.entries.length > 0;
157
181
  const right = this.renderRightSegment(width, theme, input, inlineHints);
158
- if (!hasCells && !right) return undefined;
182
+ if (!hasCells && !right.text) return undefined;
159
183
 
160
- const tail = (hasCells && right ? theme.fg("dim", CELL_SEPARATOR) : "") + right;
184
+ const segment =
185
+ " ".repeat(Math.max(0, right.width - visibleWidth(right.text))) + right.text;
186
+ const tail = (hasCells && right.text ? theme.fg("dim", CELL_SEPARATOR) : "") + segment;
161
187
  const left = hasCells
162
- ? (this.cells.render(input.entries, width - visibleWidth(tail), theme, input.selectedId, input.mode)[0] ?? "")
188
+ ? (this.cells.render(
189
+ input.entries,
190
+ width - visibleWidth(tail),
191
+ theme,
192
+ input.selectedId,
193
+ input.mode,
194
+ )[0] ?? "")
163
195
  : "";
164
- return left + " ".repeat(Math.max(0, width - visibleWidth(left) - visibleWidth(tail))) + tail;
196
+ return (
197
+ left + " ".repeat(Math.max(0, width - visibleWidth(left) - visibleWidth(tail))) + tail
198
+ );
165
199
  }
166
200
 
167
201
  /** Key hint while focused (when inline), otherwise the model; the minimal style adds context use. */
@@ -170,30 +204,57 @@ export class DockFooter {
170
204
  theme: Theme,
171
205
  input: DockFooterInput,
172
206
  inlineHints: boolean,
173
- ): string {
207
+ ): RightSegment {
174
208
  const { status, layout } = input;
175
209
  const minimal = layout.style === "minimal";
210
+ const flush = (text: string): RightSegment => ({ text, width: visibleWidth(text) });
176
211
  // Minimal has no info row to share the line with, so the right side may claim more of it.
177
- const budget = Math.floor(width * (minimal ? 0.6 : 0.5)) - visibleWidth(CELL_SEPARATOR);
212
+ const budget = Math.floor(width * (minimal ? 0.6 : 0.5)) - SEPARATOR_WIDTH;
178
213
  if (inlineHints && input.selectedId !== undefined) {
179
214
  const hint = KEY_HINTS.find((candidate) => visibleWidth(candidate) <= budget);
180
- if (hint) return theme.fg("dim", hint);
215
+ if (hint) return flush(theme.fg("dim", hint));
181
216
  }
182
- if (!status || width < MIN_MODEL_ROW_WIDTH) return "";
183
- if (!minimal || !layout.showUsage) {
184
- return layout.showModel ? renderModelSegment(status, theme, budget) : "";
217
+ if (!status || width < MIN_MODEL_ROW_WIDTH) return flush("");
218
+ if (minimal && layout.showUsage) {
219
+ // Context use outranks optional model segments, so speed never displaces the counter.
220
+ const context = renderContextCell(status, theme);
221
+ const models = layout.showModel ? modelSegmentVariants(status, theme) : [""];
222
+ for (const model of models) {
223
+ const combined = model
224
+ ? model + theme.fg("dim", CELL_SEPARATOR) + context
225
+ : context;
226
+ if (visibleWidth(combined) <= budget) return flush(combined);
227
+ }
185
228
  }
229
+ if (!layout.showModel) return flush("");
230
+ // Keep the divider on the statistics grid without moving the model off the right edge.
231
+ return !minimal && layout.showUsage
232
+ ? this.placeModel(width, theme, status, layout.showWorkspace, budget)
233
+ : flush(renderModelSegment(status, theme, budget));
234
+ }
186
235
 
187
- // Context use outranks the provider prefix: drop the provider before the counter.
188
- const context = renderContextCell(status, theme);
189
- for (const showProvider of new Set([status.showProvider, false])) {
190
- const model = layout.showModel
191
- ? renderModelSegment({ ...status, showProvider }, theme, Infinity)
192
- : "";
193
- const combined = model ? model + theme.fg("dim", CELL_SEPARATOR) + context : context;
194
- if (visibleWidth(combined) <= budget) return combined;
236
+ /**
237
+ * Keeps the divider on an info-row bar while the model stays flush right within that span.
238
+ * The rightmost bar with room wins; optional model segments go before divider alignment does,
239
+ * and a model too wide for any bar uses only its own width.
240
+ */
241
+ private placeModel(
242
+ width: number,
243
+ theme: Theme,
244
+ status: DockStatus,
245
+ workspace: boolean,
246
+ budget: number,
247
+ ): RightSegment {
248
+ const spans = statColumns(status, width, workspace)
249
+ .map((column) => column - SEPARATOR_WIDTH)
250
+ .filter((span) => span <= budget)
251
+ .sort((a, b) => a - b);
252
+ for (const text of modelSegmentVariants(status, theme)) {
253
+ const span = spans.find((candidate) => candidate >= visibleWidth(text));
254
+ if (span !== undefined) return { text, width: span };
195
255
  }
196
- return layout.showModel ? renderModelSegment(status, theme, budget) : "";
256
+ const text = renderModelSegment(status, theme, budget);
257
+ return { text, width: visibleWidth(text) };
197
258
  }
198
259
 
199
260
  /** The hint rides the rule under the cells, so it never takes width from a cell or the model. */
package/src/dock-panel.ts CHANGED
@@ -39,6 +39,7 @@ const sampleStatus: DockStatus = {
39
39
  sessionName: undefined,
40
40
  model: { provider: "anthropic", id: "claude-opus-5-5", thinking: "max" },
41
41
  showProvider: true,
42
+ tokenSpeed: { tokensPerSecond: 48.2, generating: false },
42
43
  usage: {
43
44
  input: 28_000,
44
45
  output: 5_600,
@@ -121,7 +122,8 @@ export const dockPanel = defineSettingsPanel(dockSettings, {
121
122
  }),
122
123
  field("showModel", {
123
124
  label: "Show model",
124
- description: "Provider, model and thinking level beside the cells.",
125
+ description:
126
+ "Provider, model, thinking level and response token speed beside the cells.",
125
127
  preview: dockPreview,
126
128
  }),
127
129
  field("showWorkspace", {
@@ -16,6 +16,23 @@ export function resolveSnapshotLevel(snapshot: LuneDockSnapshot, mode: LuneDockD
16
16
  return snapshot.base;
17
17
  }
18
18
 
19
+ function renderCellText(entry: VisibleDockItem, mode: LuneDockDisplayMode, width: number): string {
20
+ const lines = resolveSnapshotLevel(entry.snapshot, mode).render(width);
21
+ // A level must publish one physical line; wrapping would corrupt the host's single-row widget.
22
+ if (lines.length !== 1 || /[\r\n]/.test(lines[0]!)) {
23
+ throw new Error(`Lune snapshot ${entry.id} (${mode}) must render exactly one line`);
24
+ }
25
+ return truncateToWidth(lines[0]!, width);
26
+ }
27
+
28
+ function highlight(theme: Theme, text: string): string {
29
+ // Reapply selection after ANSI style changes so plugin resets cannot clear its background.
30
+ return text
31
+ .split(/(\x1b\[[\d;:]*m)/)
32
+ .map((part, index) => (index % 2 === 0 ? theme.bg("selectedBg", part) : part))
33
+ .join("");
34
+ }
35
+
19
36
  /** Components own their text and styling; this view adds only placement and focus chrome. */
20
37
  export class DockView {
21
38
  /** The controller keeps one view across widget rebuilds, so the window survives a re-created component. */
@@ -54,40 +71,37 @@ export class DockView {
54
71
 
55
72
  const end = this.start + count;
56
73
 
57
- const before = this.start > 0 ? `‹${this.start} ` : "";
58
-
59
- const after = end < entries.length ? ` ${entries.length - end}›` : "";
74
+ let before = this.start > 0 ? `‹${this.start} ` : "";
75
+ let after = end < entries.length ? ` ${entries.length - end}›` : "";
60
76
 
61
- // The gutter is one column either way, so focus never changes a contribution's allocation.
62
- const gutter = selected >= 0 ? theme.fg("accent", "❯") : " ";
77
+ // Overflow counts must leave the existing gutter available for the selected cell's marker.
78
+ if (selected >= 0 && 1 + visibleWidth(before + after) + 3 * (count - 1) >= width) {
79
+ before = "";
80
+ after = "";
81
+ }
63
82
 
64
- // Markers are ANSI-wrapped, so budget visible columns and keep 3 in step with the separator below.
65
83
  const overhead = 1 + visibleWidth(before + after) + 3 * (count - 1);
66
-
67
84
  const available = Math.max(0, width - overhead);
85
+ const pointer = selected >= 0 ? highlight(theme, theme.fg("accent", "❯")) : "";
68
86
 
69
87
  const cells = entries.slice(this.start, end).map((entry, index) => {
70
88
  // Leftmost cells absorb the remainder so allocation stays independent of the selection.
71
89
  const allocated = Math.floor(available / count) + (index < available % count ? 1 : 0);
72
-
73
- const lines = resolveSnapshotLevel(entry.snapshot, mode).render(allocated);
74
-
75
- // A level must publish one physical line; wrapping would corrupt the host's single-row widget.
76
- if (lines.length !== 1 || /[\r\n]/.test(lines[0]!)) {
77
- throw new Error(`Lune snapshot ${entry.id} (${mode}) must render exactly one line`);
78
- }
79
- // A level may overflow its allocation: Dock owns the width budget, not the plugin.
80
- const text = truncateToWidth(lines[0]!, allocated);
81
- // Background-only highlight keeps a selected cell exactly as wide as an unfocused one.
82
- return entry.id === selectedId ? theme.bg("selectedBg", text) : text;
90
+ const text = renderCellText(entry, mode, allocated);
91
+ const active = entry.id === selectedId;
92
+ // Reuse the gutter or separator's final blank column instead of adding space to a cell.
93
+ const prefix =
94
+ index === 0
95
+ ? active
96
+ ? pointer
97
+ : " "
98
+ : active
99
+ ? theme.fg("dim", " │") + pointer
100
+ : theme.fg("dim", " │ ");
101
+ return prefix + (active ? highlight(theme, text) : text);
83
102
  });
84
103
 
85
- let line =
86
- gutter +
87
- theme.fg("dim", before) +
88
- cells.join(theme.fg("dim", " │ ")) +
89
- theme.fg("dim", after);
90
-
104
+ const line = theme.fg("dim", before) + cells.join("") + theme.fg("dim", after);
91
105
  return [truncateToWidth(line, width)];
92
106
  }
93
107
  }