diff --git a/examples/counter-full-height/counter-full-height.tsx b/examples/counter-full-height/counter-full-height.tsx new file mode 100644 index 00000000..5e21661d --- /dev/null +++ b/examples/counter-full-height/counter-full-height.tsx @@ -0,0 +1,24 @@ +import React from 'react'; +import {Box, render, Text} from '../../src/index.js'; + +function CounterFullHeight() { + const [counter, setCounter] = React.useState(0); + + React.useEffect(() => { + const timer = setInterval(() => { + setCounter(prevCounter => prevCounter + 1); // eslint-disable-line unicorn/prevent-abbreviations + }, 100); + + return () => { + clearInterval(timer); + }; + }, []); + + return ( + + {counter} tests passed + + ); +} + +render(, {fullHeight: true}); diff --git a/examples/counter-full-height/index.ts b/examples/counter-full-height/index.ts new file mode 100644 index 00000000..7642cffe --- /dev/null +++ b/examples/counter-full-height/index.ts @@ -0,0 +1 @@ +import './counter-full-height.js'; diff --git a/src/ink.tsx b/src/ink.tsx index 7b88589c..2685bc31 100644 --- a/src/ink.tsx +++ b/src/ink.tsx @@ -24,6 +24,7 @@ export type Options = { debug: boolean; exitOnCtrlC: boolean; patchConsole: boolean; + fullHeight?: boolean; waitUntilExit?: () => Promise; }; @@ -130,6 +131,9 @@ export default class Ink { const terminalWidth = this.options.stdout.columns || 80; this.rootNode.yogaNode!.setWidth(terminalWidth); + if (this.options.fullHeight && this.options.stdout.rows) { + this.rootNode.yogaNode!.setHeight(this.options.stdout.rows); + } this.rootNode.yogaNode!.calculateLayout( undefined, diff --git a/src/render.ts b/src/render.ts index 7893f211..f0e65dc4 100644 --- a/src/render.ts +++ b/src/render.ts @@ -41,6 +41,12 @@ export type RenderOptions = { * @default true */ patchConsole?: boolean; + /** + * If true, render output will use all avaliable height (rows) + * + * @default undefined + */ + fullHeight?: boolean; }; export type Instance = {