From b2dec96e1a720d04e17745fbfb8d77214d8bee88 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 11 Mar 2021 20:14:19 +0100 Subject: [PATCH] Upgraded to tcell v2.2.0 and rewrote the Application.Suspend() function to use tcell's new methods. --- application.go | 30 +++++++++++++++--------------- go.mod | 7 ++++--- go.sum | 11 +++++++++++ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/application.go b/application.go index 7d51e21..86bda67 100644 --- a/application.go +++ b/application.go @@ -513,28 +513,28 @@ func (a *Application) Suspend(f func()) bool { } // Enter suspended mode. - screen.Fini() + if err := screen.Suspend(); err != nil { + return false // Suspension failed. + } // Wait for "f" to return. f() - // If stop was called in the meantime (a.screen is nil), we're done already. + // If the screen object has changed in the meantime, we need to do more. a.RLock() - screen = a.screen - a.RUnlock() - if screen == nil { - return true + defer a.RUnlock() + if a.screen != screen { + // Calling Stop() while in suspend mode currently still leads to a + // panic, see https://github.com/gdamore/tcell/issues/440. + screen.Fini() + if a.screen == nil { + return true // If stop was called (a.screen is nil), we're done already. + } + } else { + // It hasn't changed. Resume. + screen.Resume() // Not much we can do in case of an error. } - // Make a new screen. - var err error - screen, err = tcell.NewScreen() - if err != nil { - panic(err) - } - a.screenReplacement <- screen - // One key event will get lost, see https://github.com/gdamore/tcell/issues/194 - // Continue application loop. return true } diff --git a/go.mod b/go.mod index 2f16338..c39712d 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,11 @@ module github.com/rivo/tview go 1.12 require ( - github.com/gdamore/tcell/v2 v2.0.1-0.20201017141208-acf90d56d591 - github.com/lucasb-eyer/go-colorful v1.0.3 + github.com/gdamore/tcell/v2 v2.2.0 + github.com/lucasb-eyer/go-colorful v1.2.0 github.com/mattn/go-runewidth v0.0.10 github.com/rivo/uniseg v0.2.0 - golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78 // indirect + golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 // indirect + golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect golang.org/x/text v0.3.5 // indirect ) diff --git a/go.sum b/go.sum index a30c2cf..d5c86cc 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,12 @@ github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdk github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= github.com/gdamore/tcell/v2 v2.0.1-0.20201017141208-acf90d56d591 h1:0WWUDZ1oxq7NxVyGo8M3KI5jbkiwNAdZFFzAdC68up4= github.com/gdamore/tcell/v2 v2.0.1-0.20201017141208-acf90d56d591/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA= +github.com/gdamore/tcell/v2 v2.2.0 h1:vSyEgKwraXPSOkvCk7IwOSyX+Pv3V2cV9CikJMXg4U4= +github.com/gdamore/tcell/v2 v2.2.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/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.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= @@ -13,8 +17,15 @@ 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-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10= golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78 h1:nVuTkr9L6Bq62qpUqKo/RnZCFfzDBL0bYo6w9OJUqZY= golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 h1:46ULzRKLh1CwgRq2dC5SlBzEqqNCi8rreOZnNrbqcIY= +golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +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/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=