Text user interface for golang.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
596 B

package tui
import (
"io"
"os"
"sync"
"golang.org/x/term"
)
var (
lock = sync.Mutex{}
t *term.Terminal
oldState *term.State
)
func Start() {
lock.Lock()
defer lock.Unlock()
if t != nil {
return
}
screen := struct {
io.Reader
io.Writer
}{os.Stdin, os.Stdout}
var err error
oldState, err = term.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
t = term.NewTerminal(screen, "")
t.SetSize(80, 24)
}
func Stop() {
lock.Lock()
defer lock.Unlock()
if t == nil {
return
}
term.Restore(int(os.Stdin.Fd()), oldState)
t = nil
oldState = nil
}