| 1 | import { CommandLineIcon } from "@heroicons/react/24/outline"; |
| 2 | import { useContext } from "react"; |
| 3 | import { lightGray, vscForeground } from "../.."; |
| 4 | import { IdeMessengerContext } from "../../../context/IdeMessenger"; |
| 5 | import { extractCommand } from "../utils/commandExtractor"; |
| 6 | |
| 7 | interface RunInTerminalButtonProps { |
| 8 | command: string; |
| 9 | } |
| 10 | |
| 11 | export function RunInTerminalButton({ command }: RunInTerminalButtonProps) { |
| 12 | const ideMessenger = useContext(IdeMessengerContext); |
| 13 | |
| 14 | function runInTerminal() { |
| 15 | // Extract just the command line |
| 16 | const extractedCommand = extractCommand(command); |
| 17 | void ideMessenger.post("runCommand", { command: extractedCommand }); |
| 18 | } |
| 19 | |
| 20 | return ( |
| 21 | <div |
| 22 | className={`text-lightgray flex items-center border-none bg-transparent text-xs text-[${vscForeground}] cursor-pointer outline-none hover:brightness-125`} |
| 23 | onClick={runInTerminal} |
| 24 | > |
| 25 | <div |
| 26 | className="max-2xs:hidden flex items-center gap-1 transition-colors duration-200 hover:brightness-125" |
| 27 | style={{ color: lightGray }} |
| 28 | > |
| 29 | <> |
| 30 | <CommandLineIcon className="h-3 w-3 hover:brightness-125" /> |
| 31 | <span className="text-lightgray max-sm:hidden">Run</span> |
| 32 | </> |
| 33 | </div> |
| 34 | </div> |
| 35 | ); |
| 36 | } |