Terminal
shadcn-collections/terminalFreeComponent
Terminal component for command line interfaces
Install it
npx shadcn@latest add https://chatcn.me/r/terminal.jsonSource
1import { cn } from "@/lib/utils";2import {3 createContext,4 useState,5 ReactNode,6 useContext,7 useEffect,8 useRef,9} from "react";10import { createPortal } from "react-dom";1112type TerminalState = "normal" | "minimize" | "maximize";1314type TerminalEntry = {15 command: string;16 output: React.ReactNode | string;17};1819type TerminalContextType = {20 terminalState: TerminalState;21 setTerminalState: React.Dispatch<React.SetStateAction<TerminalState>>;22 terminalHistory: TerminalEntry[];23 setTerminalHistory: React.Dispatch<React.SetStateAction<TerminalEntry[]>>;24};2526const TerminalContext = createContext<TerminalContextType>({27 terminalState: "normal",28 setTerminalState: () => {},29 terminalHistory: [],30 setTerminalHistory: () => {},31});3233type TerminalProviderProps = {34 children: ReactNode;35 initialState?: TerminalState;36};3738export function TerminalProvider({39 children,40 initialState = "normal",41}: TerminalProviderProps) {42 const [terminalState, setTerminalState] =43 useState<TerminalState>(initialState);44 const [terminalHistory, setTerminalHistory] = useState<TerminalEntry[]>([45 {46 command: "help",47 output: (48 <div>49 <div>Available commands:</div>50 <ul className="list-disc ml-6">51 <li>whoami</li>52 <li>help</li>53 <li>clear</li>54 </ul>55 </div>56 ),57 },58 ]);5960 return (61 <TerminalContext.Provider62 value={{63 terminalState,64 setTerminalState,65 terminalHistory,66 setTerminalHistory,67 }}68 >69 {children}70 </TerminalContext.Provider>71 );72}7374export function useTerminal() {75 const context = useContext(TerminalContext);76 if (!context) {77 throw new Error("useTerminal must be used within a TerminalProvider");78 }79 return context;80}8182type TerminalProps = {83 children: ReactNode;84 className?: string;85};8687function getTerminalPositionClasses(state: TerminalState): string {88 switch (state) {89 case "maximize":90 return "fixed inset-0 w-screen h-screen z-[9999] rounded-none text-sm";91 case "minimize":92 return "fixed bottom-3 left-1/2 -translate-x-1/2 h-auto z-[9999] cursor-pointer";93 case "normal":94 default:95 return "relative h-auto";96 }97}9899function getTerminalOutput(command: string): string | React.ReactNode {100 const cmd = command.trim();101 switch (cmd) {102 case "whoami":103 return (104 <div>105 Hi Im Sanku 21 year old dev I love{" "}106// … truncated
Files it writes
More from shadcn-collections
All 24 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Audio Visualizeraudio-visualizer | shadcn-collections | Components | Free | 4 deps | |
| Calendarcalendar | shadcn-collections | Components | Free | no deps | |
| Chat Containerchat-container | shadcn-collections | Components | Free | no deps | |
| Code Editorcode-editor | shadcn-collections | Components | Free | no deps | |
| Code Blockcodeblock | shadcn-collections | Components | Free | 1 dep | |
| Command Blockcommand-block | shadcn-collections | Components | Free | no deps | |
| Command Tabscommand-tabs | shadcn-collections | Components | Free | no deps | |
| Emailemail | shadcn-collections | Components | Free | no deps |
