termkit 2.3.1 → 2.4.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 +30 -4
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +315 -56
- package/dist/index.mjs +305 -47
- package/dist/models/Command.d.ts +2 -0
- package/dist/models/Command.d.ts.map +1 -1
- package/dist/models/MultiSelect.d.ts.map +1 -1
- package/dist/models/Select.d.ts.map +1 -1
- package/dist/models/Shell.d.ts +23 -0
- package/dist/models/Shell.d.ts.map +1 -0
- package/dist/utils/color.d.ts +2 -0
- package/dist/utils/color.d.ts.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -138,6 +138,31 @@ my-app help
|
|
|
138
138
|
my-app serve help
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
+
Commands defined without an `.action()` print their help automatically when invoked. This makes parent commands that only group subcommands self-documenting — running `my-app` or `my-app serve` with no further input shows usage instead of erroring.
|
|
142
|
+
|
|
143
|
+
### Shell
|
|
144
|
+
|
|
145
|
+
Turn a command tree into an interactive REPL. `Program.shell()` runs the root command's subcommands as a live prompt instead of parsing `process.argv` once.
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
import { Program } from 'termkit'
|
|
149
|
+
|
|
150
|
+
// ...define commands with Program.command(...)
|
|
151
|
+
|
|
152
|
+
await Program.shell({ banner: 'myapp shell — type "help", "exit" to quit' })
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Two modes:
|
|
156
|
+
|
|
157
|
+
- **`drill`** (default) — step through the tree one level at a time. Each prompt lists the available subcommands; type a name to descend, `..` to go back up, `help` to print usage, or an exit command to quit. Leaf commands prompt for each declared variable in turn, then run. An empty line at the root exits.
|
|
158
|
+
- **`free`** — type full command lines as you would on the CLI, with Tab completion across the command tree. `exit`/`quit` to leave.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
await Program.shell({ mode: 'free', promptColor: '#a855f7' })
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Options: `mode` (`'drill' | 'free'`, default `'drill'`), `prompt` (free-mode prompt label, defaults to the root command name), `promptColor` (named color, hex string, or xterm number), `banner`, `exitCommands` (default `['exit', 'quit']`), `historySize` (default `100`).
|
|
165
|
+
|
|
141
166
|
### configure
|
|
142
167
|
|
|
143
168
|
Sets global display options for the entire toolkit — accent color used in help output, tables, charts, and prompts; plus Unicode glyph support.
|
|
@@ -193,7 +218,7 @@ Pass `search: true` to add a type-to-filter input. Typing narrows the list; Back
|
|
|
193
218
|
const pkg = await select('Pick a package:', packages, { search: true })
|
|
194
219
|
```
|
|
195
220
|
|
|
196
|
-
Pass `maxHeight` to cap the visible rows and enable scrolling. The viewport follows the cursor automatically.
|
|
221
|
+
Pass `maxHeight` to cap the visible rows and enable scrolling. The viewport follows the cursor automatically. Even without `maxHeight`, the list is clamped to the terminal height so a long list never scrolls the screen.
|
|
197
222
|
|
|
198
223
|
```ts
|
|
199
224
|
const tz = await select('Timezone?', timezones, { maxHeight: 8 })
|
|
@@ -236,7 +261,7 @@ Pass `search: true` to add a type-to-filter input. All printable characters go t
|
|
|
236
261
|
const pkgs = await multiSelect('Add dependencies:', packages, { search: true })
|
|
237
262
|
```
|
|
238
263
|
|
|
239
|
-
Pass `maxHeight` to cap the visible rows with auto-scrolling
|
|
264
|
+
Pass `maxHeight` to cap the visible rows with auto-scrolling. As with `select`, the list is also clamped to the terminal height automatically so it never scrolls the screen.
|
|
240
265
|
|
|
241
266
|
```ts
|
|
242
267
|
const regions = await multiSelect('Deploy to:', regions, { maxHeight: 6 })
|
|
@@ -765,6 +790,7 @@ console.log(wrap(longParagraph, 60))
|
|
|
765
790
|
| `Program.middleware` | `(fn) => fn` | Identity helper for typing middleware inline |
|
|
766
791
|
| `Program.parse` | `(argv) => Promise<void>` | Parse argv using the root command |
|
|
767
792
|
| `Program.setDefaults` | `(defaults) => void` | Apply middleware/options to all new commands |
|
|
793
|
+
| `Program.shell` | `(options?) => Promise<void>` | Run the command tree as an interactive REPL |
|
|
768
794
|
|
|
769
795
|
### Functions
|
|
770
796
|
|
|
@@ -787,11 +813,11 @@ console.log(wrap(longParagraph, 60))
|
|
|
787
813
|
|
|
788
814
|
### Classes
|
|
789
815
|
|
|
790
|
-
`Command`, `Option`, `Variable`, `TermKit`, `Bar`, `MultiBar`, `Spinner`, `Scrollbox`, `Input`, `Select`, `MultiSelect`, `Log`, `Table`, `Column`, `Chart.Bar`, `Chart.VerticalBar`, `Chart.Heatmap`, `Chart.Scatter`, `Chart.Line`
|
|
816
|
+
`Command`, `Option`, `Variable`, `TermKit`, `Shell`, `Bar`, `MultiBar`, `Spinner`, `Scrollbox`, `Input`, `Select`, `MultiSelect`, `Log`, `Table`, `Column`, `Chart.Bar`, `Chart.VerticalBar`, `Chart.Heatmap`, `Chart.Scatter`, `Chart.Line`
|
|
791
817
|
|
|
792
818
|
### Types
|
|
793
819
|
|
|
794
|
-
`ActionFn`, `MiddlewareFn`, `ParsedOptions`, `CommandDefaults`, `VariableType`, `BarMode`, `BarOptions`, `MultiBarOptions`, `SpinnerOptions`, `InputOptions`, `InputReturn`, `InputType`, `SelectItem`, `SelectOptions`, `MultiSelectItem`, `MultiSelectOptions`, `LogOptions`, `TableOptions`, `ColumnOptions`, `ColumnAlign`, `MarkupOptions`, `MarkupStyleFn`, `MarkupStyles`, `HelpColor`, `Chart.BarItem`, `Chart.BarOptions`, `Chart.VerticalBarItem`, `Chart.VerticalBarOptions`, `Chart.HeatmapOptions`, `Chart.ScatterPoint`, `Chart.ScatterOptions`, `Chart.LinePoint`, `Chart.LineOptions`, `Chart.SparklineOptions`
|
|
820
|
+
`ActionFn`, `MiddlewareFn`, `ParsedOptions`, `CommandDefaults`, `ShellOptions`, `VariableType`, `BarMode`, `BarOptions`, `MultiBarOptions`, `SpinnerOptions`, `InputOptions`, `InputReturn`, `InputType`, `SelectItem`, `SelectOptions`, `MultiSelectItem`, `MultiSelectOptions`, `LogOptions`, `TableOptions`, `ColumnOptions`, `ColumnAlign`, `MarkupOptions`, `MarkupStyleFn`, `MarkupStyles`, `HelpColor`, `Chart.BarItem`, `Chart.BarOptions`, `Chart.VerticalBarItem`, `Chart.VerticalBarOptions`, `Chart.HeatmapOptions`, `Chart.ScatterPoint`, `Chart.ScatterOptions`, `Chart.LinePoint`, `Chart.LineOptions`, `Chart.SparklineOptions`
|
|
795
821
|
|
|
796
822
|
## Authors
|
|
797
823
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Command } from '@/models/Command';
|
|
2
2
|
import { Option } from '@/models/Option';
|
|
3
|
+
import type { ShellOptions } from '@/models/Shell';
|
|
3
4
|
import type { MiddlewareFn } from '@/types';
|
|
4
5
|
export type { HelpColor } from '@/config';
|
|
5
6
|
export { configure } from '@/config';
|
|
@@ -24,6 +25,8 @@ export type { ScrollboxOptions } from '@/models/Scrollbox';
|
|
|
24
25
|
export { Scrollbox, scrollbox } from '@/models/Scrollbox';
|
|
25
26
|
export type { SelectItem, SelectOptions } from '@/models/Select';
|
|
26
27
|
export { Select, select } from '@/models/Select';
|
|
28
|
+
export type { ShellOptions } from '@/models/Shell';
|
|
29
|
+
export { Shell } from '@/models/Shell';
|
|
27
30
|
export type { SpinnerOptions } from '@/models/Spinner';
|
|
28
31
|
export { Spinner } from '@/models/Spinner';
|
|
29
32
|
export type { TableOptions } from '@/models/Table';
|
|
@@ -48,5 +51,6 @@ export declare const Program: {
|
|
|
48
51
|
middleware: (fn: MiddlewareFn) => MiddlewareFn;
|
|
49
52
|
parse: (arr: string[]) => Promise<void>;
|
|
50
53
|
setDefaults: (data: CommandDefaults) => void;
|
|
54
|
+
shell: (options?: ShellOptions) => Promise<void>;
|
|
51
55
|
};
|
|
52
56
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot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