Skip to content

Clear screen in Golang

Clear screen output in Golang

with exec

package main

import (
    "os"
    "os/exec"
)

func main(){
    fmt.println("hello world")
    cmd := exec.Comand("clear")
    cmd.Stdout = os.Stdout
    cmd.Run()
}

with ANSI

fmt.Printf("\x1bc")
// from bottom

// OR

fmt.Printf("\x1b[2J")
// from top