I tried many ways, for example
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
All you need is:
package main import ( "os" "os/exec" ) func main() { cmd := exec.Command("cmd", "/c", "cls") cmd.Stdout = os.Stdout cmd.Run() }
There is really no easy way to do this in a cross-platform way using standard libraries.
termbox-go seems to be one library that provides cross-platform terminal management. There may be others, but this is the only one I used and it seems to work well.
termbox-go
Removing the console using termbox-go would be a Clear question, and then Flush .
Clear
Flush
See http://godoc.org/github.com/nsf/termbox-go for more details.
For Linux and Mac, if anyone needs it:
fmt.Println("\033[2J")
If you look at the Play Conway of Life playground, you can see how they clean the terminal using special instructions:
//line 110 fmt.Print("\x0c", l)