codev / src /ink /components /StdoutContext.tsx
chenbhao's picture
feat: add useStdout and useIsScreenReaderEnabled hooks for ink-picture
f73174f
Raw
History Blame Contribute Delete
681 Bytes
import { createContext, useContext } from 'react'
export type Props = {
readonly stdout: NodeJS.WriteStream & { readonly rows: number; readonly columns: number }
/**
* Write any string to stdout while preserving Ink's output.
* Useful for emitting raw escape sequences (e.g. image protocols)
* outside of Ink's normal render loop.
*/
readonly write: (data: string) => void
}
const StdoutContext = createContext<Props>({
stdout: process.stdout as NodeJS.WriteStream & { rows: number; columns: number },
write() {},
})
StdoutContext.displayName = 'StdoutContext'
export default StdoutContext
export function useStdout(): Props {
return useContext(StdoutContext)
}