@narumitw/pi-usage 0.60.6 → 0.60.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-usage",
3
- "version": "0.60.6",
3
+ "version": "0.60.7",
4
4
  "description": "Pi extension that shows current-account usage and DeepSeek API balance for supported providers.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -71,6 +71,6 @@
71
71
  "directory": "packages/pi-usage"
72
72
  },
73
73
  "dependencies": {
74
- "@narumitw/pi-tui-kit": "^0.59.0"
74
+ "@narumitw/pi-tui-kit": "^0.61.0"
75
75
  }
76
76
  }
@@ -3,14 +3,7 @@ import {
3
3
  type ExtensionCommandContext,
4
4
  getSettingsListTheme,
5
5
  } from "@earendil-works/pi-coding-agent";
6
- import {
7
- Container,
8
- Key,
9
- matchesKey,
10
- type SettingItem,
11
- SettingsList,
12
- Text,
13
- } from "@earendil-works/pi-tui";
6
+ import { Key, matchesKey, type SettingItem, SettingsList, Text } from "@earendil-works/pi-tui";
14
7
  import { errorMessage } from "./core.js";
15
8
  import type { UsageSettingsRuntime } from "./settings.js";
16
9
 
@@ -19,26 +12,6 @@ const ON = "On";
19
12
 
20
13
  type UsageSettingId = "codexFastMode" | "codexStatusResetCountdown";
21
14
 
22
- function fitSettingsRows(lines: string[], maxRows: number): string[] {
23
- if (lines.length <= maxRows) return lines;
24
- const content = lines.filter((line) => stripVTControlCharacters(line).trim().length > 0);
25
- if (content.length <= maxRows) return content;
26
- const selectedIndex = content.findIndex((line) =>
27
- /^[→›]\s/u.test(stripVTControlCharacters(line)),
28
- );
29
- if (selectedIndex < 0) return content.slice(0, maxRows);
30
- return content
31
- .map((line, index) => ({ index, line }))
32
- .sort(
33
- (left, right) =>
34
- Math.abs(left.index - selectedIndex) - Math.abs(right.index - selectedIndex) ||
35
- left.index - right.index,
36
- )
37
- .slice(0, maxRows)
38
- .sort((left, right) => left.index - right.index)
39
- .map(({ line }) => line);
40
- }
41
-
42
15
  export async function showUsageSettings(
43
16
  ctx: ExtensionCommandContext,
44
17
  settingsRuntime: UsageSettingsRuntime,
@@ -50,7 +23,7 @@ export async function showUsageSettings(
50
23
  if (ctx.hasUI) ctx.ui.notify(`Edit settings manually: ${settingsRuntime.get().path}`, "info");
51
24
  return false;
52
25
  }
53
- const { HorizontalRule } = await import("@narumitw/pi-tui-kit");
26
+ const { HorizontalRule, renderBoundedFrame } = await import("@narumitw/pi-tui-kit");
54
27
  if (parentSignal.aborted || !isCurrent()) return false;
55
28
  return (
56
29
  (await ctx.ui.custom<boolean>((tui, theme, _keybindings, done) => {
@@ -76,9 +49,7 @@ export async function showUsageSettings(
76
49
  values: [OFF, ON],
77
50
  },
78
51
  ];
79
- const container = new Container();
80
52
  const rule = new HorizontalRule({ ruleStyle: (text) => theme.fg("border", text) });
81
- container.addChild(new Text(theme.fg("accent", theme.bold("pi-usage Settings")), 1, 1));
82
53
 
83
54
  let settingsList: SettingsList;
84
55
  const cancel = () => {
@@ -126,23 +97,34 @@ export async function showUsageSettings(
126
97
  },
127
98
  cancel,
128
99
  );
129
- container.addChild(settingsList);
130
100
 
131
101
  parentSignal.addEventListener("abort", cancel, { once: true });
132
102
  return {
133
103
  render(width: number) {
134
- const content = container.render(width);
104
+ // Compatibility: Kit puts the title directly below the top rule and keeps compact
105
+ // rules when at least five rows fit; both replace the legacy wrapper layout.
106
+ const title = new Text(theme.fg("accent", theme.bold("pi-usage Settings")), 1, 0).render(
107
+ width,
108
+ );
109
+ const content = settingsList.render(width);
110
+ const focusedRow = content.findIndex((line) =>
111
+ /^[→›]\s/u.test(stripVTControlCharacters(line)),
112
+ );
135
113
  const terminalRows = Number.isFinite(tui.terminal?.rows)
136
114
  ? Math.floor(tui.terminal.rows)
137
115
  : 24;
138
- const availableRows = Math.max(1, terminalRows - 3);
139
- if (content.length + 2 > availableRows) {
140
- return fitSettingsRows(content, availableRows);
141
- }
142
116
  const [ruleLine = ""] = rule.render(width);
143
- return [ruleLine, ...content, ruleLine];
117
+ return renderBoundedFrame({
118
+ width,
119
+ maxRows: Math.max(1, terminalRows - 3),
120
+ rule: ruleLine,
121
+ title,
122
+ content,
123
+ priorityRows: focusedRow < 0 ? [] : [focusedRow],
124
+ focusedRow,
125
+ });
144
126
  },
145
- invalidate: () => container.invalidate(),
127
+ invalidate: () => settingsList.invalidate(),
146
128
  handleInput(data: string) {
147
129
  if (closing) return;
148
130
  if (matchesKey(data, Key.ctrl("c"))) cancel();