forked from charmbracelet/bubbletea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtty.go
51 lines (41 loc) · 733 Bytes
/
tty.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package tea
import (
"errors"
)
var errInputIsNotAFile = errors.New("input is not a file")
func (p *Program) initTerminal() error {
err := p.initInput()
if err != nil {
return err
}
if p.inputIsTTY {
if p.console == nil {
return errors.New("no console")
}
err = p.console.SetRaw()
if err != nil {
return err
}
}
if p.outputIsTTY {
enableAnsiColors(p.output)
hideCursor(p.output)
}
return nil
}
func (p Program) restoreTerminal() error {
if p.outputIsTTY {
showCursor(p.output)
}
if err := p.restoreInput(); err != nil {
return err
}
// Console will only be set if input is a TTY.
if p.console != nil {
err := p.console.Reset()
if err != nil {
return err
}
}
return nil
}