| 1 | //go:build windows |
| 2 | |
| 3 | package proc |
| 4 | |
| 5 | import ( |
| 6 | "os/exec" |
| 7 | "syscall" |
| 8 | ) |
| 9 | |
| 10 | const createNoWindow = 0x08000000 // CREATE_NO_WINDOW |
| 11 | |
| 12 | // HideWindow stops a child process from flashing a console window on Windows, |
| 13 | // where a GUI parent (the desktop app) has no console of its own to inherit. |
| 14 | // CREATE_NO_WINDOW suppresses the console a console child (git, rg, a shell) |
| 15 | // would otherwise pop; HideWindow guards any GUI child that shows a window. |
| 16 | func HideWindow(cmd *exec.Cmd) { |
| 17 | if cmd.SysProcAttr == nil { |
| 18 | cmd.SysProcAttr = &syscall.SysProcAttr{} |
| 19 | } |
| 20 | cmd.SysProcAttr.HideWindow = true |
| 21 | cmd.SysProcAttr.CreationFlags |= createNoWindow |
| 22 | } |
| 23 |