@narumitw/pi-usage 0.60.2 → 0.60.3

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
@@ -4205,6 +4205,7 @@ function isTimeoutError(error) {
4205
4205
  }
4206
4206
 
4207
4207
  // src/usage-settings-ui.ts
4208
+ import { stripVTControlCharacters } from "node:util";
4208
4209
  import {
4209
4210
  getSettingsListTheme
4210
4211
  } from "@earendil-works/pi-coding-agent";
@@ -4217,11 +4218,25 @@ import {
4217
4218
  } from "@earendil-works/pi-tui";
4218
4219
  var OFF = "Off";
4219
4220
  var ON = "On";
4221
+ function fitSettingsRows(lines, maxRows) {
4222
+ if (lines.length <= maxRows) return lines;
4223
+ const content = lines.filter((line) => stripVTControlCharacters(line).trim().length > 0);
4224
+ if (content.length <= maxRows) return content;
4225
+ const selectedIndex = content.findIndex(
4226
+ (line) => /^[→›]\s/u.test(stripVTControlCharacters(line))
4227
+ );
4228
+ if (selectedIndex < 0) return content.slice(0, maxRows);
4229
+ return content.map((line, index) => ({ index, line })).sort(
4230
+ (left, right) => Math.abs(left.index - selectedIndex) - Math.abs(right.index - selectedIndex) || left.index - right.index
4231
+ ).slice(0, maxRows).sort((left, right) => left.index - right.index).map(({ line }) => line);
4232
+ }
4220
4233
  async function showUsageSettings(ctx, settingsRuntime, parentSignal, isCurrent, onApplied) {
4221
4234
  if (ctx.mode !== "tui") {
4222
4235
  if (ctx.hasUI) ctx.ui.notify(`Edit settings manually: ${settingsRuntime.get().path}`, "info");
4223
4236
  return false;
4224
4237
  }
4238
+ const { HorizontalRule } = await import("@narumitw/pi-tui-kit");
4239
+ if (parentSignal.aborted || !isCurrent()) return false;
4225
4240
  return await ctx.ui.custom((tui, theme, _keybindings, done) => {
4226
4241
  const localController = new AbortController();
4227
4242
  const signal = AbortSignal.any([parentSignal, localController.signal]);
@@ -4246,6 +4261,7 @@ async function showUsageSettings(ctx, settingsRuntime, parentSignal, isCurrent,
4246
4261
  }
4247
4262
  ];
4248
4263
  const container = new Container();
4264
+ const rule = new HorizontalRule({ ruleStyle: (text) => theme.fg("border", text) });
4249
4265
  container.addChild(new Text(theme.fg("accent", theme.bold("pi-usage Settings")), 1, 1));
4250
4266
  let settingsList;
4251
4267
  const cancel = () => {
@@ -4296,7 +4312,16 @@ async function showUsageSettings(ctx, settingsRuntime, parentSignal, isCurrent,
4296
4312
  container.addChild(settingsList);
4297
4313
  parentSignal.addEventListener("abort", cancel, { once: true });
4298
4314
  return {
4299
- render: (width) => container.render(width),
4315
+ render(width) {
4316
+ const content = container.render(width);
4317
+ const terminalRows = Number.isFinite(tui.terminal?.rows) ? Math.floor(tui.terminal.rows) : 24;
4318
+ const availableRows = Math.max(1, terminalRows - 3);
4319
+ if (content.length + 2 > availableRows) {
4320
+ return fitSettingsRows(content, availableRows);
4321
+ }
4322
+ const [ruleLine = ""] = rule.render(width);
4323
+ return [ruleLine, ...content, ruleLine];
4324
+ },
4300
4325
  invalidate: () => container.invalidate(),
4301
4326
  handleInput(data) {
4302
4327
  if (closing) return;