mirror of https://github.com/gdamore/tcell.git
Add NewTerminfoScreenFromTtyTerminfo to allow creating Screen using (#479)
custom terminfo as well as custom tty.
This commit is contained in:
parent
edd0f2f203
commit
2f3199b286
39
tscreen.go
39
tscreen.go
|
@ -46,19 +46,36 @@ func NewTerminfoScreen() (Screen, error) {
|
||||||
return NewTerminfoScreenFromTty(nil)
|
return NewTerminfoScreenFromTty(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTerminfoScreenFromTty returns a Screen using a custom Tty implementation.
|
// LookupTerminfo attempts to find a definition for the named $TERM falling
|
||||||
// If the passed in tty is nil, then a reasonable default (typically /dev/tty)
|
// back to attempting to parse the output from infocmp.
|
||||||
// is presumed, at least on UNIX hosts. (Windows hosts will typically fail this
|
func LookupTerminfo(name string) (ti *terminfo.Terminfo, e error) {
|
||||||
// call altogether.)
|
ti, e = terminfo.LookupTerminfo(name)
|
||||||
func NewTerminfoScreenFromTty(tty Tty) (Screen, error) {
|
|
||||||
ti, e := terminfo.LookupTerminfo(os.Getenv("TERM"))
|
|
||||||
if e != nil {
|
if e != nil {
|
||||||
ti, e = loadDynamicTerminfo(os.Getenv("TERM"))
|
ti, e = loadDynamicTerminfo(name)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
terminfo.AddTerminfo(ti)
|
terminfo.AddTerminfo(ti)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTerminfoScreenFromTtyTerminfo returns a Screen using a custom Tty
|
||||||
|
// implementation and custom terminfo specification.
|
||||||
|
// If the passed in tty is nil, then a reasonable default (typically /dev/tty)
|
||||||
|
// is presumed, at least on UNIX hosts. (Windows hosts will typically fail this
|
||||||
|
// call altogether.)
|
||||||
|
// If passed terminfo is nil, then TERM environment variable is queried for
|
||||||
|
// terminal specification.
|
||||||
|
func NewTerminfoScreenFromTtyTerminfo(tty Tty, ti *terminfo.Terminfo) (s Screen, e error) {
|
||||||
|
if ti == nil {
|
||||||
|
ti, e = LookupTerminfo(os.Getenv("TERM"))
|
||||||
|
if e != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
t := &tScreen{ti: ti, tty: tty}
|
t := &tScreen{ti: ti, tty: tty}
|
||||||
|
|
||||||
t.keyexist = make(map[Key]bool)
|
t.keyexist = make(map[Key]bool)
|
||||||
|
@ -77,6 +94,14 @@ func NewTerminfoScreenFromTty(tty Tty) (Screen, error) {
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTerminfoScreenFromTty returns a Screen using a custom Tty implementation.
|
||||||
|
// If the passed in tty is nil, then a reasonable default (typically /dev/tty)
|
||||||
|
// is presumed, at least on UNIX hosts. (Windows hosts will typically fail this
|
||||||
|
// call altogether.)
|
||||||
|
func NewTerminfoScreenFromTty(tty Tty) (Screen, error) {
|
||||||
|
return NewTerminfoScreenFromTtyTerminfo(tty, nil)
|
||||||
|
}
|
||||||
|
|
||||||
// tKeyCode represents a combination of a key code and modifiers.
|
// tKeyCode represents a combination of a key code and modifiers.
|
||||||
type tKeyCode struct {
|
type tKeyCode struct {
|
||||||
key Key
|
key Key
|
||||||
|
|
Loading…
Reference in New Issue