mirror of
https://github.com/rivo/tview.git
synced 2025-04-28 13:48:53 +08:00
Cosmetic improvements.
This commit is contained in:
parent
6b270eb8e8
commit
83483397e8
@ -41,7 +41,7 @@ type Application struct {
|
|||||||
// was drawn.
|
// was drawn.
|
||||||
afterDraw func(screen tcell.Screen)
|
afterDraw func(screen tcell.Screen)
|
||||||
|
|
||||||
// Halts the event loop during suspended mode
|
// Halts the event loop during suspended mode.
|
||||||
suspendMutex sync.Mutex
|
suspendMutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,9 +105,9 @@ func (a *Application) Run() error {
|
|||||||
for {
|
for {
|
||||||
// Do not poll events during suspend mode
|
// Do not poll events during suspend mode
|
||||||
a.suspendMutex.Lock()
|
a.suspendMutex.Lock()
|
||||||
a.Lock()
|
a.RLock()
|
||||||
screen := a.screen
|
screen := a.screen
|
||||||
a.Unlock()
|
a.RUnlock()
|
||||||
if screen == nil {
|
if screen == nil {
|
||||||
a.suspendMutex.Unlock()
|
a.suspendMutex.Unlock()
|
||||||
break
|
break
|
||||||
@ -150,9 +150,9 @@ func (a *Application) Run() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case *tcell.EventResize:
|
case *tcell.EventResize:
|
||||||
a.Lock()
|
a.RLock()
|
||||||
screen := a.screen
|
screen := a.screen
|
||||||
a.Unlock()
|
a.RUnlock()
|
||||||
screen.Clear()
|
screen.Clear()
|
||||||
a.Draw()
|
a.Draw()
|
||||||
}
|
}
|
||||||
@ -163,8 +163,8 @@ func (a *Application) Run() error {
|
|||||||
|
|
||||||
// Stop stops the application, causing Run() to return.
|
// Stop stops the application, causing Run() to return.
|
||||||
func (a *Application) Stop() {
|
func (a *Application) Stop() {
|
||||||
a.RLock()
|
a.Lock()
|
||||||
defer a.RUnlock()
|
defer a.Unlock()
|
||||||
if a.screen == nil {
|
if a.screen == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -180,18 +180,18 @@ func (a *Application) Stop() {
|
|||||||
// was called. If false is returned, the application was already suspended,
|
// was called. If false is returned, the application was already suspended,
|
||||||
// terminal UI mode was not exited, and "f" was not called.
|
// terminal UI mode was not exited, and "f" was not called.
|
||||||
func (a *Application) Suspend(f func()) bool {
|
func (a *Application) Suspend(f func()) bool {
|
||||||
a.Lock()
|
a.RLock()
|
||||||
|
|
||||||
if a.screen == nil {
|
if a.screen == nil {
|
||||||
// Screen has not yet been initialized
|
// Screen has not yet been initialized.
|
||||||
a.Unlock()
|
a.RUnlock()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enter suspended mode.
|
// Enter suspended mode.
|
||||||
a.suspendMutex.Lock()
|
a.suspendMutex.Lock()
|
||||||
defer a.suspendMutex.Unlock()
|
defer a.suspendMutex.Unlock()
|
||||||
a.Unlock()
|
a.RUnlock()
|
||||||
a.Stop()
|
a.Stop()
|
||||||
|
|
||||||
// Deal with panics during suspended mode. Exit the program.
|
// Deal with panics during suspended mode. Exit the program.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user