UNPKG

@zqui/react-terminal

Version:

A react component that renders a bash-like terminal.

87 lines (75 loc) 2.56 kB
import * as react_jsx_runtime from 'react/jsx-runtime'; import React, { SetStateAction } from 'react'; type IUserCommands = Record< string, | string | React.JSX.Element | (( args?: any ) => React.JSX.Element | string | void | Promise<string | void>) >; interface ITheme { terminalBg: string; topBarBg: string; promptColor: string; pwdColor: string; textColor: string; predictionColor: string; // TODO: Add topbarPrompt color } declare const themes: Record<string, ITheme>; interface IFile { content: string | React.JSX.Element; } interface IDirectory { [key: string]: IFile | IDirectory; } type DirectoryStructure = IDirectory; type ThemeName = keyof typeof themes; interface ITerminalProps { prompt?: string; commands?: IUserCommands; directoryStructure?: DirectoryStructure; height?: string; width?: string; borderRadius?: string; commandPrediction?: boolean; showTopBar?: boolean; topBarHeight?: string; theme?: ThemeName | ITheme; welcomeMessage?: string | React.JSX.Element; showTopBarPrompt?: boolean; autoCompleteAnimation?: boolean; btn1Callback?: (args: any) => any; btn2Callback?: (args: any) => any; btn3Callback?: (args: any) => any; asyncCommandLoader?: string; asyncCommandLoaderSpeed?: number; } declare const Terminal: ({ prompt, commands, directoryStructure, height, width, borderRadius, commandPrediction, showTopBar, topBarHeight, theme, welcomeMessage, showTopBarPrompt, autoCompleteAnimation, btn1Callback, btn2Callback, btn3Callback, asyncCommandLoader, asyncCommandLoaderSpeed, }: ITerminalProps) => react_jsx_runtime.JSX.Element; type ObjExchange = { command: string; output: string | React.JSX.Element; prompt: string; pwd: string; } type IExchange = | ObjExchange | string | React.JSX.Element; interface ITerminalContext { exchangeHistory: IExchange[]; setExchangeHistory: React.Dispatch<SetStateAction<IExchange[]>>; commandHistory: string[]; setCommandHistory: React.Dispatch<SetStateAction<string[]>>; historyPointer: number; setHistoryPointer: React.Dispatch<SetStateAction<number>>; pwd: string; setPwd: React.Dispatch<SetStateAction<string>>; welcomeMessageCallback: (message: string | React.JSX.Element) => void; } declare const TerminalContext: React.Context<ITerminalContext | null>; declare const TerminalContextProvider: (props: { children: React.ReactNode; }) => react_jsx_runtime.JSX.Element; export { TerminalContext, TerminalContextProvider, Terminal as default };