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 }