Changesets · Branches · Tags · Compare
| Changeset | 097e009e2978f54bcf694a49aaba2323a672f2a55c2a5915d884fa2c7415ab5b |
|---|---|
| Author | Saim <saimadib2002@gmail.com> · 2025-05-20 08:52 +05:30 |
| Committer | Saim <saimadib2002@gmail.com> · 2025-05-20 08:52 +05:30 |
| Parents | 5bee654fd479 |
1 file changed
modified gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/RunInTerminalButton.tsx +28 −4
| @@ -18,14 +18,38 @@ | ||
| 18 | 18 | |
| 19 | 19 | // Extract just the command line (the line after $ or the first line) |
| 20 | 20 | function extractCommand(cmd: string): string { |
| 21 | - // If the command contains a $ prompt, extract the line after it | |
| 21 | + // First handle the $ prompt case, extract the line after it | |
| 22 | 22 | if (cmd.includes("$")) { |
| 23 | 23 | const match = cmd.match(/\$\s*([^\n]+)/); |
| 24 | - return match ? match[1].trim() : ""; | |
| 24 | + if (match) { | |
| 25 | + return match[1].trim(); | |
| 26 | + } | |
| 25 | 27 | } |
| 26 | 28 | |
| 27 | - // Otherwise, just take the first line | |
| 28 | - return cmd.split("\n")[0].trim(); | |
| 29 | + // Process all lines, filtering out comments and empty lines | |
| 30 | + const lines = cmd.split("\n") | |
| 31 | + .map(line => line.trim()) | |
| 32 | + .filter(line => | |
| 33 | + line && | |
| 34 | + !line.startsWith("#") && | |
| 35 | + !line.startsWith("//") && | |
| 36 | + !line.startsWith("/*") | |
| 37 | + ); | |
| 38 | + | |
| 39 | + // Handle multi-line commands | |
| 40 | + let result = ""; | |
| 41 | + for (let i = 0; i < lines.length; i++) { | |
| 42 | + const line = lines[i]; | |
| 43 | + result += line; | |
| 44 | + | |
| 45 | + // Add space for command continuation | |
| 46 | + if (line.endsWith("&&") || line.endsWith("|") || line.endsWith("\\")) { | |
| 47 | + result += " "; | |
| 48 | + } else if (i < lines.length - 1) { | |
| 49 | + result += " "; | |
| 50 | + } | |
| 51 | + } | |
| 52 | + return result.trim(); | |
| 29 | 53 | } |
| 30 | 54 | |
| 31 | 55 | function runInTerminal() { |