summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtz.pm>2020-10-18 16:37:46 +0200
committerHubert Hirtz <hubert@hirtz.pm>2020-10-18 16:37:46 +0200
commitc9dc688f401d4d549a3776947fbc7e3d44b8c499 (patch)
tree70661ecb9b030c64fd9607f473f06fd476b4b564
parentUpdate screenshot URL (diff)
Update tcell to v2 and
- enable bracketed paste - use hex color codes instead of ansi
Diffstat (limited to '')
-rw-r--r--app.go19
-rw-r--r--cmd/irc/main.go2
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--ui/buffers.go2
-rw-r--r--ui/editor.go2
-rw-r--r--ui/style.go26
-rw-r--r--ui/ui.go3
8 files changed, 41 insertions, 19 deletions
diff --git a/app.go b/app.go
index a27db0f..f9088ae 100644
--- a/app.go
+++ b/app.go
@@ -10,12 +10,13 @@ import (
"git.sr.ht/~taiite/senpai/irc"
"git.sr.ht/~taiite/senpai/ui"
- "github.com/gdamore/tcell"
+ "github.com/gdamore/tcell/v2"
)
type App struct {
- win *ui.UI
- s *irc.Session
+ win *ui.UI
+ s *irc.Session
+ pasting bool
cfg Config
highlights []string
@@ -122,7 +123,9 @@ func (app *App) handleIRCEvents(evs []irc.Event) {
for _, ev := range evs {
app.handleIRCEvent(ev)
}
- app.draw()
+ if !app.pasting {
+ app.draw()
+ }
}
func (app *App) handleIRCEvent(ev irc.Event) {
@@ -222,14 +225,14 @@ func (app *App) handleUIEvent(ev tcell.Event) {
switch ev := ev.(type) {
case *tcell.EventResize:
app.win.Resize()
- app.draw()
+ case *tcell.EventPaste:
+ app.pasting = ev.Start()
case *tcell.EventKey:
switch ev.Key() {
case tcell.KeyCtrlC:
app.win.Exit()
case tcell.KeyCtrlL:
app.win.Resize()
- app.draw()
case tcell.KeyCtrlU, tcell.KeyPgUp:
app.win.ScrollUp()
if app.s == nil {
@@ -305,7 +308,9 @@ func (app *App) handleUIEvent(ev tcell.Event) {
default:
return
}
- app.draw()
+ if !app.pasting {
+ app.draw()
+ }
}
func (app *App) isHighlight(content string) bool {
diff --git a/cmd/irc/main.go b/cmd/irc/main.go
index fab5bc5..5f7933d 100644
--- a/cmd/irc/main.go
+++ b/cmd/irc/main.go
@@ -8,7 +8,7 @@ import (
"time"
"git.sr.ht/~taiite/senpai"
- "github.com/gdamore/tcell"
+ "github.com/gdamore/tcell/v2"
)
func init() {
diff --git a/go.mod b/go.mod
index 1ae8dbd..c3dca9c 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module git.sr.ht/~taiite/senpai
go 1.14
require (
- github.com/gdamore/tcell v1.4.0
+ github.com/gdamore/tcell/v2 v2.0.0
github.com/mattn/go-runewidth v0.0.7
gopkg.in/yaml.v2 v2.3.0
)
diff --git a/go.sum b/go.sum
index 81a782c..932da5d 100644
--- a/go.sum
+++ b/go.sum
@@ -1,7 +1,7 @@
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.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU=
-github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0=
+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 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
diff --git a/ui/buffers.go b/ui/buffers.go
index ec89893..129a10d 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -6,7 +6,7 @@ import (
"strings"
"time"
- "github.com/gdamore/tcell"
+ "github.com/gdamore/tcell/v2"
)
func IsSplitRune(r rune) bool {
diff --git a/ui/editor.go b/ui/editor.go
index d3cc7e3..cfc26b5 100644
--- a/ui/editor.go
+++ b/ui/editor.go
@@ -1,7 +1,7 @@
package ui
import (
- "github.com/gdamore/tcell"
+ "github.com/gdamore/tcell/v2"
)
type Completion struct {
diff --git a/ui/style.go b/ui/style.go
index c705846..2e09506 100644
--- a/ui/style.go
+++ b/ui/style.go
@@ -1,7 +1,7 @@
package ui
import (
- "github.com/gdamore/tcell"
+ "github.com/gdamore/tcell/v2"
"github.com/mattn/go-runewidth"
)
@@ -177,12 +177,16 @@ const (
ColorRed
)
-var ansiCodes = []tcell.Color{
- // Taken from <https://modern.ircdocs.horse/formatting.html>
+// Taken from <https://modern.ircdocs.horse/formatting.html>
+
+var baseCodes = []tcell.Color{
tcell.ColorWhite, tcell.ColorBlack, tcell.ColorBlue, tcell.ColorGreen,
tcell.ColorRed, tcell.ColorBrown, tcell.ColorPurple, tcell.ColorOrange,
tcell.ColorYellow, tcell.ColorLightGreen, tcell.ColorTeal, tcell.ColorLightCyan,
tcell.ColorLightBlue, tcell.ColorPink, tcell.ColorGrey, tcell.ColorLightGrey,
+}
+
+var ansiCodes = []uint64{
/* 16-27 */ 52, 94, 100, 58, 22, 29, 23, 24, 17, 54, 53, 89,
/* 28-39 */ 88, 130, 142, 64, 28, 35, 30, 25, 18, 91, 90, 125,
/* 40-51 */ 124, 166, 184, 106, 34, 49, 37, 33, 19, 129, 127, 161,
@@ -192,11 +196,23 @@ var ansiCodes = []tcell.Color{
/* 88-98 */ 16, 233, 235, 237, 239, 241, 244, 247, 250, 254, 231,
}
+var hexCodes = []int32{
+ 0x470000, 0x472100, 0x474700, 0x324700, 0x004700, 0x00472c, 0x004747, 0x002747, 0x000047, 0x2e0047, 0x470047, 0x47002a,
+ 0x740000, 0x743a00, 0x747400, 0x517400, 0x007400, 0x007449, 0x007474, 0x004074, 0x000074, 0x4b0074, 0x740074, 0x740045,
+ 0xb50000, 0xb56300, 0xb5b500, 0x7db500, 0x00b500, 0x00b571, 0x00b5b5, 0x0063b5, 0x0000b5, 0x7500b5, 0xb500b5, 0xb5006b,
+ 0xff0000, 0xff8c00, 0xffff00, 0xb2ff00, 0x00ff00, 0x00ffa0, 0x00ffff, 0x008cff, 0x0000ff, 0xa500ff, 0xff00ff, 0xff0098,
+ 0xff5959, 0xffb459, 0xffff71, 0xcfff60, 0x6fff6f, 0x65ffc9, 0x6dffff, 0x59b4ff, 0x5959ff, 0xc459ff, 0xff66ff, 0xff59bc,
+ 0xff9c9c, 0xffd39c, 0xffff9c, 0xe2ff9c, 0x9cff9c, 0x9cffdb, 0x9cffff, 0x9cd3ff, 0x9c9cff, 0xdc9cff, 0xff9cff, 0xff94d3,
+ 0x000000, 0x131313, 0x282828, 0x363636, 0x4d4d4d, 0x656565, 0x818181, 0x9f9f9f, 0xbcbcbc, 0xe2e2e2, 0xffffff,
+}
+
func colorFromCode(code int) (color tcell.Color) {
- if code < 0 || len(ansiCodes) <= code {
+ if code < 0 || 99 <= code {
color = tcell.ColorDefault
+ } else if code < 16 {
+ color = baseCodes[code]
} else {
- color = ansiCodes[code]
+ color = tcell.NewHexColor(hexCodes[code-16])
}
return
}
diff --git a/ui/ui.go b/ui/ui.go
index 9d295ce..d778641 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -4,7 +4,7 @@ import (
"sync/atomic"
"time"
- "github.com/gdamore/tcell"
+ "github.com/gdamore/tcell/v2"
)
type Config struct {
@@ -36,6 +36,7 @@ func New(config Config) (ui *UI, err error) {
if err != nil {
return
}
+ ui.screen.EnablePaste()
w, h := ui.screen.Size()
ui.screen.Clear()