Skip to content

Commit 52f1ecd

Browse files
committed
refactor: render Scrollable content as React elements
1 parent 68b2493 commit 52f1ecd

File tree

5 files changed

+208
-186
lines changed

5 files changed

+208
-186
lines changed

src/ui/cli/Blocks.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { Box, BoxProps } from 'ink'
33

44
export function Block(props: React.PropsWithChildren<BoxProps>) {
55
return <Box
6-
{...props}
6+
flexShrink={0}
7+
flexGrow={0}
78
flexDirection="column"
89
justifyContent="flex-start"
910
flexWrap="nowrap"
11+
{...props}
1012
/>
1113
}
1214

src/ui/cli/Error.tsx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { StackEntry, XError } from '../../error/XError'
33
import { useTester } from '../TesterContext'
44
import { useSubscribers } from './useSubscribers'
55
import { Text } from 'ink'
6-
import { Scrollable } from './Scrollable'
6+
import { Block, Line } from './Blocks'
77

88
export function StackEntryText({
99
entry,
@@ -19,29 +19,29 @@ export function StackEntryText({
1919
return <Text color="redBright" dimColor>at {String(entry)}</Text>
2020
}
2121

22-
export function* renderError(
23-
error: XError,
24-
renderLine: (l: React.ReactNode, isLast: boolean) => React.ReactNode,
25-
) {
26-
const text = error.text.split('\n')
27-
for(let i = 0; i < text.length; i++) {
28-
yield renderLine((
29-
<Text color="redBright">{text[i]}</Text>
30-
), !error.stackEntries && i === text.length -1)
31-
}
32-
if (error.stackEntries) {
33-
for(let i = 0; i < error.stackEntries.length; i++) {
34-
yield renderLine((
35-
<StackEntryText key={`stackEntry-${i}`} entry={error.stackEntries[i]}/>
36-
), i === error.stackEntries.length -1)
37-
}
38-
}
39-
}
40-
41-
export function ScrollableError({
22+
export function XErrorComponent({
4223
error,
24+
border = false,
4325
}: {
4426
error: XError,
27+
border?: boolean,
4528
}) {
46-
return <Scrollable key={error.stack ?? error.text}>{Array.from(renderError(error, l => l))}</Scrollable>
29+
return <Block>
30+
{error.text.split('\n').map((t, i, a) => (
31+
<Line key={`${i}-${t}`}>
32+
{border && (<Text color="grey" dimColor>{
33+
(!error.stackEntries && i === a.length - 1) ? '╰ ' : '╎ '
34+
}</Text>)}
35+
<Text color="redBright">{t}</Text>
36+
</Line>
37+
))}
38+
{error.stackEntries?.map((entry, i, a) => (
39+
<Line key={`stack-${i}`}>
40+
{border && (<Text color="grey" dimColor>{
41+
(i === a.length - 1) ? '╰ ' : '╎ '
42+
}</Text>)}
43+
<StackEntryText entry={entry}/>
44+
</Line>
45+
))}
46+
</Block>
4747
}

src/ui/cli/Errors.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { TestGroup, TestGroupStack } from '../../conductor/TestRun/TestGroup'
77
import { findNodeFrom, hasError } from './helper'
88
import { TreeExcerpt } from './Tree'
99
import { Element } from './Blocks'
10-
import { ScrollableError } from './Error'
10+
import { Scrollable } from './Scrollable'
11+
import { XErrorComponent } from './Error'
1112

1213
export function Errors({
1314
run,
@@ -102,7 +103,9 @@ export function Errors({
102103
</Box>
103104
)}
104105
<Box height={1}/>
105-
<ScrollableError error={error[0]}/>
106+
<Scrollable key={error[0].stack}>
107+
<XErrorComponent error={error[0]}/>
108+
</Scrollable>
106109
{error.length > 1 && (
107110
<Element>
108111
<Text color="grey">…and {error.length - 1} more on this node/hook</Text>

src/ui/cli/Results.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { Element } from './Blocks'
99
import { FunctionStatusIcon } from './StatusIcons'
1010
import { findNodeFrom } from './helper'
1111
import { NodeConductor } from './Node'
12-
import { ScrollableError } from './Error'
12+
import { Scrollable } from './Scrollable'
13+
import { XErrorComponent } from './Error'
1314

1415
export function Results({
1516
run,
@@ -134,7 +135,9 @@ function Result({
134135
return null
135136
}
136137

137-
return <ScrollableError error={result.error}/>
138+
return <Scrollable key={result.error.stack}>
139+
<XErrorComponent error={result.error}/>
140+
</Scrollable>
138141
}
139142

140143
function nextRunInstance(

0 commit comments

Comments
 (0)