@timmo001/groundwork-tui 0.19.2 → 0.20.1
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 +5 -1
- package/package.json +5 -3
- package/src/choice-dialog.ts +4 -1
- package/src/confirm-dialog.ts +7 -2
- package/src/menu-list.ts +9 -1
- package/src/theme.test.ts +0 -104
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
|
|
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,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timmo001/groundwork-tui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"description": "Groundwork's terminal components: OpenTUI renderables on the terminal tokens",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
|
-
".": "./src/index.ts"
|
|
8
|
+
".": "./src/index.ts",
|
|
9
|
+
"./*": "./src/*"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
12
|
"src",
|
|
13
|
+
"!src/*.test.ts",
|
|
12
14
|
"README.md",
|
|
13
15
|
"LICENSE"
|
|
14
16
|
],
|
|
@@ -31,7 +33,7 @@
|
|
|
31
33
|
"dependencies": {
|
|
32
34
|
"@effect/platform-node": "4.1.2",
|
|
33
35
|
"@opentui/core": "0.8.3",
|
|
34
|
-
"@timmo001/groundwork-tokens": "0.
|
|
36
|
+
"@timmo001/groundwork-tokens": "0.20.1",
|
|
35
37
|
"effect": "4.1.2",
|
|
36
38
|
"fuse.js": "7.5.0"
|
|
37
39
|
},
|
package/src/choice-dialog.ts
CHANGED
|
@@ -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" },
|
package/src/confirm-dialog.ts
CHANGED
|
@@ -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
|
-
|
|
706
|
+
|
|
707
|
+
row.titleText.content = t`${fg(color)(label)}`;
|
|
700
708
|
row.descText.content = "";
|
|
701
709
|
|
|
702
710
|
return;
|
package/src/theme.test.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests loading a theme that isn't one of the generated ones: a theme file
|
|
3
|
-
* by path, an app's own document by id and from `GW_THEME`, and the
|
|
4
|
-
* transparent option.
|
|
5
|
-
*
|
|
6
|
-
* @module
|
|
7
|
-
*/
|
|
8
|
-
import { afterEach, expect, test } from "bun:test";
|
|
9
|
-
import { fileURLToPath } from "node:url";
|
|
10
|
-
import { parseTheme } from "@timmo001/groundwork-tokens/runtime";
|
|
11
|
-
import { Effect, Result } from "effect";
|
|
12
|
-
import {
|
|
13
|
-
DEFAULT_THEME,
|
|
14
|
-
loadThemeWith,
|
|
15
|
-
resolveTheme,
|
|
16
|
-
themeFor,
|
|
17
|
-
themeFromDocument,
|
|
18
|
-
themeOptionsWith,
|
|
19
|
-
} from "./theme.ts";
|
|
20
|
-
|
|
21
|
-
const glazingFile = fileURLToPath(
|
|
22
|
-
import.meta.resolve("@timmo001/groundwork-tokens/themes/glazing.json"),
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
const kiln = Result.getOrThrow(
|
|
26
|
-
parseTheme(
|
|
27
|
-
JSON.stringify({
|
|
28
|
-
kind: "solved",
|
|
29
|
-
id: "kiln",
|
|
30
|
-
name: "Kiln",
|
|
31
|
-
description: "Warm clay and ember orange.",
|
|
32
|
-
background: "#1f1a17",
|
|
33
|
-
accent: "#e08a4f",
|
|
34
|
-
style: {
|
|
35
|
-
font: "Inter",
|
|
36
|
-
mono: "JetBrains Mono",
|
|
37
|
-
radius: { panel: 6, control: 4, chip: 4 },
|
|
38
|
-
border: { width: 1, strength: "soft" },
|
|
39
|
-
weights: { regular: 400, strong: 600 },
|
|
40
|
-
density: "compact",
|
|
41
|
-
capitals: false,
|
|
42
|
-
link: { color: "accent", underline: "thin" },
|
|
43
|
-
surfaceAccent: "none",
|
|
44
|
-
rows: "dense",
|
|
45
|
-
},
|
|
46
|
-
}),
|
|
47
|
-
),
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
afterEach(() => {
|
|
51
|
-
delete process.env.GW_THEME;
|
|
52
|
-
delete process.env.GW_MODE;
|
|
53
|
-
delete process.env.GW_TRANSPARENT;
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test("a theme file by path matches the generated theme", async () => {
|
|
57
|
-
const fromFile = await Effect.runPromise(
|
|
58
|
-
resolveTheme({ theme: glazingFile, mode: "light" }),
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
expect(fromFile).toEqual(themeFor("glazing", "light"));
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test("a theme file that isn't there falls back to the default", async () => {
|
|
65
|
-
const theme = await Effect.runPromise(
|
|
66
|
-
resolveTheme({ theme: "./no-such-theme.json" }),
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
expect(theme).toEqual(DEFAULT_THEME);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("an app's own theme by id, in its own mode, and transparent", async () => {
|
|
73
|
-
const theme = await Effect.runPromise(
|
|
74
|
-
resolveTheme({ theme: "kiln", transparent: true }, [kiln]),
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
expect(theme).toEqual(
|
|
78
|
-
themeFromDocument(kiln, undefined, { transparent: true }),
|
|
79
|
-
);
|
|
80
|
-
expect(theme.transparent).toBe(true);
|
|
81
|
-
expect(theme.accent).not.toBe(DEFAULT_THEME.accent);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test("GW_THEME takes a path and GW_TRANSPARENT the option", async () => {
|
|
85
|
-
process.env.GW_THEME = glazingFile;
|
|
86
|
-
process.env.GW_MODE = "darker";
|
|
87
|
-
process.env.GW_TRANSPARENT = "true";
|
|
88
|
-
|
|
89
|
-
const theme = await Effect.runPromise(loadThemeWith());
|
|
90
|
-
|
|
91
|
-
expect(theme).toEqual({
|
|
92
|
-
...themeFor("glazing", "darker"),
|
|
93
|
-
transparent: true,
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test("the picker lists the app's themes first, then the optional ones too", async () => {
|
|
98
|
-
const options = await Effect.runPromise(themeOptionsWith([kiln]));
|
|
99
|
-
const ids = options.map((option) => option.id);
|
|
100
|
-
|
|
101
|
-
expect(ids[0]).toBe("kiln");
|
|
102
|
-
expect(ids).toContain("catppuccin-mocha");
|
|
103
|
-
expect(options[0]?.modes).toEqual(["light", "dark", "darker"]);
|
|
104
|
-
});
|