Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/crutchcorn/codewrapper. A modular, framework-agnostic library for building interactive code editors codewrapper.vercel.app
Something went wrong. Try again.
12345678910111213141516171819202122232425import { initTerm } from "@codewrapper/core";import { forwardRef, useCallback, useLayoutEffect, useState } from "react";import { assignRef } from "./utils";import { Terminal as XTermTerminal } from "@xterm/xterm";
export const Terminal = forwardRef<XTermTerminal>((_, ref) => { const [containerEl, setContainerEl] = useState<HTMLDivElement>();
useLayoutEffect(() => { if (!containerEl) return; const term = initTerm(); if (ref) assignRef(ref, term); term.open(containerEl); return () => { term.dispose(); }; }, [containerEl]);
return ( <div ref={useCallback((view: HTMLDivElement) => setContainerEl(view), [])} /> );});