import tcell/v2 from gitlab.com/Provessor/lfp

This commit is contained in:
Gokcehan 2020-12-04 23:59:12 +03:00
parent 73d1a81d85
commit 90b3b166e1
10 changed files with 38 additions and 39 deletions

2
app.go
View File

@ -13,7 +13,7 @@ import (
"syscall"
"time"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
type cmdItem struct {

View File

@ -10,7 +10,7 @@ import (
"strings"
"time"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
func run() {

View File

@ -7,7 +7,7 @@ import (
"strconv"
"strings"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
type styleMap map[string]tcell.Style
@ -64,6 +64,8 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
}
// 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++ {
n := nums[i]
switch {
@ -79,11 +81,17 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
st = st.Blink(true)
case n == 7:
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:
st = st.Foreground(tcell.Color(n - 30))
st = st.Foreground(tcell.PaletteColor(n - 30))
case n == 38:
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
} else if i+5 <= len(nums) && nums[i+1] == 2 {
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)
}
case n >= 40 && n <= 47:
st = st.Background(tcell.Color(n - 40))
st = st.Background(tcell.PaletteColor(n - 40))
case n == 48:
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
} else if i+5 <= len(nums) && nums[i+1] == 2 {
st = st.Background(tcell.NewRGBColor(

View File

@ -3,7 +3,7 @@ package main
import (
"testing"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
func TestApplyAnsiCodes(t *testing.T) {
@ -47,18 +47,18 @@ func TestApplyAnsiCodes(t *testing.T) {
{"38;5;0", none, none.Foreground(tcell.ColorBlack)},
{"38;5;1", none, none.Foreground(tcell.ColorMaroon)},
{"38;5;8", none, none.Foreground(tcell.Color(8))},
{"38;5;16", none, none.Foreground(tcell.Color(16))},
{"38;5;232", none, none.Foreground(tcell.Color(232))},
{"38;5;8", none, none.Foreground(tcell.ColorGray)},
{"38;5;16", none, none.Foreground(tcell.Color16)},
{"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).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"48;5;0", none, none.Background(tcell.ColorBlack)},
{"48;5;1", none, none.Background(tcell.ColorMaroon)},
{"48;5;8", none, none.Background(tcell.Color(8))},
{"48;5;16", none, none.Background(tcell.Color(16))},
{"48;5;232", none, none.Background(tcell.Color(232))},
{"48;5;8", none, none.Background(tcell.ColorGray)},
{"48;5;16", none, none.Background(tcell.Color16)},
{"48;5;232", none, none.Background(tcell.Color232)},
{"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))},
// 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 {

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/gokcehan/lf
go 1.12
require (
github.com/gdamore/tcell v1.3.0
github.com/gdamore/tcell/v2 v2.0.0
github.com/mattn/go-runewidth v0.0.9
gopkg.in/djherbis/times.v1 v1.2.0
)

12
go.sum
View File

@ -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/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM=
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/gdamore/tcell/v2 v2.0.0 h1:GRWG8aLfWAlekj9Q6W29bVvkHENc6hp79XOqG4AWDOs=
github.com/gdamore/tcell/v2 v2.0.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
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/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10=

View File

@ -51,7 +51,6 @@ func exportEnvVars() {
os.Setenv("EDITOR", envEditor)
os.Setenv("PAGER", envPager)
os.Setenv("SHELL", envShell)
os.Setenv("TCELL_TRUECOLOR", envTcellTruecolor)
level, err := strconv.Atoi(envLevel)
if err != nil {

13
os.go
View File

@ -15,11 +15,10 @@ import (
)
var (
envOpener = os.Getenv("OPENER")
envEditor = os.Getenv("EDITOR")
envPager = os.Getenv("PAGER")
envShell = os.Getenv("SHELL")
envTcellTruecolor = os.Getenv("TCELL_TRUECOLOR")
envOpener = os.Getenv("OPENER")
envEditor = os.Getenv("EDITOR")
envPager = os.Getenv("PAGER")
envShell = os.Getenv("SHELL")
)
var (
@ -56,10 +55,6 @@ func init() {
envShell = "sh"
}
if envTcellTruecolor == "" {
envTcellTruecolor = "disable"
}
u, err := user.Current()
if err != nil {
log.Printf("user: %s", err)

View File

@ -12,11 +12,10 @@ import (
)
var (
envOpener = os.Getenv("OPENER")
envEditor = os.Getenv("EDITOR")
envPager = os.Getenv("PAGER")
envShell = os.Getenv("SHELL")
envTcellTruecolor = os.Getenv("TCELL_TRUECOLOR")
envOpener = os.Getenv("OPENER")
envEditor = os.Getenv("EDITOR")
envPager = os.Getenv("PAGER")
envShell = os.Getenv("SHELL")
)
var envPathExt = os.Getenv("PATHEXT")

2
ui.go
View File

@ -15,7 +15,7 @@ import (
"unicode"
"unicode/utf8"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/mattn/go-runewidth"
)