Support bracketed paste mode via tcell

This commit is contained in:
Trevor Slocum 2020-10-16 08:28:51 -07:00
parent 597052a7e7
commit df2d4e418e
5 changed files with 41 additions and 11 deletions

View File

@ -16,6 +16,7 @@ v1.5.1 (WIP)
- Remove return values from methods which return their primitive (breaks chaining)
- Remove Application.ForceDraw (Application.Draw may be called anywhere)
- Rename Pages as Panels
- Support bracketed paste mode via tcell
v1.5.0 (2020-10-03)
- Add scroll bar to TextView

View File

@ -46,6 +46,9 @@ type Application struct {
// Whether or not the application resizes the root primitive.
rootFullscreen bool
// Whether or not to enable bracketed paste mode.
enableBracketedPaste bool
// Whether or not to enable mouse events.
enableMouse bool
@ -115,9 +118,10 @@ type Application struct {
// NewApplication creates and returns a new application.
func NewApplication() *Application {
return &Application{
events: make(chan tcell.Event, queueSize),
updates: make(chan func(), queueSize),
screenReplacement: make(chan tcell.Screen, 1),
enableBracketedPaste: true,
events: make(chan tcell.Event, queueSize),
updates: make(chan func(), queueSize),
screenReplacement: make(chan tcell.Screen, 1),
}
}
@ -211,6 +215,20 @@ func (a *Application) GetScreenSize() (width, height int) {
return a.width, a.height
}
// EnableBracketedPaste enables bracketed paste mode, which is enabled by default.
func (a *Application) EnableBracketedPaste(enable bool) {
a.Lock()
defer a.Unlock()
if enable != a.enableBracketedPaste && a.screen != nil {
if enable {
a.screen.EnablePaste()
} else {
a.screen.DisablePaste()
}
}
a.enableBracketedPaste = enable
}
// EnableMouse enables mouse events.
func (a *Application) EnableMouse(enable bool) {
a.Lock()
@ -223,7 +241,6 @@ func (a *Application) EnableMouse(enable bool) {
}
}
a.enableMouse = enable
}
// Run starts the application and thus the event loop. This function returns
@ -243,6 +260,9 @@ func (a *Application) Run() error {
a.Unlock()
return err
}
if a.enableBracketedPaste {
a.screen.EnablePaste()
}
if a.enableMouse {
a.screen.EnableMouse()
}
@ -302,6 +322,9 @@ func (a *Application) Run() error {
if err := screen.Init(); err != nil {
panic(err)
}
if a.enableBracketedPaste {
screen.EnablePaste()
}
if a.enableMouse {
screen.EnableMouse()
}

8
doc.go
View File

@ -72,7 +72,13 @@ file.
cbind: https://gitlab.com/tslocum/cbind
cbind example: https://docs.rocketnine.space/gitlab.com/tslocum/cbind/#example_NewConfiguration
Bracketed Paste Mode
Bracketed paste mode is enabled by default. It may be disabled by calling
Application.EnableBracketedPaste before Application.Run. The following demo
shows how to handle paste events and process pasted text.
tcell bracketed paste demo: https://github.com/gdamore/tcell/blob/master/_demos/mouse.go
Mouse Support

4
go.mod
View File

@ -3,10 +3,10 @@ module gitlab.com/tslocum/cview
go 1.12
require (
github.com/gdamore/tcell/v2 v2.0.0-dev.0.20201014051707-aeb3a1194825
github.com/gdamore/tcell/v2 v2.0.0
github.com/lucasb-eyer/go-colorful v1.0.3
github.com/mattn/go-runewidth v0.0.9
github.com/rivo/uniseg v0.1.0
gitlab.com/tslocum/cbind v0.1.2
golang.org/x/sys v0.0.0-20201014080544-cc95f250f6bc // indirect
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 // indirect
)

8
go.sum
View File

@ -1,8 +1,8 @@
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/v2 v2.0.0-dev/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
github.com/gdamore/tcell/v2 v2.0.0-dev.0.20201014051707-aeb3a1194825 h1:PniILgKHAXM1OsfAsUoxnmeaH2DNk67W9degA+x4Byc=
github.com/gdamore/tcell/v2 v2.0.0-dev.0.20201014051707-aeb3a1194825/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
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=
@ -15,8 +15,8 @@ gitlab.com/tslocum/cbind v0.1.2/go.mod h1:HfB7qAhHSZbn1rFK8M9SvSN5NG6ScAg/3h3iE6
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 h1:DvY3Zkh7KabQE/kfzMvYvKirSiguP9Q/veMtkYyf0o8=
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201014080544-cc95f250f6bc h1:HVFDs9bKvTxP6bh1Rj9MCSo+UmafQtI8ZWDPVwVk9g4=
golang.org/x/sys v0.0.0-20201014080544-cc95f250f6bc/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=