import tcell/v2 from gitlab.com/Provessor/lfp
This commit is contained in:
parent
73d1a81d85
commit
90b3b166e1
2
app.go
2
app.go
@ -13,7 +13,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type cmdItem struct {
|
type cmdItem struct {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func run() {
|
func run() {
|
||||||
|
18
colors.go
18
colors.go
@ -7,7 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type styleMap map[string]tcell.Style
|
type styleMap map[string]tcell.Style
|
||||||
@ -64,6 +64,8 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ECMA-48 details the standard
|
// ECMA-48 details the standard
|
||||||
|
// TODO: should we support turning off attributes?
|
||||||
|
// Probably because this is used for previewers too
|
||||||
for i := 0; i < len(nums); i++ {
|
for i := 0; i < len(nums); i++ {
|
||||||
n := nums[i]
|
n := nums[i]
|
||||||
switch {
|
switch {
|
||||||
@ -79,11 +81,17 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
|
|||||||
st = st.Blink(true)
|
st = st.Blink(true)
|
||||||
case n == 7:
|
case n == 7:
|
||||||
st = st.Reverse(true)
|
st = st.Reverse(true)
|
||||||
|
case n == 8:
|
||||||
|
// TODO: tcell PR for proper conceal
|
||||||
|
_, bg, _ := st.Decompose()
|
||||||
|
st = st.Foreground(bg)
|
||||||
|
case n == 9:
|
||||||
|
st = st.StrikeThrough(true)
|
||||||
case n >= 30 && n <= 37:
|
case n >= 30 && n <= 37:
|
||||||
st = st.Foreground(tcell.Color(n - 30))
|
st = st.Foreground(tcell.PaletteColor(n - 30))
|
||||||
case n == 38:
|
case n == 38:
|
||||||
if i+3 <= len(nums) && nums[i+1] == 5 {
|
if i+3 <= len(nums) && nums[i+1] == 5 {
|
||||||
st = st.Foreground(tcell.Color(nums[i+2]))
|
st = st.Foreground(tcell.PaletteColor(nums[i+2]))
|
||||||
i += 2
|
i += 2
|
||||||
} else if i+5 <= len(nums) && nums[i+1] == 2 {
|
} else if i+5 <= len(nums) && nums[i+1] == 2 {
|
||||||
st = st.Foreground(tcell.NewRGBColor(
|
st = st.Foreground(tcell.NewRGBColor(
|
||||||
@ -95,10 +103,10 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
|
|||||||
log.Printf("unknown ansi code or incorrect form: %d", n)
|
log.Printf("unknown ansi code or incorrect form: %d", n)
|
||||||
}
|
}
|
||||||
case n >= 40 && n <= 47:
|
case n >= 40 && n <= 47:
|
||||||
st = st.Background(tcell.Color(n - 40))
|
st = st.Background(tcell.PaletteColor(n - 40))
|
||||||
case n == 48:
|
case n == 48:
|
||||||
if i+3 <= len(nums) && nums[i+1] == 5 {
|
if i+3 <= len(nums) && nums[i+1] == 5 {
|
||||||
st = st.Background(tcell.Color(nums[i+2]))
|
st = st.Background(tcell.PaletteColor(nums[i+2]))
|
||||||
i += 2
|
i += 2
|
||||||
} else if i+5 <= len(nums) && nums[i+1] == 2 {
|
} else if i+5 <= len(nums) && nums[i+1] == 2 {
|
||||||
st = st.Background(tcell.NewRGBColor(
|
st = st.Background(tcell.NewRGBColor(
|
||||||
|
@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestApplyAnsiCodes(t *testing.T) {
|
func TestApplyAnsiCodes(t *testing.T) {
|
||||||
@ -47,18 +47,18 @@ func TestApplyAnsiCodes(t *testing.T) {
|
|||||||
|
|
||||||
{"38;5;0", none, none.Foreground(tcell.ColorBlack)},
|
{"38;5;0", none, none.Foreground(tcell.ColorBlack)},
|
||||||
{"38;5;1", none, none.Foreground(tcell.ColorMaroon)},
|
{"38;5;1", none, none.Foreground(tcell.ColorMaroon)},
|
||||||
{"38;5;8", none, none.Foreground(tcell.Color(8))},
|
{"38;5;8", none, none.Foreground(tcell.ColorGray)},
|
||||||
{"38;5;16", none, none.Foreground(tcell.Color(16))},
|
{"38;5;16", none, none.Foreground(tcell.Color16)},
|
||||||
{"38;5;232", none, none.Foreground(tcell.Color(232))},
|
{"38;5;232", none, none.Foreground(tcell.Color232)},
|
||||||
|
|
||||||
{"38;5;1", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon)},
|
{"38;5;1", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon)},
|
||||||
{"38;5;1", none.Foreground(tcell.ColorGreen).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true)},
|
{"38;5;1", none.Foreground(tcell.ColorGreen).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||||
|
|
||||||
{"48;5;0", none, none.Background(tcell.ColorBlack)},
|
{"48;5;0", none, none.Background(tcell.ColorBlack)},
|
||||||
{"48;5;1", none, none.Background(tcell.ColorMaroon)},
|
{"48;5;1", none, none.Background(tcell.ColorMaroon)},
|
||||||
{"48;5;8", none, none.Background(tcell.Color(8))},
|
{"48;5;8", none, none.Background(tcell.ColorGray)},
|
||||||
{"48;5;16", none, none.Background(tcell.Color(16))},
|
{"48;5;16", none, none.Background(tcell.Color16)},
|
||||||
{"48;5;232", none, none.Background(tcell.Color(232))},
|
{"48;5;232", none, none.Background(tcell.Color232)},
|
||||||
|
|
||||||
{"48;5;1", none.Background(tcell.ColorGreen), none.Background(tcell.ColorMaroon)},
|
{"48;5;1", none.Background(tcell.ColorGreen), none.Background(tcell.ColorMaroon)},
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ func TestApplyAnsiCodes(t *testing.T) {
|
|||||||
{"48;2;0;48;143", none, none.Background(tcell.NewRGBColor(0, 48, 143))},
|
{"48;2;0;48;143", none, none.Background(tcell.NewRGBColor(0, 48, 143))},
|
||||||
|
|
||||||
// Fixes color construction issue: https://github.com/gokcehan/lf/pull/439#issuecomment-674409446
|
// Fixes color construction issue: https://github.com/gokcehan/lf/pull/439#issuecomment-674409446
|
||||||
{"38;5;34;1", none, none.Foreground(tcell.Color(34)).Bold(true)},
|
{"38;5;34;1", none, none.Foreground(tcell.Color34).Bold(true)},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/gokcehan/lf
|
|||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gdamore/tcell v1.3.0
|
github.com/gdamore/tcell/v2 v2.0.0
|
||||||
github.com/mattn/go-runewidth v0.0.9
|
github.com/mattn/go-runewidth v0.0.9
|
||||||
gopkg.in/djherbis/times.v1 v1.2.0
|
gopkg.in/djherbis/times.v1 v1.2.0
|
||||||
)
|
)
|
||||||
|
12
go.sum
12
go.sum
@ -1,12 +1,10 @@
|
|||||||
github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFDnH08=
|
|
||||||
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
|
||||||
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||||
github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM=
|
github.com/gdamore/tcell/v2 v2.0.0 h1:GRWG8aLfWAlekj9Q6W29bVvkHENc6hp79XOqG4AWDOs=
|
||||||
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
|
github.com/gdamore/tcell/v2 v2.0.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
|
||||||
github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=
|
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
|
||||||
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
|
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10=
|
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10=
|
||||||
|
1
main.go
1
main.go
@ -51,7 +51,6 @@ func exportEnvVars() {
|
|||||||
os.Setenv("EDITOR", envEditor)
|
os.Setenv("EDITOR", envEditor)
|
||||||
os.Setenv("PAGER", envPager)
|
os.Setenv("PAGER", envPager)
|
||||||
os.Setenv("SHELL", envShell)
|
os.Setenv("SHELL", envShell)
|
||||||
os.Setenv("TCELL_TRUECOLOR", envTcellTruecolor)
|
|
||||||
|
|
||||||
level, err := strconv.Atoi(envLevel)
|
level, err := strconv.Atoi(envLevel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
13
os.go
13
os.go
@ -15,11 +15,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
envOpener = os.Getenv("OPENER")
|
envOpener = os.Getenv("OPENER")
|
||||||
envEditor = os.Getenv("EDITOR")
|
envEditor = os.Getenv("EDITOR")
|
||||||
envPager = os.Getenv("PAGER")
|
envPager = os.Getenv("PAGER")
|
||||||
envShell = os.Getenv("SHELL")
|
envShell = os.Getenv("SHELL")
|
||||||
envTcellTruecolor = os.Getenv("TCELL_TRUECOLOR")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -56,10 +55,6 @@ func init() {
|
|||||||
envShell = "sh"
|
envShell = "sh"
|
||||||
}
|
}
|
||||||
|
|
||||||
if envTcellTruecolor == "" {
|
|
||||||
envTcellTruecolor = "disable"
|
|
||||||
}
|
|
||||||
|
|
||||||
u, err := user.Current()
|
u, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("user: %s", err)
|
log.Printf("user: %s", err)
|
||||||
|
@ -12,11 +12,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
envOpener = os.Getenv("OPENER")
|
envOpener = os.Getenv("OPENER")
|
||||||
envEditor = os.Getenv("EDITOR")
|
envEditor = os.Getenv("EDITOR")
|
||||||
envPager = os.Getenv("PAGER")
|
envPager = os.Getenv("PAGER")
|
||||||
envShell = os.Getenv("SHELL")
|
envShell = os.Getenv("SHELL")
|
||||||
envTcellTruecolor = os.Getenv("TCELL_TRUECOLOR")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var envPathExt = os.Getenv("PATHEXT")
|
var envPathExt = os.Getenv("PATHEXT")
|
||||||
|
Loading…
Reference in New Issue
Block a user