-
-
Notifications
You must be signed in to change notification settings - Fork 656
/
Copy pathrenderer.ts
56 lines (44 loc) · 1.38 KB
/
renderer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import Yoga from 'yoga-layout-prebuilt';
import renderNodeToOutput from './render-node-to-output.js';
import Output from './output.js';
import {type DOMElement} from './dom.js';
type Result = {
output: string;
outputHeight: number;
staticOutput: string;
};
const renderer = (node: DOMElement, terminalWidth: number): Result => {
node.yogaNode!.setWidth(terminalWidth);
if (node.yogaNode) {
node.yogaNode.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
const output = new Output({
width: node.yogaNode.getComputedWidth(),
height: node.yogaNode.getComputedHeight()
});
renderNodeToOutput(node, output, {skipStaticElements: true});
let staticOutput;
if (node.staticNode?.yogaNode) {
staticOutput = new Output({
width: node.staticNode.yogaNode.getComputedWidth(),
height: node.staticNode.yogaNode.getComputedHeight()
});
renderNodeToOutput(node.staticNode, staticOutput, {
skipStaticElements: false
});
}
const {output: generatedOutput, height: outputHeight} = output.get();
return {
output: generatedOutput,
outputHeight,
// Newline at the end is needed, because static output doesn't have one, so
// interactive output will override last line of static output
staticOutput: staticOutput ? `${staticOutput.get().output}\n` : ''
};
}
return {
output: '',
outputHeight: 0,
staticOutput: ''
};
};
export default renderer;