Terminal control/Clear the screen: Difference between revisions
→{{header|Go}}: add ansi, ncurses examples
No edit summary |
(→{{header|Go}}: add ansi, ncurses examples) |
||
Line 125:
=={{header|Go}}==
===Shell command===
Probably most reliable way to clear the screen.
<lang go>package main
Line 136 ⟶ 138:
c.Stdout = os.Stdout
c.Run()
}</lang>
===ANSI escape code===
Simplest, if your terminal supports the ANSI code you want.
<lang go>package main
import "fmt"
func main() {
fmt.Print("\033[2J")
}</lang>
===Ncurses===
More complex, but works across multiple terminal types.
{{libheader|curses}}
<lang go>package main
import (
"log"
"time"
"code.google.com/p/goncurses"
)
func main() {
s, err := goncurses.Init()
if err != nil {
log.Fatal("goncurses:", err)
}
defer goncurses.End()
s.Println("Clearing screen...")
s.Refresh()
time.Sleep(1 * time.Second)
s.Clear() // clear screen
// Goncurses saves the screen on Init and restores it on End. This
// GetChar() allows you to see the effect of the program before it exits.
s.GetChar() // press any key to continue
}</lang>
|