@opentui/react 0.1.8 → 0.1.10

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 CHANGED
@@ -39,6 +39,7 @@ OpenTUI React provides several built-in components that map to OpenTUI core rend
39
39
  - **`<input>`** - Text input field
40
40
  - **`<select>`** - Selection dropdown
41
41
  - **`<tab-select>`** - Tab-based selection
42
+ - **`<ascii-font>`** - Display ASCII art text with different font styles
42
43
 
43
44
  ### Styling
44
45
 
@@ -135,6 +136,29 @@ function MyComponent() {
135
136
  }
136
137
  ```
137
138
 
139
+ #### `useTerminalDimensions()`
140
+
141
+ Get current terminal dimensions and automatically update when the terminal is resized.
142
+
143
+ ```tsx
144
+ import { useTerminalDimensions } from "@opentui/react"
145
+
146
+ function MyComponent() {
147
+ const { width, height } = useTerminalDimensions()
148
+
149
+ return (
150
+ <group>
151
+ <text>Terminal dimensions: {width}x{height}</text>
152
+ <box style={{ width: Math.floor(width / 2), height: Math.floor(height / 3) }}>
153
+ <text>Half-width, third-height box</text>
154
+ </box>
155
+ </group>
156
+ )
157
+ }
158
+ ```
159
+
160
+ **Returns:** An object with `width` and `height` properties representing the current terminal dimensions.
161
+
138
162
  ## Components
139
163
 
140
164
  ### Text Component
@@ -274,6 +298,67 @@ function SelectExample() {
274
298
  }
275
299
  ```
276
300
 
301
+ ### ASCII Font Component
302
+
303
+ Display ASCII art text with different font styles.
304
+
305
+ ```tsx
306
+ import { measureText } from "@opentui/core"
307
+ import { useState } from "react"
308
+
309
+ function ASCIIFontExample() {
310
+ const text = "ASCII"
311
+ const [font, setFont] = useState<"block" | "shade" | "slick" | "tiny">("tiny")
312
+
313
+ const { width, height } = measureText({
314
+ text,
315
+ font,
316
+ })
317
+
318
+ return (
319
+ <group style={{ paddingLeft: 1, paddingRight: 1 }}>
320
+ <box
321
+ style={{
322
+ height: 8,
323
+ marginBottom: 1,
324
+ }}
325
+ >
326
+ <select
327
+ focused
328
+ onChange={(_, option) => setFont(option?.value)}
329
+ showScrollIndicator
330
+ options={[
331
+ {
332
+ name: "Tiny",
333
+ description: "Tiny font",
334
+ value: "tiny",
335
+ },
336
+ {
337
+ name: "Block",
338
+ description: "Block font",
339
+ value: "block",
340
+ },
341
+ {
342
+ name: "Slick",
343
+ description: "Slick font",
344
+ value: "slick",
345
+ },
346
+ {
347
+ name: "Shade",
348
+ description: "Shade font",
349
+ value: "shade",
350
+ },
351
+ ]}
352
+ style={{ flexGrow: 1 }}
353
+ />
354
+ </box>
355
+
356
+ <ascii-font style={{ width, height }} text={text} font={font} />
357
+ </group>
358
+ )
359
+ }
360
+ ```
361
+
277
362
  ## Examples
278
363
 
279
364
  ### Login Form
package/index.js CHANGED
@@ -65,6 +65,20 @@ var useOnResize = (callback) => {
65
65
  }, [renderer, callback]);
66
66
  return renderer;
67
67
  };
68
+ // src/hooks/use-terminal-dimensions.tsx
69
+ import { useState } from "react";
70
+ var useTerminalDimensions = () => {
71
+ const renderer = useRenderer();
72
+ const [dimensions, setDimensions] = useState({
73
+ width: renderer.terminalWidth,
74
+ height: renderer.terminalHeight
75
+ });
76
+ const cb = (width, height) => {
77
+ setDimensions({ width, height });
78
+ };
79
+ useOnResize(cb);
80
+ return dimensions;
81
+ };
68
82
  // src/reconciler/renderer.ts
69
83
  import { createCliRenderer, getKeyHandler } from "@opentui/core";
70
84
  import React from "react";
@@ -407,6 +421,7 @@ async function render(node, rendererConfig = {}) {
407
421
  _render(React.createElement(AppContext.Provider, { value: { keyHandler, renderer } }, node), renderer.root);
408
422
  }
409
423
  export {
424
+ useTerminalDimensions,
410
425
  useRenderer,
411
426
  useOnResize,
412
427
  useKeyboard,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "type": "module",
7
- "version": "0.1.8",
7
+ "version": "0.1.10",
8
8
  "description": "React renderer for building terminal user interfaces using OpenTUI core",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -35,7 +35,7 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@opentui/core": "0.1.8",
38
+ "@opentui/core": "0.1.10",
39
39
  "react-reconciler": "^0.32.0"
40
40
  },
41
41
  "devDependencies": {
@@ -0,0 +1,4 @@
1
+ export declare const useTerminalDimensions: () => {
2
+ width: number;
3
+ height: number;
4
+ };
package/src/index.d.ts CHANGED
@@ -3,5 +3,6 @@ export * from "./components/app";
3
3
  export * from "./hooks/use-keyboard";
4
4
  export * from "./hooks/use-renderer";
5
5
  export * from "./hooks/use-resize";
6
+ export * from "./hooks/use-terminal-dimensions";
6
7
  export * from "./reconciler/renderer";
7
8
  export * from "./types/components";