Skip to content

Commit 9fa04e2

Browse files
committed
Add option to render using full available height (rows)
1 parent 57a4b21 commit 9fa04e2

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import {Box, render, Text} from '../../src/index.js';
3+
4+
function CounterFullHeight() {
5+
const [counter, setCounter] = React.useState(0);
6+
7+
React.useEffect(() => {
8+
const timer = setInterval(() => {
9+
setCounter(prevCounter => prevCounter + 1); // eslint-disable-line unicorn/prevent-abbreviations
10+
}, 100);
11+
12+
return () => {
13+
clearInterval(timer);
14+
};
15+
}, []);
16+
17+
return (
18+
<Box borderStyle="round" flexGrow={1}>
19+
<Text color="green">{counter} tests passed</Text>
20+
</Box>
21+
);
22+
}
23+
24+
render(<CounterFullHeight />, {fullHeight: true});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './counter-full-height.js';

src/ink.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type Options = {
2424
debug: boolean;
2525
exitOnCtrlC: boolean;
2626
patchConsole: boolean;
27+
fullHeight?: boolean;
2728
waitUntilExit?: () => Promise<void>;
2829
};
2930

@@ -130,6 +131,9 @@ export default class Ink {
130131
const terminalWidth = this.options.stdout.columns || 80;
131132

132133
this.rootNode.yogaNode!.setWidth(terminalWidth);
134+
if (this.options.fullHeight && this.options.stdout.rows) {
135+
this.rootNode.yogaNode!.setHeight(this.options.stdout.rows);
136+
}
133137

134138
this.rootNode.yogaNode!.calculateLayout(
135139
undefined,

src/render.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ export type RenderOptions = {
4141
* @default true
4242
*/
4343
patchConsole?: boolean;
44+
/**
45+
* If true, render output will use all avaliable height (rows)
46+
*
47+
* @default undefined
48+
*/
49+
fullHeight?: boolean;
4450
};
4551

4652
export type Instance = {

0 commit comments

Comments
 (0)