0
0
Fork 0

tui: add plain-text Viewer (highlighting deferred)

<Viewer pou text scrollTop visibleRows/> renders a POU's source as
line-numbered text (4-col padding) with a bold header
'<name>.st (<kind>, <loc> L)'. Falls back to a dim '(no POU
selected)' when pou or text is null.

No syntax highlighting in v0.1 — that's intentional and tracked as
deferred. Smoke build only; render behavior is exercised through the
browser-mode integration tests in subsequent tasks.
This commit is contained in:
Karstein Phobic Nyvold Kvistad 2026-04-28 22:22:06 +02:00
parent 9902cd6dcf
commit 0aef1fe009

View file

@ -0,0 +1,34 @@
import React from 'react';
import { Box, Text } from 'ink';
import { POU } from '../shared/types.js';
export interface ViewerProps {
pou: POU | null;
text: string | null;
scrollTop: number;
visibleRows: number;
}
export function Viewer({ pou, text, scrollTop, visibleRows }: ViewerProps): React.ReactElement {
if (!pou || text == null) {
return (
<Box flexDirection="column">
<Text dimColor>(no POU selected)</Text>
</Box>
);
}
const lines = text.split(/\r?\n/);
const slice = lines.slice(scrollTop, scrollTop + visibleRows);
return (
<Box flexDirection="column">
<Text bold>
{pou.name}.st ({pou.kind}, {pou.loc} L)
</Text>
{slice.map((l, i) => (
<Text key={scrollTop + i}>
{String(scrollTop + i + 1).padStart(4, ' ')} {l}
</Text>
))}
</Box>
);
}