@termdraw/opentui 0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ben Vinegar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # @termdraw/opentui
2
+
3
+ `@termdraw/opentui` provides the embeddable OpenTUI components and renderables behind termDRAW for terminal apps that want an in-process drawing surface.
4
+
5
+ ## What it provides
6
+
7
+ - `TermDrawApp` for the full chrome with header, palette, footer, and splash
8
+ - `TermDrawEditor` for the bare editor surface
9
+ - `TermDraw` as an alias for `TermDrawApp`
10
+ - renderables and helpers for saved output and CLI help text
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install @termdraw/opentui @opentui/core @opentui/react react
16
+ ```
17
+
18
+ ## Quick start
19
+
20
+ ```tsx
21
+ import { createCliRenderer } from "@opentui/core";
22
+ import { createRoot } from "@opentui/react";
23
+ import { TermDrawApp } from "@termdraw/opentui";
24
+
25
+ const renderer = await createCliRenderer({
26
+ useMouse: true,
27
+ enableMouseMovement: true,
28
+ autoFocus: true,
29
+ screenMode: "alternate-screen",
30
+ });
31
+
32
+ createRoot(renderer).render(
33
+ <TermDrawApp
34
+ width="100%"
35
+ height="100%"
36
+ autoFocus
37
+ onSave={(art) => {
38
+ console.log(art);
39
+ }}
40
+ onCancel={() => {
41
+ renderer.destroy();
42
+ }}
43
+ />,
44
+ );
45
+ ```
46
+
47
+ ## Also exported
48
+
49
+ - `TermDrawAppRenderable`
50
+ - `TermDrawEditorRenderable`
51
+ - `TermDrawRenderable`
52
+ - `formatSavedOutput`
53
+ - `buildHelpText`
54
+ - `registerTermDrawComponent`
55
+ - `registerTermDrawComponents`
56
+
57
+ ## Standalone app
58
+
59
+ If you want the packaged terminal app instead of the embeddable OpenTUI surface:
60
+
61
+ ```bash
62
+ npm install --global @termdraw/app
63
+ ```
64
+
65
+ Then run:
66
+
67
+ ```bash
68
+ termdraw
69
+ ```
70
+
71
+ ## Contributing
72
+
73
+ Contributions are welcome.
74
+
75
+ Before opening a PR:
76
+
77
+ - keep the change focused
78
+ - run `bun run check`
79
+ - add or update tests when editor behavior changes
80
+ - open an issue first for larger UX or API changes
81
+
82
+ ## Security
83
+
84
+ Please report security issues privately through GitHub Security Advisories:
85
+
86
+ - <https://github.com/benvinegar/termdraw/security/advisories/new>
87
+
88
+ ## License
89
+
90
+ MIT. See [LICENSE](LICENSE).
package/dist/app.d.ts ADDED
@@ -0,0 +1,71 @@
1
+ import { FrameBufferRenderable, type KeyEvent, type MouseEvent, type OptimizedBuffer, type RenderContext, type RenderableOptions } from "@opentui/core";
2
+ type ChromeMode = "full" | "editor";
3
+ export interface TermDrawRenderableOptions extends RenderableOptions<FrameBufferRenderable> {
4
+ width?: number | "auto" | `${number}%`;
5
+ height?: number | "auto" | `${number}%`;
6
+ respectAlpha?: boolean;
7
+ onSave?: (art: string) => void;
8
+ onCancel?: () => void;
9
+ autoFocus?: boolean;
10
+ showStartupLogo?: boolean;
11
+ cancelOnCtrlC?: boolean;
12
+ footerText?: string;
13
+ chromeMode?: ChromeMode;
14
+ }
15
+ export declare class TermDrawRenderable extends FrameBufferRenderable {
16
+ private readonly state;
17
+ private readonly chromeMode;
18
+ private onSaveCallback;
19
+ private onCancelCallback;
20
+ private autoFocusEnabled;
21
+ private startupLogoEnabled;
22
+ private startupLogoDismissed;
23
+ private cancelOnCtrlCEnabled;
24
+ private footerTextOverride;
25
+ constructor(ctx: RenderContext, options?: TermDrawRenderableOptions);
26
+ set onSave(handler: ((art: string) => void) | undefined);
27
+ set onCancel(handler: (() => void) | undefined);
28
+ set autoFocus(value: boolean | undefined);
29
+ set showStartupLogo(value: boolean | undefined);
30
+ set cancelOnCtrlC(value: boolean | undefined);
31
+ set footerText(value: string | undefined);
32
+ exportArt(): string;
33
+ protected onResize(width: number, height: number): void;
34
+ protected onMouseEvent(event: MouseEvent): void;
35
+ protected renderSelf(buffer: OptimizedBuffer): void;
36
+ handleKeyPress(key: KeyEvent): boolean;
37
+ private dismissStartupLogo;
38
+ private syncCanvasLayout;
39
+ private getLayout;
40
+ private getPaletteButtonLeft;
41
+ private getToolButtons;
42
+ private getBoxStyleButtons;
43
+ private getColorSwatches;
44
+ private isCanvasChromeEvent;
45
+ private drawTooSmallMessage;
46
+ private drawChrome;
47
+ private drawHeaderRow;
48
+ private drawHeaderDivider;
49
+ private drawFooterRow;
50
+ private drawToolPalette;
51
+ private drawToolButton;
52
+ private drawBoxStyleButton;
53
+ private drawColorPicker;
54
+ private drawColorSwatch;
55
+ private drawCanvas;
56
+ private drawStartupLogo;
57
+ private drawOuterSideBorders;
58
+ private drawHorizontalBorder;
59
+ }
60
+ export type TermDrawAppRenderableOptions = Omit<TermDrawRenderableOptions, "chromeMode">;
61
+ export type TermDrawEditorRenderableOptions = Omit<TermDrawRenderableOptions, "chromeMode">;
62
+ export declare class TermDrawAppRenderable extends TermDrawRenderable {
63
+ constructor(ctx: RenderContext, options?: TermDrawAppRenderableOptions);
64
+ }
65
+ export declare class TermDrawEditorRenderable extends TermDrawRenderable {
66
+ constructor(ctx: RenderContext, options?: TermDrawEditorRenderableOptions);
67
+ }
68
+ export declare function formatSavedOutput(art: string, fenced: boolean): string;
69
+ export declare function buildHelpText(binaryName?: string): string;
70
+ export {};
71
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAIrB,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACvB,MAAM,eAAe,CAAC;AAsDvB,KAAK,UAAU,GAAG,MAAM,GAAG,QAAQ,CAAC;AAyIpC,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB,CAAC,qBAAqB,CAAC;IACzF,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC;IACvC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC;IACxC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,qBAAa,kBAAmB,SAAQ,qBAAqB;IAC3D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAY;IAClC,OAAO,CAAC,QAA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