@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/dist/index.ts CHANGED
@@ -4296,33 +4296,15 @@ import { stripVTControlCharacters } from "node:util";
4296
4296
  import {
4297
4297
  getSettingsListTheme
4298
4298
  } from "@earendil-works/pi-coding-agent";
4299
- import {
4300
- Container,
4301
- Key,
4302
- matchesKey,
4303
- SettingsList,
4304
- Text
4305
- } from "@earendil-works/pi-tui";
4299
+ import { Key, matchesKey, SettingsList, Text } from "@earendil-works/pi-tui";
4306
4300
  var OFF = "Off";
4307
4301
  var ON = "On";
4308
- function fitSettingsRows(lines, maxRows) {
4309
- if (lines.length <= maxRows) return lines;
4310
- const content = lines.filter((line) => stripVTControlCharacters(line).trim().length > 0);
4311
- if (content.length <= maxRows) return content;
4312
- const selectedIndex = content.findIndex(
4313
- (line) => /^[→›]\s/u.test(stripVTControlCharacters(line))
4314
- );
4315
- if (selectedIndex < 0) return content.slice(0, maxRows);
4316
- return content.map((line, index) => ({ index, line })).sort(
4317
- (left, right) => Math.abs(left.index - selectedIndex) - Math.abs(right.index - selectedIndex) || left.index - right.index
4318
- ).slice(0, maxRows).sort((left, right) => left.index - right.index).map(({ line }) => line);
4319
- }
4320
4302
  async function showUsageSettings(ctx, settingsRuntime, parentSignal, isCurrent, onApplied) {
4321
4303
  if (ctx.mode !== "tui") {
4322
4304
  if (ctx.hasUI) ctx.ui.notify(`Edit settings manually: ${settingsRuntime.get().path}`, "info");
4323
4305
  return false;
4324
4306
  }
4325
- const { HorizontalRule } = await import("@narumitw/pi-tui-kit");
4307
+ const { HorizontalRule, renderBoundedFrame } = await import("@narumitw/pi-tui-kit");
4326
4308
  if (parentSignal.aborted || !isCurrent()) return false;
4327
4309
  return await ctx.ui.custom((tui, theme, _keybindings, done) => {
4328
4310
  const localController = new AbortController();
@@ -4347,9 +4329,7 @@ async function showUsageSettings(ctx, settingsRuntime, parentSignal, isCurrent,
4347
4329
  values: [OFF, ON]
4348
4330
  }
4349
4331
  ];
4350
- const container = new Container();
4351
4332
  const rule = new HorizontalRule({ ruleStyle: (text) => theme.fg("border", text) });
4352
- container.addChild(new Text(theme.fg("accent", theme.bold("pi-usage Settings")), 1, 1));
4353
4333
  let settingsList;
4354
4334
  const cancel = () => {
4355
4335
  if (closing) return;
@@ -4396,20 +4376,29 @@ async function showUsageSettings(ctx, settingsRuntime, parentSignal, isCurrent,
4396
4376
  },
4397
4377
  cancel
4398
4378
  );
4399
- container.addChild(settingsList);
4400
4379
  parentSignal.addEventListener("abort", cancel, { once: true });
4401
4380
  return {
4402
4381
  render(width) {
4403
- const content = container.render(width);
4382
+ const title = new Text(theme.fg("accent", theme.bold("pi-usage Settings")), 1, 0).render(
4383
+ width
4384
+ );
4385
+ const content = settingsList.render(width);
4386
+ const focusedRow = content.findIndex(
4387
+ (line) => /^[→›]\s/u.test(stripVTControlCharacters(line))
4388
+ );
4404
4389
  const terminalRows = Number.isFinite(tui.terminal?.rows) ? Math.floor(tui.terminal.rows) : 24;
4405
- const availableRows = Math.max(1, terminalRows - 3);
4406
- if (content.length + 2 > availableRows) {
4407
- return fitSettingsRows(content, availableRows);
4408
- }
4409
4390
  const [ruleLine = ""] = rule.render(width);
4410
- return [ruleLine, ...content, ruleLine];
4391
+ return renderBoundedFrame({
4392
+ width,
4393
+ maxRows: Math.max(1, terminalRows - 3),
4394
+ rule: ruleLine,
4395
+ title,
4396
+ content,
4397
+ priorityRows: focusedRow < 0 ? [] : [focusedRow],
4398
+ focusedRow
4399
+ });
4411
4400
  },
4412
- invalidate: () => container.invalidate(),
4401
+ invalidate: () => settingsList.invalidate(),
4413
4402
  handleInput(data) {
4414
4403
  if (closing) return;
4415
4404
  if (matchesKey(data, Key.ctrl("c"))) cancel();