commit c9dc688
Hubert Hirtz
·
2020-10-18 14:37:46 +0000 UTC
parent a387410
Update tcell to v2 and - enable bracketed paste - use hex color codes instead of ansi
M
app.go
+12,
-7
1@@ -10,12 +10,13 @@ import (
2
3 "git.sr.ht/~taiite/senpai/irc"
4 "git.sr.ht/~taiite/senpai/ui"
5- "github.com/gdamore/tcell"
6+ "github.com/gdamore/tcell/v2"
7 )
8
9 type App struct {
10- win *ui.UI
11- s *irc.Session
12+ win *ui.UI
13+ s *irc.Session
14+ pasting bool
15
16 cfg Config
17 highlights []string
18@@ -122,7 +123,9 @@ func (app *App) handleIRCEvents(evs []irc.Event) {
19 for _, ev := range evs {
20 app.handleIRCEvent(ev)
21 }
22- app.draw()
23+ if !app.pasting {
24+ app.draw()
25+ }
26 }
27
28 func (app *App) handleIRCEvent(ev irc.Event) {
29@@ -222,14 +225,14 @@ func (app *App) handleUIEvent(ev tcell.Event) {
30 switch ev := ev.(type) {
31 case *tcell.EventResize:
32 app.win.Resize()
33- app.draw()
34+ case *tcell.EventPaste:
35+ app.pasting = ev.Start()
36 case *tcell.EventKey:
37 switch ev.Key() {
38 case tcell.KeyCtrlC:
39 app.win.Exit()
40 case tcell.KeyCtrlL:
41 app.win.Resize()
42- app.draw()
43 case tcell.KeyCtrlU, tcell.KeyPgUp:
44 app.win.ScrollUp()
45 if app.s == nil {
46@@ -305,7 +308,9 @@ func (app *App) handleUIEvent(ev tcell.Event) {
47 default:
48 return
49 }
50- app.draw()
51+ if !app.pasting {
52+ app.draw()
53+ }
54 }
55
56 func (app *App) isHighlight(content string) bool {
+1,
-1
1@@ -8,7 +8,7 @@ import (
2 "time"
3
4 "git.sr.ht/~taiite/senpai"
5- "github.com/gdamore/tcell"
6+ "github.com/gdamore/tcell/v2"
7 )
8
9 func init() {
M
go.mod
+1,
-1
1@@ -3,7 +3,7 @@ module git.sr.ht/~taiite/senpai
2 go 1.14
3
4 require (
5- github.com/gdamore/tcell v1.4.0
6+ github.com/gdamore/tcell/v2 v2.0.0
7 github.com/mattn/go-runewidth v0.0.7
8 gopkg.in/yaml.v2 v2.3.0
9 )
M
go.sum
+2,
-2
1@@ -1,7 +1,7 @@
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.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU=
5-github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0=
6+github.com/gdamore/tcell/v2 v2.0.0 h1:GRWG8aLfWAlekj9Q6W29bVvkHENc6hp79XOqG4AWDOs=
7+github.com/gdamore/tcell/v2 v2.0.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
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-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
+1,
-1
1@@ -6,7 +6,7 @@ import (
2 "strings"
3 "time"
4
5- "github.com/gdamore/tcell"
6+ "github.com/gdamore/tcell/v2"
7 )
8
9 func IsSplitRune(r rune) bool {
+1,
-1
1@@ -1,7 +1,7 @@
2 package ui
3
4 import (
5- "github.com/gdamore/tcell"
6+ "github.com/gdamore/tcell/v2"
7 )
8
9 type Completion struct {
+21,
-5
1@@ -1,7 +1,7 @@
2 package ui
3
4 import (
5- "github.com/gdamore/tcell"
6+ "github.com/gdamore/tcell/v2"
7 "github.com/mattn/go-runewidth"
8 )
9
10@@ -177,12 +177,16 @@ const (
11 ColorRed
12 )
13
14-var ansiCodes = []tcell.Color{
15- // Taken from <https://modern.ircdocs.horse/formatting.html>
16+// Taken from <https://modern.ircdocs.horse/formatting.html>
17+
18+var baseCodes = []tcell.Color{
19 tcell.ColorWhite, tcell.ColorBlack, tcell.ColorBlue, tcell.ColorGreen,
20 tcell.ColorRed, tcell.ColorBrown, tcell.ColorPurple, tcell.ColorOrange,
21 tcell.ColorYellow, tcell.ColorLightGreen, tcell.ColorTeal, tcell.ColorLightCyan,
22 tcell.ColorLightBlue, tcell.ColorPink, tcell.ColorGrey, tcell.ColorLightGrey,
23+}
24+
25+var ansiCodes = []uint64{
26 /* 16-27 */ 52, 94, 100, 58, 22, 29, 23, 24, 17, 54, 53, 89,
27 /* 28-39 */ 88, 130, 142, 64, 28, 35, 30, 25, 18, 91, 90, 125,
28 /* 40-51 */ 124, 166, 184, 106, 34, 49, 37, 33, 19, 129, 127, 161,
29@@ -192,11 +196,23 @@ var ansiCodes = []tcell.Color{
30 /* 88-98 */ 16, 233, 235, 237, 239, 241, 244, 247, 250, 254, 231,
31 }
32
33+var hexCodes = []int32{
34+ 0x470000, 0x472100, 0x474700, 0x324700, 0x004700, 0x00472c, 0x004747, 0x002747, 0x000047, 0x2e0047, 0x470047, 0x47002a,
35+ 0x740000, 0x743a00, 0x747400, 0x517400, 0x007400, 0x007449, 0x007474, 0x004074, 0x000074, 0x4b0074, 0x740074, 0x740045,
36+ 0xb50000, 0xb56300, 0xb5b500, 0x7db500, 0x00b500, 0x00b571, 0x00b5b5, 0x0063b5, 0x0000b5, 0x7500b5, 0xb500b5, 0xb5006b,
37+ 0xff0000, 0xff8c00, 0xffff00, 0xb2ff00, 0x00ff00, 0x00ffa0, 0x00ffff, 0x008cff, 0x0000ff, 0xa500ff, 0xff00ff, 0xff0098,
38+ 0xff5959, 0xffb459, 0xffff71, 0xcfff60, 0x6fff6f, 0x65ffc9, 0x6dffff, 0x59b4ff, 0x5959ff, 0xc459ff, 0xff66ff, 0xff59bc,
39+ 0xff9c9c, 0xffd39c, 0xffff9c, 0xe2ff9c, 0x9cff9c, 0x9cffdb, 0x9cffff, 0x9cd3ff, 0x9c9cff, 0xdc9cff, 0xff9cff, 0xff94d3,
40+ 0x000000, 0x131313, 0x282828, 0x363636, 0x4d4d4d, 0x656565, 0x818181, 0x9f9f9f, 0xbcbcbc, 0xe2e2e2, 0xffffff,
41+}
42+
43 func colorFromCode(code int) (color tcell.Color) {
44- if code < 0 || len(ansiCodes) <= code {
45+ if code < 0 || 99 <= code {
46 color = tcell.ColorDefault
47+ } else if code < 16 {
48+ color = baseCodes[code]
49 } else {
50- color = ansiCodes[code]
51+ color = tcell.NewHexColor(hexCodes[code-16])
52 }
53 return
54 }
M
ui/ui.go
+2,
-1
1@@ -4,7 +4,7 @@ import (
2 "sync/atomic"
3 "time"
4
5- "github.com/gdamore/tcell"
6+ "github.com/gdamore/tcell/v2"
7 )
8
9 type Config struct {
10@@ -36,6 +36,7 @@ func New(config Config) (ui *UI, err error) {
11 if err != nil {
12 return
13 }
14+ ui.screen.EnablePaste()
15
16 w, h := ui.screen.Size()
17 ui.screen.Clear()