I've tried a lot of ways, like
package main
import (
"os"
"os/exec"
)
func main() {
c := exec.Command("cls")
c.Stdout = os.Stdout
c.Run()
}
and
C.system(C.CString("cls"))
And the escape sequence doesn't work either
There's really no easy way to do this in a cross-platform way using the standard libraries.
termbox-go
seems to be one library providing cross-platform terminal control. There are probably others, but it's the only one I've used and it seems to work well.
Clearing the console using termbox-go
would be a matter of doing a Clear
and then a Flush
.
See http://godoc.org/github.com/nsf/termbox-go for more details.
All you need is :
package main
import (
"os"
"os/exec"
)
func main() {
cmd := exec.Command("cmd", "/c", "cls")
cmd.Stdout = os.Stdout
cmd.Run()
}
For linux and mac in case someone needs it:
fmt.Println("\033[2J")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With