@nbtca/prompt 1.5.6 → 1.5.8

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.
@@ -1,4 +1,4 @@
1
- import { type, space, glyph, brandMark } from '../core/theme.js';
1
+ import { type, space, glyph, brandMark, MAX_FRAME_COLS } from '../core/theme.js';
2
2
  import { pickIcon } from '../core/icons.js';
3
3
  import { t } from '../i18n/index.js';
4
4
  import { clipAnsiToVisualWidth, visualWidth } from '../core/text.js';
@@ -19,7 +19,8 @@ export function resolveChromeLayout(rows) {
19
19
  return { headerLines: 0, footerLines: 0 };
20
20
  }
21
21
  function renderRule(cols) {
22
- const width = Number.isFinite(cols) ? Math.max(1, Math.floor(cols)) : 80;
22
+ const terminal = Number.isFinite(cols) ? Math.max(1, Math.floor(cols)) : 80;
23
+ const width = Math.min(terminal, MAX_FRAME_COLS);
23
24
  const indent = visualWidth(space.indent) < width ? space.indent : '';
24
25
  const ruleWidth = Math.max(1, width - visualWidth(indent) * 2);
25
26
  return indent + type.hint(glyph.rule().repeat(ruleWidth));
@@ -146,8 +147,9 @@ export function renderFooter(_active, cols, tabCount, overrideHint, lineCount =
146
147
  function withPosition(hint, hintText, indent, position, cols) {
147
148
  if (position === undefined)
148
149
  return hint;
149
- const margin = visualWidth(space.indent) < cols ? space.indent : '';
150
- const gap = cols - visualWidth(indent + hintText) - visualWidth(position) - visualWidth(margin);
150
+ const frame = Math.min(cols, MAX_FRAME_COLS);
151
+ const margin = visualWidth(space.indent) < frame ? space.indent : '';
152
+ const gap = frame - visualWidth(indent + hintText) - visualWidth(position) - visualWidth(margin);
151
153
  if (gap < 2)
152
154
  return hint;
153
155
  return hint + ' '.repeat(gap) + type.hint(position) + margin;
@@ -44,7 +44,7 @@ export class ListField {
44
44
  const maxVisible = this.maxVisible;
45
45
  if (!maxVisible || options.length <= maxVisible) {
46
46
  return renderMenu({
47
- title,
47
+ ...(title === undefined ? {} : { title }),
48
48
  options,
49
49
  selectedIndex: this.index,
50
50
  ...(footer === undefined ? {} : { footer }),
@@ -52,7 +52,7 @@ export class ListField {
52
52
  }
53
53
  const visible = options.slice(this.scrollTop, this.scrollTop + maxVisible);
54
54
  const lines = renderMenu({
55
- title,
55
+ ...(title === undefined ? {} : { title }),
56
56
  options: visible,
57
57
  selectedIndex: this.index - this.scrollTop,
58
58
  }, cols).split('\n');
@@ -80,12 +80,16 @@ export class ListField {
80
80
  const labelWidth = options.reduce((width, option) => Math.max(width, visualWidth(option.label)), 0);
81
81
  const optionGroups = options.map((option, index) => renderMenuOption(option, index === this.index, labelWidth, cols));
82
82
  const selectedLines = optionGroups[this.index] ?? [];
83
- const titleValue = options.length > 1
84
- ? `${type.heading(title)}${type.hint(` ${this.index + 1}/${options.length}`)}`
85
- : type.heading(title);
83
+ const titleValue = !title
84
+ ? ''
85
+ : options.length > 1
86
+ ? `${type.heading(title)}${type.hint(` ${this.index + 1}/${options.length}`)}`
87
+ : type.heading(title);
86
88
  const titleLines = title ? renderIndentedOutput(titleValue, cols) : [];
87
89
  let header = [];
88
- if (titleLines.length + 1 + selectedLines.length <= maxRows)
90
+ if (titleLines.length === 0)
91
+ header = [];
92
+ else if (titleLines.length + 1 + selectedLines.length <= maxRows)
89
93
  header = [...titleLines, ''];
90
94
  else if (titleLines.length + selectedLines.length <= maxRows)
91
95
  header = titleLines;
@@ -92,10 +92,8 @@ function goToLoginId(errorMessage) {
92
92
  };
93
93
  }
94
94
  function buildPublicField() {
95
- const trans = t();
96
95
  return new ListField({
97
- title: trans.timetable.menuEntry,
98
- options: [{ value: 'login', label: trans.timetable.publicLoginAction }],
96
+ options: [{ value: 'login', label: t().timetable.publicLoginAction }],
99
97
  });
100
98
  }
101
99
  async function goToPublic(ctx, generation = lifecycleGeneration) {
@@ -87,8 +87,7 @@ export function renderMenuOption(option, selected, labelWidth = visualWidth(opti
87
87
  }
88
88
  export function renderMenu(state, cols = Number.POSITIVE_INFINITY) {
89
89
  const labelWidth = state.options.reduce((width, option) => Math.max(width, visualWidth(option.label)), 0);
90
- const lines = renderIndentedText(state.title, cols, type.heading);
91
- lines.push('');
90
+ const lines = state.title ? [...renderIndentedText(state.title, cols, type.heading), ''] : [];
92
91
  state.options.forEach((option, index) => {
93
92
  lines.push(...renderMenuOption(option, index === state.selectedIndex, labelWidth, cols));
94
93
  });
@@ -42,6 +42,8 @@ export const glyph = {
42
42
  barFilled: () => pickIcon('█', '#'),
43
43
  barEmpty: () => pickIcon('░', '-'),
44
44
  };
45
+ /** Beyond this the app stops stretching; a terminal wider than this keeps the slack. */
46
+ export const MAX_FRAME_COLS = 100;
45
47
  export const space = {
46
48
  indent: ' ',
47
49
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nbtca/prompt",
3
- "version": "1.5.6",
3
+ "version": "1.5.8",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {