@timmo001/groundwork-tui 0.19.2 → 0.20.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.
package/README.md CHANGED
@@ -22,7 +22,7 @@ import { AppHeader, formatHelpBar, loadTheme } from "@timmo001/groundwork-tui";
22
22
  - `formatBreadcrumb`, `formatFilterBar` and `formatHelpBar` build the title
23
23
  trail, the filter line and the key hints along the bottom.
24
24
  - `MenuList` is a filterable list of two-line rows, with group headings and
25
- paging. `StatusList` is a plain list of labelled values.
25
+ paging. `StatusList` is a plain list of labeled values.
26
26
  - `MenuGrid` lays out `Tile` cards under `SectionHeading` rows, with arrow
27
27
  keys moving to the nearest tile.
28
28
  - `ScrollSurface` is a themed scroll box, and `surfaceBackground` its color.
@@ -33,4 +33,8 @@ import { AppHeader, formatHelpBar, loadTheme } from "@timmo001/groundwork-tui";
33
33
  `ChoiceDialog` picks from a list. `Toast` is a single self-closing message
34
34
  for results nothing else on screen can show.
35
35
 
36
+ Every word a component shows takes an option for an app in another language:
37
+ `pageLabels` on `MenuList`, `confirmLabel` and `cancelLabel` on
38
+ `ConfirmDialog`, and `help` on each dialog for its key hints.
39
+
36
40
  `templates/tui-menu` shows the components, and runs with `mise run demo:tui`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@timmo001/groundwork-tui",
3
- "version": "0.19.2",
3
+ "version": "0.20.0",
4
4
  "description": "Groundwork's terminal components: OpenTUI renderables on the terminal tokens",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -31,7 +31,7 @@
31
31
  "dependencies": {
32
32
  "@effect/platform-node": "4.1.2",
33
33
  "@opentui/core": "0.8.3",
34
- "@timmo001/groundwork-tokens": "0.19.2",
34
+ "@timmo001/groundwork-tokens": "0.20.0",
35
35
  "effect": "4.1.2",
36
36
  "fuse.js": "7.5.0"
37
37
  },
@@ -8,6 +8,7 @@
8
8
  import { SelectRenderable, SelectRenderableEvents } from "@opentui/core";
9
9
  import type { CliRenderer } from "@opentui/core";
10
10
  import { Dialog } from "./dialog.ts";
11
+ import type { HelpEntry } from "./help-bar.ts";
11
12
  import type { Theme } from "./theme.ts";
12
13
 
13
14
  export interface Choice<Value> {
@@ -21,6 +22,8 @@ export interface ChoiceDialogOptions<Value> {
21
22
  readonly theme: Theme;
22
23
  /** 50 by default */
23
24
  readonly width?: number | undefined;
25
+ /** The key hints along the bottom, for an app in another language; ↑↓ to move, Enter to choose and Esc to cancel by default */
26
+ readonly help?: readonly HelpEntry[] | undefined;
24
27
  readonly onChoose: (value: Value) => void;
25
28
  /** Runs when it closes without a choice */
26
29
  readonly onCancel?: (() => void) | undefined;
@@ -43,7 +46,7 @@ export class ChoiceDialog<Value> {
43
46
  theme,
44
47
  title: "",
45
48
  width: options.width ?? 50,
46
- help: [
49
+ help: options.help ?? [
47
50
  { key: "↑↓", action: "move" },
48
51
  { key: "Enter", action: "choose" },
49
52
  { key: "Esc", action: "cancel" },
@@ -8,6 +8,7 @@ import { BoxRenderable, TextRenderable, fg, t } from "@opentui/core";
8
8
  import type { CliRenderer, KeyEvent } from "@opentui/core";
9
9
  import { Button } from "./button.ts";
10
10
  import { Dialog } from "./dialog.ts";
11
+ import type { HelpEntry } from "./help-bar.ts";
11
12
  import type { Theme } from "./theme.ts";
12
13
 
13
14
  export interface ConfirmDialogOptions {
@@ -17,6 +18,10 @@ export interface ConfirmDialogOptions {
17
18
  readonly destructive?: boolean | undefined;
18
19
  /** "Confirm" by default */
19
20
  readonly confirmLabel?: string | undefined;
21
+ /** "Cancel" by default, for an app in another language */
22
+ readonly cancelLabel?: string | undefined;
23
+ /** The key hints along the bottom, for an app in another language; y to confirm, Tab to move and Esc to cancel by default */
24
+ readonly help?: readonly HelpEntry[] | undefined;
20
25
  readonly onConfirm: () => void;
21
26
  /** Runs when it closes without confirming */
22
27
  readonly onCancel?: (() => void) | undefined;
@@ -41,7 +46,7 @@ export class ConfirmDialog {
41
46
  title: "",
42
47
  color: options.destructive === true ? options.theme.red : undefined,
43
48
  height: 8,
44
- help: [
49
+ help: options.help ?? [
45
50
  { key: "y", action: "confirm" },
46
51
  { key: "Tab", action: "move" },
47
52
  { key: "Esc", action: "cancel" },
@@ -66,7 +71,7 @@ export class ConfirmDialog {
66
71
  const cancel = new Button(renderer, {
67
72
  id: `${options.id}-cancel`,
68
73
  theme: options.theme,
69
- label: "Cancel",
74
+ label: options.cancelLabel ?? "Cancel",
70
75
  onPress: () => this.dialog.close(),
71
76
  });
72
77
 
package/src/menu-list.ts CHANGED
@@ -80,6 +80,8 @@ export interface MenuListOptions<Item extends MenuListItem> {
80
80
  * unset.
81
81
  */
82
82
  readonly pageSize?: number;
83
+ /** The paging rows' text, for an app in another language. "Previous page" and "Next page" by default */
84
+ readonly pageLabels?: { readonly previous?: string; readonly next?: string };
83
85
  /** Called when the page changes, for a page indicator */
84
86
  readonly onPageChange?: (page: number, totalPages: number) => void;
85
87
  /**
@@ -694,9 +696,15 @@ export class MenuList<
694
696
  if (entry.kind !== "item") {
695
697
  const color = selected ? theme.accent : theme.fgSubtle;
696
698
  const next = entry.kind === "next";
699
+ const labels = this.options.pageLabels;
700
+
701
+ const label = next
702
+ ? (labels?.next ?? "Next page")
703
+ : (labels?.previous ?? "Previous page");
697
704
 
698
705
  row.iconText.content = t`${fg(color)(next ? "→" : "←")}`;
699
- row.titleText.content = t`${fg(color)(next ? "Next page" : "Previous page")}`;
706
+
707
+ row.titleText.content = t`${fg(color)(label)}`;
700
708
  row.descText.content = "";
701
709
 
702
710
  return;