diff --git a/terminfo/a/alacritty/term.go b/terminfo/a/alacritty/term.go index bb5fa7b..4cc2a13 100644 --- a/terminfo/a/alacritty/term.go +++ b/terminfo/a/alacritty/term.go @@ -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", diff --git a/terminfo/k/konsole/term.go b/terminfo/k/konsole/term.go index 57faa66..4545633 100644 --- a/terminfo/k/konsole/term.go +++ b/terminfo/k/konsole/term.go @@ -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", diff --git a/terminfo/mkinfo.go b/terminfo/mkinfo.go index 175fdec..a715a0d 100644 --- a/terminfo/mkinfo.go +++ b/terminfo/mkinfo.go @@ -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, "}") diff --git a/terminfo/s/simpleterm/term.go b/terminfo/s/simpleterm/term.go index bee4fbc..5caa17e 100644 --- a/terminfo/s/simpleterm/term.go +++ b/terminfo/s/simpleterm/term.go @@ -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, }) } diff --git a/terminfo/terminfo.go b/terminfo/terminfo.go index a789d4e..4f29534 100644 --- a/terminfo/terminfo.go +++ b/terminfo/terminfo.go @@ -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", diff --git a/terminfo/x/xterm_kitty/term.go b/terminfo/x/xterm_kitty/term.go index 1dde744..1437893 100644 --- a/terminfo/x/xterm_kitty/term.go +++ b/terminfo/x/xterm_kitty/term.go @@ -62,5 +62,6 @@ func init() { KeyF12: "\x1b[24~", KeyBacktab: "\x1b[Z", Modifiers: 1, + TrueColor: true, }) }