-
Notifications
You must be signed in to change notification settings - Fork 31
/
screen.go
44 lines (35 loc) · 883 Bytes
/
screen.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
// Copyright 2022 Graham Clark. All rights reserved. Use of this source
// code is governed by the MIT license that can be found in the LICENSE
// file.
//
// +build !windows
package gowid
import (
"os"
tcell "github.com/gdamore/tcell/v2"
)
//======================================================================
func tcellScreen(ttys string) (tcell.Screen, error) {
var tty tcell.Tty
var err error
tty, err = tcell.NewDevTtyFromDev(bestTty(ttys))
if err != nil {
return nil, WithKVs(err, map[string]interface{}{"tty": ttys})
}
return tcell.NewTerminfoScreenFromTty(tty)
}
func bestTty(tty string) string {
if tty != "" {
return tty
}
gwtty := os.Getenv("GOWID_TTY")
if gwtty != "" {
return gwtty
}
return "/dev/tty"
}
//======================================================================
// Local Variables:
// mode: Go
// fill-column: 110
// End: