2
0
mirror of https://github.com/rivo/tview.git synced 2024-11-15 06:12:46 +00:00

Allow setting the pause between redraws

Fixes #710

Signed-off-by: Sam Whited <sam@samwhited.com>
This commit is contained in:
Sam Whited 2022-03-13 16:35:10 -04:00
parent 9994674d60
commit 7a764af96d
No known key found for this signature in database
GPG Key ID: 16D5138E52B849B3

View File

@ -10,9 +10,6 @@ import (
const (
// The size of the event/update/redraw channels.
queueSize = 100
// The minimum time between two consecutive redraws.
redrawPause = 50 * time.Millisecond
)
// DoubleClickInterval specifies the maximum time between clicks to register a
@ -118,6 +115,7 @@ type Application struct {
mouseDownX, mouseDownY int // The position of the mouse when its button was last pressed.
lastMouseClick time.Time // The time when a mouse button was last clicked.
lastMouseButtons tcell.ButtonMask // The last mouse button state.
redrawPause time.Duration
}
// NewApplication creates and returns a new application.
@ -126,9 +124,15 @@ func NewApplication() *Application {
events: make(chan tcell.Event, queueSize),
updates: make(chan queuedUpdate, queueSize),
screenReplacement: make(chan tcell.Screen, 1),
redrawPause: 50 * time.Millisecond,
}
}
// SetRedrawPause changes the minimum time between two consecutive redraws.
func (a *Application) SetRedrawPause(t time.Duration) {
a.redrawPause = t
}
// SetInputCapture sets a function which captures all key events before they are
// forwarded to the key event handler of the primitive which currently has
// focus. This function can then choose to forward that key event (or a
@ -344,11 +348,11 @@ EventLoop:
a.draw()
}
case *tcell.EventResize:
if time.Since(lastRedraw) < redrawPause {
if time.Since(lastRedraw) < a.redrawPause {
if redrawTimer != nil {
redrawTimer.Stop()
}
redrawTimer = time.AfterFunc(redrawPause, func() {
redrawTimer = time.AfterFunc(a.redrawPause, func() {
a.events <- event
})
}