React hook to get the columns and rows of a stream (likely stdout) in Ink
This library is ESM compatible.
npm install ink-use-stream-dimensions
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
⚠️ 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
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 (
<Box>
<Text>
{columns}x{rows}
</Text>
</Box>
)
}
export default MyApp
This project is licensed under the Unlicense - see the LICENSE file for details.