https://github.com/gowikel/ink-use-stream-dimensions
React hook to get the columns and rows of a stream (likely stdout) in Ink
https://github.com/gowikel/ink-use-stream-dimensions
command-line console dimensions ink ink-hook react stdout stdout-stream stream terminal
Last synced: 6 months ago
JSON representation
React hook to get the columns and rows of a stream (likely stdout) in Ink
- Host: GitHub
- URL: https://github.com/gowikel/ink-use-stream-dimensions
- Owner: gowikel
- License: unlicense
- Created: 2024-05-08T15:25:21.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-14T00:40:07.000Z (about 2 years ago)
- Last Synced: 2025-10-19T01:01:26.803Z (9 months ago)
- Topics: command-line, console, dimensions, ink, ink-hook, react, stdout, stdout-stream, stream, terminal
- Language: TypeScript
- Homepage:
- Size: 272 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ink-use-stream-dimensions
> React hook to get the columns and rows of a stream (likely stdout) in [Ink](https://github.com/vadimdemedes/ink)
This library is ESM compatible.
## Install
```
npm install ink-use-stream-dimensions
```
## API
### `useStreamDimensions(stdout: ConsoleStream): [number, number]`
`ConsoleStream` is any type that contais:
- rows as a `number`
- columns as a `number`
- on, handler with signature `(event: "resize", callback: () => void) => void`
- off, handler with signature `(event: "resize", callback: () => void) => void`
(`useStdout` returns the `stdout` object which already has that signature)
It returns the columns and rows, and subscribes to changes to them
## Example
> :warning: This is my first published package. I am trying to make it compatible with ESM and CJS. If you find any
> issue importing the library, feel free to file a bug
```javascript
import React from 'react'
import { Box, Text, useStdout } from "ink"
import { useStreamDimensions } from "ink-use-stream-dimensions"
function MyApp() {
const { stdout } = useStdout()
const [columns, rows] = useStreamDimensions(stdout)
return (
{columns}x{rows}
)
}
export default MyApp
```
## License
This project is licensed under the Unlicense - see the [LICENSE](LICENSE) file for details.