Elffuss BraidHub

kikocis/continue public

main · 1.4 KiBRawPermalink
1import { Box, Text, useInput } from "ink";
2import React, { useEffect } from "react";
3
4import { ColoredDiff } from "./ColoredDiff.js";
5
6interface DiffViewerProps {
7 diffContent: string;
8 onClose: () => void;
9}
10
11/**
12 * Full-screen diff viewer overlay
13 * Shows diff content with syntax highlighting and allows closing with ESC
14 */
15export const DiffViewer: React.FC<DiffViewerProps> = ({
16 diffContent,
17 onClose,
18}) => {
19 // Handle ESC key to close the diff viewer
20 useInput((input, key) => {
21 if (key.escape) {
22 onClose();
23 }
24 });
25
26 // Auto-focus when component mounts
27 useEffect(() => {
28 // Component is already focused by default in Ink
29 }, []);
30
31 return (
32 <Box
33 flexDirection="column"
34 height="100%"
35 borderStyle="single"
36 borderColor="blue"
37 padding={1}
38 >
39 {/* Header */}
40 <Box marginBottom={1}>
41 <Text color="blue" bold>
42 Git Diff (Press ESC to close)
43 </Text>
44 </Box>
45
46 {/* Diff content - scrollable */}
47 <Box flexDirection="column" flexGrow={1} overflow="hidden">
48 {diffContent.trim() ? (
49 <ColoredDiff diffContent={diffContent} />
50 ) : (
51 <Text color="gray" italic>
52 No changes to display
53 </Text>
54 )}
55 </Box>
56
57 {/* Footer */}
58 <Box marginTop={1} justifyContent="center">
59 <Text color="gray" dimColor>
60 ESC to close
61 </Text>
62 </Box>
63 </Box>
64 );
65};