ink-sdl 0.1.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 Derek Petersen
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,189 @@
1
+ # ink-sdl
2
+
3
+ Render [Ink](https://github.com/vadimdemedes/ink) TUI applications to an SDL window instead of the terminal.
4
+
5
+ ## Features
6
+
7
+ - Full ANSI color support (16, 256, and 24-bit true color)
8
+ - Keyboard input with modifier keys (Ctrl, Shift, Alt)
9
+ - Window resizing with automatic terminal dimension updates
10
+ - HiDPI/Retina display support
11
+ - Glyph caching for efficient text rendering
12
+ - Bundled monospace font (Cozette)
13
+
14
+ ## Prerequisites
15
+
16
+ You need SDL2 and SDL2_ttf installed on your system:
17
+
18
+ **macOS:**
19
+
20
+ ```bash
21
+ brew install sdl2 sdl2_ttf
22
+ ```
23
+
24
+ **Ubuntu/Debian:**
25
+
26
+ ```bash
27
+ apt install libsdl2-2.0-0 libsdl2-ttf-2.0-0
28
+ ```
29
+
30
+ **Fedora:**
31
+
32
+ ```bash
33
+ dnf install SDL2 SDL2_ttf
34
+ ```
35
+
36
+ **Windows:**
37
+ Download SDL2.dll and SDL2_ttf.dll from [libsdl.org](https://libsdl.org) and place them in your system path.
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ npm install ink-sdl
43
+ # or
44
+ pnpm add ink-sdl
45
+ ```
46
+
47
+ ## Demo
48
+
49
+ To run the included example:
50
+
51
+ ```bash
52
+ git clone https://github.com/anthropics/ink-sdl.git
53
+ cd ink-sdl
54
+ pnpm install
55
+ pnpm exec tsx examples/hello.tsx
56
+ ```
57
+
58
+ > **Note:** This project uses [pnpm](https://pnpm.io/) for development. You can install and use ink-sdl in your own project with npm or pnpm, but if you're contributing to the library itself, use pnpm.
59
+
60
+ ## Usage
61
+
62
+ ```tsx
63
+ import React, { useState, useEffect } from "react";
64
+ import { render, Text, Box } from "ink";
65
+ import { createSdlStreams } from "ink-sdl";
66
+
67
+ const App = () => {
68
+ const [count, setCount] = useState(0);
69
+
70
+ useEffect(() => {
71
+ const timer = setInterval(() => {
72
+ setCount((c) => c + 1);
73
+ }, 1_000);
74
+ return () => clearInterval(timer);
75
+ }, []);
76
+
77
+ return (
78
+ <Box flexDirection="column" padding={1}>
79
+ <Text color="green" bold>
80
+ Hello from SDL!
81
+ </Text>
82
+ <Text>
83
+ Counter: <Text color="cyan">{count}</Text>
84
+ </Text>
85
+ </Box>
86
+ );
87
+ };
88
+
89
+ // Create SDL streams
90
+ const { stdin, stdout, window } = createSdlStreams({
91
+ title: "My App",
92
+ width: 800,
93
+ height: 600,
94
+ });
95
+
96
+ // Render the Ink app
97
+ render(<App />, { stdin, stdout });
98
+
99
+ // Handle window close
100
+ window.on("close", () => process.exit(0));
101
+ ```
102
+
103
+ ## API
104
+
105
+ ### `createSdlStreams(options?)`
106
+
107
+ Creates stdin/stdout streams and a window for use with Ink.
108
+
109
+ #### Options
110
+
111
+ | Option | Type | Default | Description |
112
+ | ------------- | ---------------- | ----------- | ------------------------------------------ |
113
+ | `title` | `string` | `"ink-sdl"` | Window title |
114
+ | `width` | `number` | `800` | Window width in pixels |
115
+ | `height` | `number` | `600` | Window height in pixels |
116
+ | `vsync` | `boolean` | `true` | Enable vertical sync |
117
+ | `fontSize` | `number` | `11` | Font size in points |
118
+ | `scaleFactor` | `number \| null` | `null` | Override scale factor (null = auto-detect) |
119
+
120
+ #### Returns
121
+
122
+ ```typescript
123
+ {
124
+ stdin: SdlInputStream; // Readable stream for keyboard input
125
+ stdout: SdlOutputStream; // Writable stream for ANSI output
126
+ window: SdlWindow; // Window wrapper with events
127
+ }
128
+ ```
129
+
130
+ ### `SdlWindow`
131
+
132
+ Event emitter for window events.
133
+
134
+ #### Events
135
+
136
+ - `close` - Emitted when the window is closed
137
+ - `key` - Emitted on keyboard events
138
+
139
+ #### Methods
140
+
141
+ - `getDimensions()` - Returns `{ columns, rows }` for terminal size
142
+ - `setTitle(title)` - Set the window title
143
+ - `clear()` - Clear the screen
144
+ - `close()` - Close the window
145
+ - `isClosed()` - Check if window is closed
146
+
147
+ ### `isSdlAvailable()`
148
+
149
+ Check if SDL is available on the system.
150
+
151
+ ```typescript
152
+ import { isSdlAvailable } from "ink-sdl";
153
+
154
+ if (isSdlAvailable()) {
155
+ // Use SDL rendering
156
+ } else {
157
+ // Fall back to terminal rendering
158
+ }
159
+ ```
160
+
161
+ ## Advanced Usage
162
+
163
+ For more control, you can use the lower-level components directly:
164
+
165
+ ```typescript
166
+ import {
167
+ SdlUiRenderer,
168
+ AnsiParser,
169
+ TextRenderer,
170
+ InputBridge,
171
+ getSDL2,
172
+ getSDL_ttf,
173
+ } from "ink-sdl";
174
+ ```
175
+
176
+ ## Keyboard Support
177
+
178
+ The following keys are mapped to terminal sequences:
179
+
180
+ - Arrow keys (Up, Down, Left, Right)
181
+ - Enter, Escape, Backspace, Tab, Delete
182
+ - Home, End, Page Up, Page Down
183
+ - Function keys (F1-F12)
184
+ - Ctrl+A through Ctrl+Z
185
+ - Shift for uppercase letters
186
+
187
+ ## License
188
+
189
+ MIT