A finished block; `columns`: the window's width when it is written (rows are fitted to it).
({ block, columns }: { block: Block; columns: number })
| 67 | |
| 68 | /** A finished block; `columns`: the window's width when it is written (rows are fitted to it). */ |
| 69 | function BlockView({ block, columns }: { block: Block; columns: number }) { |
| 70 | const { unicode, shade } = useTheme(); |
| 71 | const roles = useRoles(); |
| 72 | const body = (() => { |
| 73 | switch (block.kind) { |
| 74 | case "header": |
| 75 | return ( |
| 76 | <Welcome |
| 77 | version={block.version} |
| 78 | model={block.model} |
| 79 | keyed={block.keyed} |
| 80 | news={block.news} |
| 81 | columns={columns} |
| 82 | /> |
| 83 | ); |
| 84 | case "question": { |
| 85 | // A block of its own across the window: shaded where the background is known, else the text in |
| 86 | // bold; a blank row above and below either way. Lines after the first sit under the text. |
| 87 | const rows = block.text.split("\n").map((line, index) => ( |
| 88 | // A wrapped line stays under the text, not under the prompt. |
| 89 | // biome-ignore lint/suspicious/noArrayIndexKey: the lines of one finished block never change |
| 90 | <Box key={index}> |
| 91 | <Box width={2} flexShrink={0}> |
| 92 | <Text {...roles.detail}>{index === 0 ? "›" : ""}</Text> |
| 93 | </Box> |
| 94 | <Text bold={!shade}>{printable(line) || " "}</Text> |
| 95 | </Box> |
| 96 | )); |
| 97 | return ( |
| 98 | <Box |
| 99 | flexDirection="column" |
| 100 | paddingY={1} |
| 101 | width={columns} |
| 102 | {...(shade ? { backgroundColor: shade } : {})} |
| 103 | > |
| 104 | {rows} |
| 105 | </Box> |
| 106 | ); |
| 107 | } |
| 108 | case "message": |
| 109 | // Laid out here, row by row, exactly as the live region showed it. |
| 110 | return ( |
| 111 | <Box flexDirection="column"> |
| 112 | {answerRows(withoutBlankEdges(block.text), { columns, unicode, lead: block.lead === true }).map( |
| 113 | (row, index) => ( |
| 114 | // biome-ignore lint/suspicious/noArrayIndexKey: the rows of one finished block never change |
| 115 | <Text key={index} wrap="truncate"> |
| 116 | {row || " "} |
| 117 | </Text> |
| 118 | ), |
| 119 | )} |
| 120 | </Box> |
| 121 | ); |
| 122 | case "lines": |
| 123 | // As wide as the window, so a wrapped row wraps here, under its column, not again in the terminal. |
| 124 | return ( |
| 125 | <Box flexDirection="column" paddingLeft={2} width={columns}> |
| 126 | {block.lines.map((line, index) => { |
nothing calls this directly
no test coverage detected