import React, { ComponentPropsWithoutRef } from "react"; import XTermJs, { XTermRef } from "./xtermjs"; import Ionicons from "@expo/vector-icons/Ionicons"; import { Pressable, ScrollView, StyleProp, StyleSheet, Text, TextStyle, View, } from "react-native"; 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 TerminalProps = ComponentPropsWithoutRef & { wsUrl: string; }; const Terminal = ({ wsUrl, style, ...props }: TerminalProps) => { const ref = React.useRef(null); const send = (data: string) => { ref.current?.send(data); }; return ( } 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?: StyleProp; }) => ( [styles.btn, pressed && styles.btnPressed]} {...props} > {typeof title === "string" ? ( {title} ) : ( title )} ); const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#232323", }, buttons: { display: "flex", flexDirection: "row", alignItems: "stretch", backgroundColor: "#232323", }, btn: { display: "flex", justifyContent: "center", alignItems: "center", paddingHorizontal: 14, paddingVertical: 10, }, btnPressed: { backgroundColor: "#3a3a3a", }, btnText: { color: "white", fontSize: 16, }, }); export default Terminal;