Rename files, improve keyboard usability
This commit is contained in:
@@ -29,6 +29,7 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
|
||||
const lastSentSizeRef = useRef<{ cols: number; rows: number } | null>(null);
|
||||
const pendingSizeRef = useRef<{ cols: number; rows: number } | null>(null);
|
||||
const notifyTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const overlayTextareaRef = useRef<HTMLTextAreaElement | null>(null);
|
||||
const DEBOUNCE_MS = 140;
|
||||
|
||||
useEffect(() => {
|
||||
@@ -111,7 +112,7 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
|
||||
};
|
||||
|
||||
textarea.addEventListener('focus', preventKeyboard);
|
||||
textarea.blur(); // Initial blur
|
||||
textarea.blur();
|
||||
|
||||
return () => {
|
||||
textarea.removeEventListener('focus', preventKeyboard);
|
||||
@@ -119,6 +120,27 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
|
||||
}
|
||||
}, [terminal]);
|
||||
|
||||
function syncOverlay() {
|
||||
if (!terminal || !overlayTextareaRef.current) return;
|
||||
const buffer = terminal.buffer.active;
|
||||
let text = "";
|
||||
for (let i = 0; i < buffer.length; i++) {
|
||||
text += buffer.getLine(i)?.translateToString() + "\n";
|
||||
}
|
||||
overlayTextareaRef.current.value = text;
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!terminal) return;
|
||||
syncOverlay();
|
||||
|
||||
const disposeRender = terminal.onRender(() => syncOverlay());
|
||||
|
||||
return () => {
|
||||
disposeRender.dispose();
|
||||
};
|
||||
}, [terminal]);
|
||||
|
||||
function handleWindowResize() {
|
||||
if (!isVisibleRef.current) return;
|
||||
fitAddonRef.current?.fit();
|
||||
@@ -169,7 +191,7 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
|
||||
if (!terminal || !xtermRef.current || !hostConfig) return;
|
||||
|
||||
terminal.options = {
|
||||
cursorBlink: true,
|
||||
cursorBlink: false,
|
||||
cursorStyle: 'bar',
|
||||
scrollback: 10000,
|
||||
fontSize: 14,
|
||||
@@ -184,6 +206,8 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
|
||||
fastScrollModifier: 'alt',
|
||||
fastScrollSensitivity: 5,
|
||||
allowProposedApi: true,
|
||||
disableStdin: true,
|
||||
cursorInactiveStyle: "bar",
|
||||
};
|
||||
|
||||
const fitAddon = new FitAddon();
|
||||
@@ -276,10 +300,26 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={xtermRef}
|
||||
className="h-full w-full m-1"
|
||||
style={{opacity: visible && isVisible ? 1 : 0, overflow: 'hidden'}}
|
||||
/>
|
||||
className="h-full w-full m-1 relative"
|
||||
style={{ opacity: visible && isVisible ? 1 : 0 }}
|
||||
>
|
||||
<div ref={xtermRef} className="h-full w-full" />
|
||||
|
||||
<textarea
|
||||
ref={overlayTextareaRef}
|
||||
readOnly
|
||||
className="absolute top-0 left-0 w-full h-full"
|
||||
style={{
|
||||
opacity: 0.01,
|
||||
cursor: "text",
|
||||
background: "none",
|
||||
border: "none",
|
||||
resize: "none",
|
||||
userSelect: "text",
|
||||
WebkitUserSelect: "text",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user