import { Readable , ReadableOptions } from 'stream' ; export interface ResizableStream { columns : number ; rows : number ; on ( event , cb ) : void ; } export interface TerminalSize { height : number ; width : number ; } export class TerminalSizeQueue extends Readable { constructor ( opts = { } ) { super ( { ... opts , read ( ) { } , } ) ; } public handleResizes ( writeStream ) { this . resize ( getTerminalSize ( writeStream ) ) ; writeStream . on ( 'resize' , ( ) => this . resize ( getTerminalSize ( writeStream ) ) ) ; } private resize ( size ) { this . push ( JSON . stringify ( size ) ) ; } } export function isResizable ( stream ) { if ( stream == null ) { return false ; } const hasRows = 'rows' in stream ; const hasColumns = 'columns' in stream ; const hasOn = typeof stream . on === 'function' ; return hasRows && hasColumns && hasOn ; } function getTerminalSize ( writeStream ) { return { height : writeStream . rows ! , width : writeStream . columns ! } ; }