@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.
- package/CHANGELOG.md +37 -0
- package/README.md +18 -18
- package/docs/dock-overview.png +0 -0
- package/docs/dock-overview.svg +2 -2
- package/docs/dock-styles.png +0 -0
- package/docs/dock-styles.svg +8 -8
- package/docs/reference.md +80 -49
- package/package.json +4 -4
- package/src/dock-controller.ts +24 -2
- package/src/dock-footer.ts +85 -24
- package/src/dock-panel.ts +3 -1
- package/src/dock-renderer.ts +38 -24
- package/src/dock-status.ts +272 -85
- package/src/index.ts +9 -2
package/src/dock-footer.ts
CHANGED
|
@@ -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(
|
|
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) =>
|
|
123
|
+
const frame = (left: string, fill: string, right: string) =>
|
|
124
|
+
border(left) + fill + border(right);
|
|
111
125
|
const wrap = (row: string) =>
|
|
112
|
-
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 =
|
|
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(
|
|
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
|
|
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(
|
|
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
|
|
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
|
-
):
|
|
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)) -
|
|
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 (
|
|
184
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
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:
|
|
125
|
+
description:
|
|
126
|
+
"Provider, model, thinking level and response token speed beside the cells.",
|
|
125
127
|
preview: dockPreview,
|
|
126
128
|
}),
|
|
127
129
|
field("showWorkspace", {
|
package/src/dock-renderer.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
//
|
|
62
|
-
|
|
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
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
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
|
}
|