1
0
mirror of https://github.com/gdamore/tcell.git synced 2025-04-24 13:48:51 +08:00

fixes #373 Check for and use RGB property in terminfo

This also regenerated some definitions, which should lead to
more accurate mouse mode for a few of the terminals.
This commit is contained in:
Garrett D'Amore 2020-08-30 19:33:25 -07:00
parent 5216188a4f
commit bf3f269ccb
6 changed files with 37 additions and 5 deletions

View File

@ -34,7 +34,7 @@ func init() {
EnterAcs: "\x1b(0",
ExitAcs: "\x1b(B",
Mouse: "\x1b[<",
MouseMode: "%?%p1%{1}%=%t%'h'%Pa%e%'l'%Pa%;\x1b[?1000%ga%c\x1b[?1002%ga%c\x1b[?1003%ga%c\x1b[?1006%ga%c",
MouseMode: "\x1b[?1006;1000%?%p1%{1}%=%th%el%;",
SetCursor: "\x1b[%i%p1%d;%p2%dH",
CursorBack1: "\b",
CursorUp1: "\x1b[A",

View File

@ -34,7 +34,7 @@ func init() {
ExitAcs: "\x0f",
EnableAcs: "\x1b)0",
Mouse: "\x1b[<",
MouseMode: "%?%p1%{1}%=%t%'h'%Pa%e%'l'%Pa%;\x1b[?1000%ga%c\x1b[?1002%ga%c\x1b[?1003%ga%c\x1b[?1006%ga%c",
MouseMode: "\x1b[?1006;1000%?%p1%{1}%=%th%el%;",
SetCursor: "\x1b[%i%p1%d;%p2%dH",
CursorBack1: "\b",
CursorUp1: "\x1b[A",
@ -93,7 +93,7 @@ func init() {
ExitAcs: "\x0f",
EnableAcs: "\x1b)0",
Mouse: "\x1b[<",
MouseMode: "%?%p1%{1}%=%t%'h'%Pa%e%'l'%Pa%;\x1b[?1000%ga%c\x1b[?1002%ga%c\x1b[?1003%ga%c\x1b[?1006%ga%c",
MouseMode: "\x1b[?1006;1000%?%p1%{1}%=%th%el%;",
SetCursor: "\x1b[%i%p1%d;%p2%dH",
CursorBack1: "\b",
CursorUp1: "\x1b[A",

View File

@ -132,7 +132,7 @@ func unescape(s string) string {
}
func (tc *termcap) setupterm(name string) error {
cmd := exec.Command("infocmp", "-1", name)
cmd := exec.Command("infocmp", "-x", "-1", name)
output := &bytes.Buffer{}
cmd.Stdout = output
@ -362,6 +362,24 @@ func getinfo(name string) (*terminfo.Terminfo, string, error) {
t.KeyCtrlEnd = "\x1b[8^"
}
// Technically the RGB flag that is provided for xterm-direct is not
// quite right. The problem is that the -direct flag that was introduced
// with ncurses 6.1 requires a parsing for the parameters that we lack.
// For this case we'll just assume it's XTerm compatible. Someday this
// may be incorrect, but right now it is correct, and nobody uses it
// anyway.
if tc.getflag("Tc") {
// This presumes XTerm 24-bit true color.
t.TrueColor = true
} else if tc.getflag("RGB") {
// This is for xterm-direct, which uses a different scheme entirely.
// (ncurses went a very different direction from everyone else, and
// so it's unlikely anything is using this definition.)
t.TrueColor = true
t.SetBg = "\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m"
t.SetFg = "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m"
}
// If the kmous entry is present, then we need to record the
// the codes to enter and exit mouse mode. Sadly, this is not
// part of the terminfo databases anywhere that I've found, but
@ -427,6 +445,13 @@ func dotGoAddStr(w io.Writer, n string, s string) {
}
fmt.Fprintf(w, "\t\t%-13s %q,\n", n+":", s)
}
func dotGoAddFlag(w io.Writer, n string, b bool) {
if !b {
// initialized to 0, ignore
return
}
fmt.Fprintf(w, "\t\t%-13s true,\n", n+":")
}
func dotGoAddArr(w io.Writer, n string, a []string) {
if len(a) == 0 {
@ -596,6 +621,7 @@ func dotGoInfo(w io.Writer, terms []*TData) {
dotGoAddStr(w, "KeyCtrlHome", t.KeyCtrlHome)
dotGoAddStr(w, "KeyCtrlEnd", t.KeyCtrlEnd)
dotGoAddInt(w, "Modifiers", t.Modifiers)
dotGoAddFlag(w, "TrueColor", t.TrueColor)
fmt.Fprintln(w, "\t})")
}
fmt.Fprintln(w, "}")

View File

@ -65,6 +65,7 @@ func init() {
KeyClear: "\x1b[3;5~",
KeyBacktab: "\x1b[Z",
Modifiers: 1,
TrueColor: true,
})
// simpleterm with 256 colors
@ -126,5 +127,6 @@ func init() {
KeyClear: "\x1b[3;5~",
KeyBacktab: "\x1b[Z",
Modifiers: 1,
TrueColor: true,
})
}

View File

@ -212,6 +212,7 @@ type Terminfo struct {
KeyMetaShfHome string
KeyMetaShfEnd string
Modifiers int
TrueColor bool // true if the terminal supports direct color
}
const (
@ -737,7 +738,9 @@ func LookupTerminfo(name string) (*Terminfo, error) {
// If the name ends in -truecolor, then fabricate an entry
// from the corresponding -256color, -color, or bare terminal.
if t == nil && strings.HasSuffix(name, "-truecolor") {
if t.TrueColor {
addtruecolor = true
} else if t == nil && strings.HasSuffix(name, "-truecolor") {
suffixes := []string{
"-256color",

View File

@ -62,5 +62,6 @@ func init() {
KeyF12: "\x1b[24~",
KeyBacktab: "\x1b[Z",
Modifiers: 1,
TrueColor: true,
})
}