From c2399629e7f11ab8c56ed869827f511aae71ecae Mon Sep 17 00:00:00 2001 From: Pieter van Loon Date: Sat, 1 Jan 2022 22:40:35 +0100 Subject: [PATCH 1/3] Added support for tcell.Screen.SetCursorStyle --- go.mod | 5 ++--- go.sum | 23 ++++++++++++----------- gui.go | 15 +++++++++++++++ tcell_driver.go | 5 +++++ 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 3fd1bf4..dda274b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/awesome-gocui/gocui go 1.13 require ( - github.com/gdamore/tcell/v2 v2.4.0 - github.com/mattn/go-runewidth v0.0.10 - golang.org/x/text v0.3.3 // indirect + github.com/gdamore/tcell/v2 v2.4.1-0.20211227212015-3260e4ac4385 + github.com/mattn/go-runewidth v0.0.13 ) diff --git a/go.sum b/go.sum index 61f7537..d289d94 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,19 @@ 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.4.0 h1:W6dxJEmaxYvhICFoTY3WrLLEXsQ11SaFnKGVEXW57KM= -github.com/gdamore/tcell/v2 v2.4.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU= -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.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg= -github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= -github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY= -github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= +github.com/gdamore/tcell/v2 v2.4.1-0.20211227212015-3260e4ac4385 h1:O5oaOCRcXvNnsPikhB6xGd4a1bbfgcuFQCQgDB4tM7Y= +github.com/gdamore/tcell/v2 v2.4.1-0.20211227212015-3260e4ac4385/go.mod h1:I8YJFI9gzgl4dHi9UlRDZosCW+jYkDA37AXmXvL51w4= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20211113001501-0c823b97ae02 h1:7NCfEGl0sfUojmX78nK9pBJuUlSZWEJA/TwASvfiPLo= +golang.org/x/sys v0.0.0-20211113001501-0c823b97ae02/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 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= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/gui.go b/gui.go index 76bcb5c..447e485 100644 --- a/gui.go +++ b/gui.go @@ -8,6 +8,8 @@ import ( "errors" "fmt" "runtime" + + "github.com/gdamore/tcell/v2" ) // OutputMode represents an output mode, which determines how colors @@ -926,6 +928,11 @@ func (g *Gui) execKeybindings(v *View, ev *gocuiEvent) (matched bool, err error) return false, nil } +// Set the style of the cursor +func (g *Gui) SetCursorStyle(style CursorStyle) { + setCursorStyle(style) +} + // execKeybinding executes a given keybinding func (g *Gui) execKeybinding(v *View, kb *keybinding) (bool, error) { if g.isBlacklisted(kb.key) { @@ -947,3 +954,11 @@ func (g *Gui) isBlacklisted(k Key) bool { } return false } + +type CursorStyle = tcell.CursorStyle + +const ( + CursorStyleBlinkingBlock = CursorStyle(tcell.CursorStyleBlinkingBlock) + CursorStyleBlinkingBar = CursorStyle(tcell.CursorStyleBlinkingBar) + CursorStyleBlinkingUnderline = CursorStyle(tcell.CursorStyleBlinkingUnderline) +) diff --git a/tcell_driver.go b/tcell_driver.go index 38c15ba..5be1864 100644 --- a/tcell_driver.go +++ b/tcell_driver.go @@ -32,6 +32,11 @@ func Resume() error { return tcellInit() } +// Set the style of the cursor +func setCursorStyle(style CursorStyle) { + screen.SetCursorStyle(style) +} + // tcellInitSimulation creates a tcell simulated screen for testing func tcellInitSimulation() error { simScreen := tcell.NewSimulationScreen("UTF-8") From 371d861b751f3732736cc761225f999926cafb91 Mon Sep 17 00:00:00 2001 From: Pieter van Loon Date: Sun, 2 Jan 2022 15:24:23 +0100 Subject: [PATCH 2/3] Update tcell_driver.go Co-authored-by: Mark Kopenga --- tcell_driver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcell_driver.go b/tcell_driver.go index 5be1864..653e26a 100644 --- a/tcell_driver.go +++ b/tcell_driver.go @@ -32,7 +32,7 @@ func Resume() error { return tcellInit() } -// Set the style of the cursor +// setCursorStyle sets the style of the cursor func setCursorStyle(style CursorStyle) { screen.SetCursorStyle(style) } From 2cca7dc11a05fd73b0f40bdd63afae65486e1249 Mon Sep 17 00:00:00 2001 From: Pieter van Loon Date: Sun, 2 Jan 2022 15:26:38 +0100 Subject: [PATCH 3/3] Update gui.go Co-authored-by: Mark Kopenga --- gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui.go b/gui.go index 447e485..bdb9ec4 100644 --- a/gui.go +++ b/gui.go @@ -928,7 +928,7 @@ func (g *Gui) execKeybindings(v *View, ev *gocuiEvent) (matched bool, err error) return false, nil } -// Set the style of the cursor +// SetCursorStyle sets the style of the cursor func (g *Gui) SetCursorStyle(style CursorStyle) { setCursorStyle(style) }