@pablozaiden/terminatui 0.1.2 → 0.3.0-beta-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.
Files changed (175) hide show
  1. package/AGENTS.md +43 -0
  2. package/CLAUDE.md +1 -0
  3. package/README.md +64 -43
  4. package/bun.lock +85 -0
  5. package/examples/tui-app/commands/config/app/get.ts +62 -0
  6. package/examples/tui-app/commands/config/app/index.ts +23 -0
  7. package/examples/tui-app/commands/config/app/set.ts +96 -0
  8. package/examples/tui-app/commands/config/index.ts +28 -0
  9. package/examples/tui-app/commands/config/user/get.ts +61 -0
  10. package/examples/tui-app/commands/config/user/index.ts +23 -0
  11. package/examples/tui-app/commands/config/user/set.ts +57 -0
  12. package/examples/tui-app/commands/greet.ts +14 -11
  13. package/examples/tui-app/commands/math.ts +6 -9
  14. package/examples/tui-app/commands/status.ts +24 -13
  15. package/examples/tui-app/index.ts +7 -3
  16. package/guides/01-hello-world.md +7 -2
  17. package/guides/02-adding-options.md +2 -2
  18. package/guides/03-multiple-commands.md +6 -8
  19. package/guides/04-subcommands.md +8 -8
  20. package/guides/05-interactive-tui.md +45 -30
  21. package/guides/06-config-validation.md +4 -12
  22. package/guides/07-async-cancellation.md +15 -69
  23. package/guides/08-complete-application.md +13 -179
  24. package/guides/README.md +7 -3
  25. package/package.json +4 -8
  26. package/src/__tests__/application.test.ts +87 -68
  27. package/src/__tests__/buildCliCommand.test.ts +99 -119
  28. package/src/__tests__/builtins.test.ts +27 -75
  29. package/src/__tests__/command.test.ts +100 -131
  30. package/src/__tests__/context.test.ts +1 -26
  31. package/src/__tests__/helpCore.test.ts +227 -0
  32. package/src/__tests__/parser.test.ts +98 -244
  33. package/src/__tests__/registry.test.ts +33 -160
  34. package/src/__tests__/schemaToFields.test.ts +75 -158
  35. package/src/builtins/help.ts +19 -4
  36. package/src/builtins/settings.ts +18 -32
  37. package/src/builtins/version.ts +4 -4
  38. package/src/cli/output/colors.ts +1 -1
  39. package/src/cli/parser.ts +26 -95
  40. package/src/core/application.ts +192 -110
  41. package/src/core/command.ts +26 -9
  42. package/src/core/context.ts +31 -20
  43. package/src/core/help.ts +24 -18
  44. package/src/core/knownCommands.ts +13 -0
  45. package/src/core/logger.ts +39 -42
  46. package/src/core/registry.ts +5 -12
  47. package/src/tui/TuiApplication.tsx +63 -120
  48. package/src/tui/TuiRoot.tsx +135 -0
  49. package/src/tui/adapters/factory.ts +19 -0
  50. package/src/tui/adapters/ink/InkRenderer.tsx +135 -0
  51. package/src/tui/adapters/ink/components/Button.tsx +12 -0
  52. package/src/tui/adapters/ink/components/Code.tsx +6 -0
  53. package/src/tui/adapters/ink/components/CodeHighlight.tsx +6 -0
  54. package/src/tui/adapters/ink/components/Container.tsx +5 -0
  55. package/src/tui/adapters/ink/components/Field.tsx +12 -0
  56. package/src/tui/adapters/ink/components/Label.tsx +24 -0
  57. package/src/tui/adapters/ink/components/MenuButton.tsx +12 -0
  58. package/src/tui/adapters/ink/components/MenuItem.tsx +17 -0
  59. package/src/tui/adapters/ink/components/Overlay.tsx +5 -0
  60. package/src/tui/adapters/ink/components/Panel.tsx +15 -0
  61. package/src/tui/adapters/ink/components/ScrollView.tsx +5 -0
  62. package/src/tui/adapters/ink/components/Select.tsx +44 -0
  63. package/src/tui/adapters/ink/components/Spacer.tsx +15 -0
  64. package/src/tui/adapters/ink/components/Spinner.tsx +5 -0
  65. package/src/tui/adapters/ink/components/TextInput.tsx +22 -0
  66. package/src/tui/adapters/ink/components/Value.tsx +7 -0
  67. package/src/tui/adapters/ink/keyboard.ts +97 -0
  68. package/src/tui/adapters/ink/utils.ts +16 -0
  69. package/src/tui/adapters/opentui/OpenTuiRenderer.tsx +115 -0
  70. package/src/tui/adapters/opentui/components/Button.tsx +13 -0
  71. package/src/tui/adapters/opentui/components/Code.tsx +12 -0
  72. package/src/tui/adapters/opentui/components/CodeHighlight.tsx +24 -0
  73. package/src/tui/adapters/opentui/components/Container.tsx +56 -0
  74. package/src/tui/adapters/opentui/components/Field.tsx +18 -0
  75. package/src/tui/adapters/opentui/components/Label.tsx +15 -0
  76. package/src/tui/adapters/opentui/components/MenuButton.tsx +14 -0
  77. package/src/tui/adapters/opentui/components/MenuItem.tsx +29 -0
  78. package/src/tui/adapters/opentui/components/Overlay.tsx +21 -0
  79. package/src/tui/adapters/opentui/components/Panel.tsx +78 -0
  80. package/src/tui/adapters/opentui/components/ScrollView.tsx +85 -0
  81. package/src/tui/adapters/opentui/components/Select.tsx +59 -0
  82. package/src/tui/adapters/opentui/components/Spacer.tsx +5 -0
  83. package/src/tui/adapters/opentui/components/Spinner.tsx +12 -0
  84. package/src/tui/adapters/opentui/components/TextInput.tsx +13 -0
  85. package/src/tui/adapters/opentui/components/Value.tsx +13 -0
  86. package/src/tui/{hooks → adapters/opentui/hooks}/useSpinner.ts +2 -11
  87. package/src/tui/adapters/opentui/keyboard.ts +61 -0
  88. package/src/tui/adapters/types.ts +70 -0
  89. package/src/tui/components/ActionButton.tsx +0 -36
  90. package/src/tui/components/CommandSelector.tsx +52 -92
  91. package/src/tui/components/ConfigForm.tsx +68 -42
  92. package/src/tui/components/FieldRow.tsx +0 -30
  93. package/src/tui/components/Header.tsx +14 -13
  94. package/src/tui/components/JsonHighlight.tsx +10 -17
  95. package/src/tui/components/ModalBase.tsx +38 -0
  96. package/src/tui/components/ResultsPanel.tsx +27 -36
  97. package/src/tui/components/StatusBar.tsx +24 -39
  98. package/src/tui/components/logColors.ts +12 -0
  99. package/src/tui/context/ClipboardContext.tsx +87 -0
  100. package/src/tui/context/ExecutorContext.tsx +139 -0
  101. package/src/tui/context/KeyboardContext.tsx +85 -71
  102. package/src/tui/context/LogsContext.tsx +35 -0
  103. package/src/tui/context/NavigationContext.tsx +194 -0
  104. package/src/tui/context/RendererContext.tsx +20 -0
  105. package/src/tui/context/TuiAppContext.tsx +58 -0
  106. package/src/tui/hooks/useActiveKeyHandler.ts +75 -0
  107. package/src/tui/hooks/useBackHandler.ts +34 -0
  108. package/src/tui/hooks/useClipboard.ts +40 -25
  109. package/src/tui/hooks/useClipboardProvider.ts +42 -0
  110. package/src/tui/hooks/useGlobalKeyHandler.ts +54 -0
  111. package/src/tui/modals/CliModal.tsx +82 -0
  112. package/src/tui/modals/EditorModal.tsx +207 -0
  113. package/src/tui/modals/LogsModal.tsx +98 -0
  114. package/src/tui/registry.ts +102 -0
  115. package/src/tui/screens/CommandSelectScreen.tsx +162 -0
  116. package/src/tui/screens/ConfigScreen.tsx +160 -0
  117. package/src/tui/screens/ErrorScreen.tsx +58 -0
  118. package/src/tui/screens/ResultsScreen.tsx +60 -0
  119. package/src/tui/screens/RunningScreen.tsx +72 -0
  120. package/src/tui/screens/ScreenBase.ts +6 -0
  121. package/src/tui/semantic/Button.tsx +7 -0
  122. package/src/tui/semantic/Code.tsx +7 -0
  123. package/src/tui/semantic/CodeHighlight.tsx +7 -0
  124. package/src/tui/semantic/Container.tsx +7 -0
  125. package/src/tui/semantic/Field.tsx +7 -0
  126. package/src/tui/semantic/Label.tsx +7 -0
  127. package/src/tui/semantic/MenuButton.tsx +7 -0
  128. package/src/tui/semantic/MenuItem.tsx +7 -0
  129. package/src/tui/semantic/Overlay.tsx +7 -0
  130. package/src/tui/semantic/Panel.tsx +7 -0
  131. package/src/tui/semantic/ScrollView.tsx +9 -0
  132. package/src/tui/semantic/Select.tsx +7 -0
  133. package/src/tui/semantic/Spacer.tsx +7 -0
  134. package/src/tui/semantic/Spinner.tsx +7 -0
  135. package/src/tui/semantic/TextInput.tsx +7 -0
  136. package/src/tui/semantic/Value.tsx +7 -0
  137. package/src/tui/semantic/types.ts +195 -0
  138. package/src/tui/theme.ts +25 -14
  139. package/src/tui/utils/buildCliCommand.ts +1 -0
  140. package/src/tui/utils/getEnumKeys.ts +3 -0
  141. package/src/tui/utils/parameterPersistence.ts +1 -0
  142. package/src/types/command.ts +0 -60
  143. package/examples/tui-app/commands/index.ts +0 -3
  144. package/src/__tests__/colors.test.ts +0 -127
  145. package/src/__tests__/commandClass.test.ts +0 -130
  146. package/src/__tests__/help.test.ts +0 -412
  147. package/src/__tests__/registryNew.test.ts +0 -160
  148. package/src/__tests__/table.test.ts +0 -146
  149. package/src/__tests__/tui.test.ts +0 -26
  150. package/src/builtins/index.ts +0 -4
  151. package/src/cli/help.ts +0 -174
  152. package/src/cli/index.ts +0 -3
  153. package/src/cli/output/index.ts +0 -2
  154. package/src/cli/output/table.ts +0 -141
  155. package/src/commands/help.ts +0 -50
  156. package/src/commands/index.ts +0 -1
  157. package/src/components/index.ts +0 -147
  158. package/src/core/index.ts +0 -15
  159. package/src/hooks/index.ts +0 -131
  160. package/src/index.ts +0 -137
  161. package/src/registry/commandRegistry.ts +0 -77
  162. package/src/registry/index.ts +0 -1
  163. package/src/tui/TuiApp.tsx +0 -582
  164. package/src/tui/app.ts +0 -29
  165. package/src/tui/components/CliModal.tsx +0 -81
  166. package/src/tui/components/EditorModal.tsx +0 -177
  167. package/src/tui/components/LogsPanel.tsx +0 -86
  168. package/src/tui/components/index.ts +0 -13
  169. package/src/tui/context/index.ts +0 -7
  170. package/src/tui/hooks/index.ts +0 -35
  171. package/src/tui/hooks/useKeyboardHandler.ts +0 -91
  172. package/src/tui/hooks/useLogStream.ts +0 -96
  173. package/src/tui/index.ts +0 -65
  174. package/src/tui/utils/index.ts +0 -13
  175. package/src/types/index.ts +0 -1
package/src/index.ts DELETED
@@ -1,137 +0,0 @@
1
- // Core - New OOP Architecture
2
- export {
3
- Application,
4
- AppContext,
5
- Command,
6
- CommandRegistry,
7
- ConfigValidationError,
8
- AbortError,
9
- Logger,
10
- createLogger,
11
- LogLevel,
12
- generateCommandHelp,
13
- generateAppHelp,
14
- } from "./core/index.ts";
15
- export type {
16
- ApplicationConfig,
17
- ApplicationHooks,
18
- GlobalOptions,
19
- AppConfig,
20
- AnyCommand,
21
- CommandExample,
22
- CommandResult,
23
- CommandExecutionContext,
24
- ResolveResult,
25
- LoggerConfig,
26
- LogEvent,
27
- HelpOptions,
28
- } from "./core/index.ts";
29
-
30
- // Execution Mode
31
- export { ExecutionMode } from "./types/execution.ts";
32
-
33
- // Built-in Commands (new)
34
- export { HelpCommand, VersionCommand, SettingsCommand, formatVersion } from "./builtins/index.ts";
35
- export type { VersionConfig } from "./builtins/index.ts";
36
-
37
- // TUI Framework (new)
38
- export {
39
- TuiApp,
40
- TuiApplication,
41
- Theme,
42
- KeyboardProvider,
43
- KeyboardPriority,
44
- useKeyboardHandler,
45
- useClipboard,
46
- useSpinner,
47
- useConfigState,
48
- useCommandExecutor,
49
- useLogStream,
50
- LogLevel as TuiLogLevel,
51
- FieldRow,
52
- ActionButton,
53
- Header,
54
- StatusBar,
55
- LogsPanel,
56
- ResultsPanel,
57
- ConfigForm,
58
- EditorModal,
59
- CliModal,
60
- CommandSelector,
61
- JsonHighlight,
62
- schemaToFieldConfigs,
63
- groupFieldConfigs,
64
- getFieldDisplayValue,
65
- buildCliCommand,
66
- } from "./tui/index.ts";
67
- export type {
68
- TuiApplicationConfig,
69
- ThemeColors,
70
- KeyboardEvent as TuiKeyboardEvent,
71
- KeyboardHandler,
72
- UseClipboardResult,
73
- UseSpinnerResult,
74
- UseConfigStateOptions,
75
- UseConfigStateResult,
76
- UseCommandExecutorResult,
77
- LogEntry,
78
- LogEvent as TuiLogEvent,
79
- LogSource,
80
- UseLogStreamResult,
81
- FieldType,
82
- FieldOption,
83
- FieldConfig,
84
- } from "./tui/index.ts";
85
-
86
- // Types (legacy, for backwards compatibility)
87
- export { defineCommand, defineTuiCommand } from "./types/command.ts";
88
- export type {
89
- Command as LegacyCommand,
90
- TuiCommand,
91
- OptionDef,
92
- OptionSchema,
93
- OptionValues,
94
- CommandContext,
95
- CommandExecutor,
96
- } from "./types/command.ts";
97
-
98
- // CLI Parser
99
- export {
100
- parseCliArgs,
101
- extractCommandChain,
102
- schemaToParseArgsOptions,
103
- parseOptionValues,
104
- validateOptions,
105
- } from "./cli/parser.ts";
106
- export type { ParseResult, ParseError } from "./cli/parser.ts";
107
-
108
- // Registry (legacy)
109
- export { createCommandRegistry } from "./registry/commandRegistry.ts";
110
- export type { CommandRegistry as LegacyCommandRegistry } from "./registry/commandRegistry.ts";
111
-
112
- // Built-in Commands (legacy)
113
- export { createHelpCommand } from "./commands/help.ts";
114
-
115
- // CLI Output
116
- export { colors, supportsColors } from "./cli/output/colors.ts";
117
- export { table, keyValueList, bulletList, numberedList } from "./cli/output/table.ts";
118
-
119
- // Help Generation (legacy)
120
- export {
121
- generateHelp,
122
- formatCommands,
123
- formatOptions as formatOptionsLegacy,
124
- formatUsage as formatUsageLegacy,
125
- formatExamples as formatExamplesLegacy,
126
- getCommandSummary,
127
- } from "./cli/help.ts";
128
-
129
- // TUI
130
- export { createApp } from "./tui/app.ts";
131
- export type { AppConfig as TuiAppConfig, AppState } from "./tui/app.ts";
132
-
133
- // Components
134
- export { Box, Text, Input, Select, Button, Modal, Spinner } from "./components/index.ts";
135
-
136
- // Hooks
137
- export { useCommand, useOptions, useNavigation, useModal, useAsync } from "./hooks/index.ts";
@@ -1,77 +0,0 @@
1
- import type { Command, OptionSchema } from "../types/command.ts";
2
-
3
- /**
4
- * Command registry for managing commands
5
- */
6
- export interface CommandRegistry<T extends OptionSchema = OptionSchema> {
7
- register(command: Command<T>): void;
8
- get(name: string): Command<T> | undefined;
9
- resolve(nameOrAlias: string): Command<T> | undefined;
10
- has(nameOrAlias: string): boolean;
11
- list(): Command<T>[];
12
- getNames(): string[];
13
- getCommandMap(): Record<string, Command<T>>;
14
- }
15
-
16
- /**
17
- * Create a command registry
18
- */
19
- export function createCommandRegistry<
20
- T extends OptionSchema = OptionSchema,
21
- >(): CommandRegistry<T> {
22
- const commands = new Map<string, Command<T>>();
23
- const aliases = new Map<string, string>();
24
-
25
- return {
26
- register(command: Command<T>): void {
27
- if (commands.has(command.name)) {
28
- throw new Error(`Command "${command.name}" is already registered`);
29
- }
30
-
31
- commands.set(command.name, command);
32
-
33
- if (command.aliases) {
34
- for (const alias of command.aliases) {
35
- if (aliases.has(alias) || commands.has(alias)) {
36
- throw new Error(`Alias "${alias}" conflicts with existing command or alias`);
37
- }
38
- aliases.set(alias, command.name);
39
- }
40
- }
41
- },
42
-
43
- get(name: string): Command<T> | undefined {
44
- return commands.get(name);
45
- },
46
-
47
- resolve(nameOrAlias: string): Command<T> | undefined {
48
- // Try direct name first
49
- const cmd = commands.get(nameOrAlias);
50
- if (cmd) return cmd;
51
-
52
- // Try alias
53
- const resolvedName = aliases.get(nameOrAlias);
54
- if (resolvedName) {
55
- return commands.get(resolvedName);
56
- }
57
-
58
- return undefined;
59
- },
60
-
61
- has(nameOrAlias: string): boolean {
62
- return commands.has(nameOrAlias) || aliases.has(nameOrAlias);
63
- },
64
-
65
- list(): Command<T>[] {
66
- return Array.from(commands.values());
67
- },
68
-
69
- getNames(): string[] {
70
- return Array.from(commands.keys());
71
- },
72
-
73
- getCommandMap(): Record<string, Command<T>> {
74
- return Object.fromEntries(commands);
75
- },
76
- };
77
- }
@@ -1 +0,0 @@
1
- export * from "./commandRegistry.ts";