@geoqiao/pi-ask 1.2.3 → 1.3.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.
@@ -1,5 +1,9 @@
1
- import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
2
- import { UI_DIMENSIONS } from "../constants/ui.ts";
1
+ import {
2
+ truncateToWidth,
3
+ visibleWidth,
4
+ wrapTextWithAnsi,
5
+ } from "@earendil-works/pi-tui";
6
+ import { UI_DIMENSIONS, UI_TEXT } from "../constants/ui.ts";
3
7
  import {
4
8
  measurePreviewLeftWidth,
5
9
  mergeColumns,
@@ -83,7 +87,13 @@ function renderStandardOption(
83
87
  row.pointer,
84
88
  " ".repeat(visibleWidth(row.pointer))
85
89
  );
86
- renderOptionDescription(lines, row.description, context.width, context.theme);
90
+ renderOptionSubtitle(
91
+ lines,
92
+ row.description,
93
+ row.recommended,
94
+ context.width,
95
+ context.theme
96
+ );
87
97
  renderOptionDetail(lines, row.detail, context, {
88
98
  suppressLeadingGap: !!row.description,
89
99
  });
@@ -170,7 +180,7 @@ function renderPreviewOptionList(
170
180
  row.pointer,
171
181
  " "
172
182
  );
173
- renderOptionDescription(lines, row.description, width, theme);
183
+ renderOptionSubtitle(lines, row.description, row.recommended, width, theme);
174
184
  }
175
185
  return lines;
176
186
  }
@@ -275,14 +285,36 @@ function renderInteractiveCustomOption(
275
285
  });
276
286
  }
277
287
 
278
- function renderOptionDescription(
288
+ function renderOptionSubtitle(
279
289
  lines: string[],
280
290
  description: string | undefined,
291
+ recommended: boolean,
281
292
  width: number,
282
293
  theme: Theme
283
294
  ) {
284
- if (!description) {
295
+ if (!recommended) {
296
+ if (description) {
297
+ pushWrappedText(
298
+ lines,
299
+ description,
300
+ width,
301
+ theme,
302
+ "muted",
303
+ " ",
304
+ " "
305
+ );
306
+ }
285
307
  return;
286
308
  }
287
- pushWrappedText(lines, description, width, theme, "muted", " ", " ");
309
+
310
+ const indent = " ";
311
+ const text =
312
+ theme.fg("warning", UI_TEXT.recommendedMarker) +
313
+ (description ? theme.fg("muted", ` | ${description}`) : "");
314
+ for (const line of wrapTextWithAnsi(
315
+ text,
316
+ Math.max(1, width - visibleWidth(indent))
317
+ )) {
318
+ lines.push(truncateToWidth(`${indent}${line}`, width));
319
+ }
288
320
  }
@@ -30,6 +30,7 @@ export interface OptionRowModel {
30
30
  label: string;
31
31
  pointer: string;
32
32
  prefix: string;
33
+ recommended: boolean;
33
34
  selected: boolean;
34
35
  }
35
36
 
@@ -104,6 +105,7 @@ function buildOptionRowModel(
104
105
  label: option.label,
105
106
  pointer,
106
107
  prefix: getOptionPrefix(question.type, option, answered),
108
+ recommended: option.recommended === true,
107
109
  selected,
108
110
  };
109
111
  }