import React, { ComponentPropsWithoutRef } from "react"; import XTermJs, { XTermRef } from "./xtermjs"; import Ionicons from "@expo/vector-icons/Ionicons"; import { ScrollView, Text, TextStyle, View } from "tamagui"; import Pressable from "../ui/pressable"; import Icons from "../ui/icons"; import useThemeStore from "@/stores/theme"; const Keys = { ArrowLeft: "\x1b[D", ArrowRight: "\x1b[C", ArrowUp: "\x1b[A", ArrowDown: "\x1b[B", Enter: "\x0D", Escape: "\x1b", Home: "\x1b[H", End: "\x1b[F", PageUp: "\x1b[5~", PageDown: "\x1b[6~", Alt: "\x1b", Tab: "\x09", }; type XTermJsProps = { client?: "xtermjs"; url: string; }; type TerminalProps = ComponentPropsWithoutRef & XTermJsProps; const Terminal = ({ client = "xtermjs", style, ...props }: TerminalProps) => { const xtermRef = React.useRef(null); const theme = useThemeStore((i) => i.theme); const send = (data: string) => { switch (client) { case "xtermjs": xtermRef.current?.send(data); break; } }; return ( {client === "xtermjs" && ( )} } // onPress={() => send(Keys.Tab)} /> send(Keys.Escape)} /> } onPress={() => send(Keys.Home)} /> } onPress={() => send(Keys.ArrowLeft)} /> } onPress={() => send(Keys.ArrowUp)} /> } onPress={() => send(Keys.ArrowDown)} /> } onPress={() => send(Keys.ArrowRight)} /> send(Keys.Enter)} /> send(Keys.End)} /> send(Keys.PageUp)} /> send(Keys.PageDown)} /> {/* send(Keys.Alt)} /> */} send("\x03")} /> send("\x04")} /> send("\x11")} /> send("\x11")} /> send("\x13")} /> send("\x18")} /> send("\x18")} /> send("\x1a")} /> ); }; const TerminalButton = ({ title, textStyle, ...props }: ComponentPropsWithoutRef & { title: string | React.ReactNode; textStyle?: TextStyle; }) => ( {typeof title === "string" ? {title} : title} ); export default Terminal;