| 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 { isJetBrains } from "../../../util"; |
| 6 | import { extractCommand } from "../utils/commandExtractor"; |
| 7 | |
| 8 | interface RunInTerminalButtonProps { |
| 9 | command: string; |
| 10 | } |
| 11 | |
| 12 | export function RunInTerminalButton({ command }: RunInTerminalButtonProps) { |
| 13 | const ideMessenger = useContext(IdeMessengerContext); |
| 14 | |
| 15 | if (isJetBrains()) { |
| 16 | // JetBrains plugin doesn't currently have a way to run the command in the terminal for the user |
| 17 | return null; |
| 18 | } |
| 19 | |
| 20 | function runInTerminal() { |
| 21 | // Extract just the command line |
| 22 | const extractedCommand = extractCommand(command); |
| 23 | void ideMessenger.post("runCommand", { command: extractedCommand }); |
| 24 | } |
| 25 | |
| 26 | return ( |
| 27 | <div |
| 28 | className={`text-lightgray flex items-center border-none bg-transparent text-xs text-[${vscForeground}] cursor-pointer outline-none hover:brightness-125`} |
| 29 | onClick={runInTerminal} |
| 30 | > |
| 31 | <div |
| 32 | className="max-2xs:hidden flex items-center gap-1 transition-colors duration-200 hover:brightness-125" |
| 33 | style={{ color: lightGray }} |
| 34 | > |
| 35 | <> |
| 36 | <CommandLineIcon className="h-3 w-3 hover:brightness-125" /> |
| 37 | <span className="text-lightgray max-sm:hidden">Run</span> |
| 38 | </> |
| 39 | </div> |
| 40 | </div> |
| 41 | ); |
| 42 | } |