[tcell] 24-bit color support
TAGS=tcell make install printf "\x1b[38;2;100;200;250mTRUECOLOR\x1b[m\n" | TERM=xterm-truecolor fzf --ansi
This commit is contained in:
parent
6f17f412ba
commit
de1c6b8727
14
src/ansi.go
14
src/ansi.go
@ -169,6 +169,8 @@ func interpretCode(ansiCode string, prevState *ansiState) *ansiState {
|
||||
}
|
||||
case 1:
|
||||
switch num {
|
||||
case 2:
|
||||
state256 = 10 // MAGIC
|
||||
case 5:
|
||||
state256++
|
||||
default:
|
||||
@ -177,8 +179,20 @@ func interpretCode(ansiCode string, prevState *ansiState) *ansiState {
|
||||
case 2:
|
||||
*ptr = tui.Color(num)
|
||||
state256 = 0
|
||||
case 10:
|
||||
*ptr = tui.Color(1<<24) | tui.Color(num<<16)
|
||||
state256++
|
||||
case 11:
|
||||
*ptr = *ptr | tui.Color(num<<8)
|
||||
state256++
|
||||
case 12:
|
||||
*ptr = *ptr | tui.Color(num)
|
||||
state256 = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
if state256 > 0 {
|
||||
*ptr = -1
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
@ -295,6 +295,10 @@ func RefreshWindows(windows []*Window) {
|
||||
}
|
||||
|
||||
func PairFor(fg Color, bg Color) ColorPair {
|
||||
// ncurses does not support 24-bit colors
|
||||
if fg.is24() || bg.is24() {
|
||||
return ColDefault
|
||||
}
|
||||
key := (int(fg) << 8) + int(bg)
|
||||
if found, prs := _colorMap[key]; prs {
|
||||
return found
|
||||
|
@ -11,8 +11,9 @@ import (
|
||||
|
||||
"runtime"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/gdamore/tcell/encoding"
|
||||
// https://github.com/gdamore/tcell/pull/135
|
||||
"github.com/junegunn/tcell"
|
||||
"github.com/junegunn/tcell/encoding"
|
||||
|
||||
"github.com/junegunn/go-runewidth"
|
||||
)
|
||||
|
@ -93,7 +93,11 @@ const (
|
||||
doubleClickDuration = 500 * time.Millisecond
|
||||
)
|
||||
|
||||
type Color int16
|
||||
type Color int32
|
||||
|
||||
func (c Color) is24() bool {
|
||||
return c > 0 && (c&(1<<24)) > 0
|
||||
}
|
||||
|
||||
const (
|
||||
colUndefined Color = -2
|
||||
|
Loading…
Reference in New Issue
Block a user