Add truecolor support for Windows, if available (#2156)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
- Update to latest tcell which has 24 bit Windows support - light renderer under Windows defaults to Dark256, if possible - Respect TCELL_TRUECOLOR - Remove tcell 1.3 references
authored by Michael Kelley · committed by GitHub · parent f2d44ab · Browse files · 5 files·+25 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+25 added−15 removed
- other:+25 added−15 removed
Provenance
- Commit
ae15eda- Tree
0e4c371- Author
Michael Kelley <michael.a.kelley@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
f2d44ab
5 files changed+25 added−15 removed
modified:src/tui/light_unix.go+13 added
3 unmodified lines4 5 import (6 "fmt"7 "os"8+ "os/exec"9+ "strings"10 "syscall"11 12 "github.com/junegunn/fzf/src/util"13 "golang.org/x/crypto/ssh/terminal"2 unmodified lines16 func IsLightRendererSupported() bool {17 return true18 }19 20+func (r *LightRenderer) defaultTheme() *ColorTheme {21+ if strings.Contains(os.Getenv("TERM"), "256") {22+ return Dark25623+ }24+ colors, err := exec.Command("tput", "colors").Output()25+ if err == nil && atoi(strings.TrimSpace(string(colors)), 16) > 16 {26+ return Dark25627+ }28+ return Default1629+}30+31 func (r *LightRenderer) fd() int {32 return int(r.ttyin.Fd())33 }34 76 unmodified linesmodified:src/tui/light_windows.go+8 added
32 unmodified lines33 windows.SetConsoleMode(windows.Stderr, oldState)34 return canSetVt10035 }36 37+func (r *LightRenderer) defaultTheme() *ColorTheme {38+ // the getenv check is borrowed from here: https://github.com/gdamore/tcell/commit/0c473b86d82f68226a142e96cc5a34c5a29b3690#diff-b008fcd5e6934bf31bc3d33bf49f47d8R178:39+ if !IsLightRendererSupported() || os.Getenv("ConEmuPID") != "" || os.Getenv("TCELL_TRUECOLOR") == "disable" {40+ return Default1641+ }42+ return Dark25643+}44+45 func (r *LightRenderer) initPlatform() error {46 //outHandle := windows.Stdout47 outHandle, _ := syscall.Open("CONOUT$", syscall.O_RDWR, 0)48 // enable vt100 emulation (https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences)92 unmodified linesmodified:src/tui/light.go-12 removed
1 unmodified line2 3 import (4 "fmt"5 "os"6- "os/exec"6 "regexp"7 "strconv"8 "strings"9 "time"114 unmodified lines124 maxHeightFunc: maxHeightFunc}125 return &r126 }127 129-func (r *LightRenderer) defaultTheme() *ColorTheme {130- if strings.Contains(os.Getenv("TERM"), "256") {131- return Dark256132- }133- colors, err := exec.Command("tput", "colors").Output()134- if err == nil && atoi(strings.TrimSpace(string(colors)), 16) > 16 {135- return Dark256136- }137- return Default16138-}139-128 func repeat(r rune, times int) string {129 if times > 0 {130 return strings.Repeat(string(r), times)131 }792 unmodified linesmodified:go.mod+1 added-1 removed
1 module github.com/junegunn/fzf2 3 require (4- github.com/gdamore/tcell v1.3.04+ github.com/gdamore/tcell v1.4.05 github.com/lucasb-eyer/go-colorful v1.0.3 // indirect6 github.com/mattn/go-isatty v0.0.127 github.com/mattn/go-runewidth v0.0.88 github.com/mattn/go-shellwords v1.0.97 unmodified linesmodified:go.sum+3 added-2 removed
1 github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=2 github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=3 github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=4-github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM=5-github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=4+github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU=5+github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0=6 github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=7 github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=8 github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=9 github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=10 github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=11 github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=12 github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=13 github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=14+github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=15 github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuujKs0=16 github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=17 github.com/mattn/go-shellwords v1.0.9 h1:eaB5JspOwiKKcHdqcjbfe5lA9cNn/4NRRtddXJCimqk=18 github.com/mattn/go-shellwords v1.0.9/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=27 unmodified lines