From 7a0b45cce021bc07acad47429b7f0edc64e7154a Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 16 May 2021 09:21:17 -0700 Subject: [PATCH] fixes #422 RFE: Handling events in batches --- console_win.go | 4 ++++ screen.go | 13 ++++++++++--- simulation.go | 4 ++++ tscreen.go | 5 +++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/console_win.go b/console_win.go index 227e4fcb..7c571603 100644 --- a/console_win.go +++ b/console_win.go @@ -352,6 +352,10 @@ func (s *cScreen) PollEvent() Event { } } +func (s *cScreen) HasPendingEvent() bool { + return len(s.evch) > 0 +} + type cursorInfo struct { size uint32 visible uint32 diff --git a/screen.go b/screen.go index 37d7894d..2d9a9ad9 100644 --- a/screen.go +++ b/screen.go @@ -83,6 +83,13 @@ type Screen interface { // Furthermore, this will return nil if the Screen is finalized. PollEvent() Event + // HasPendingEvent returns true if PollEvent would return an event + // without blocking. If the screen is stopped and PollEvent would + // return nil, then the return value from this function is unspecified. + // The purpose of this function is to allow multiple events to be collected + // at once, to minimize screen redraws. + HasPendingEvent() bool + // PostEvent tries to post an event into the event stream. This // can fail if the event queue is full. In that case, the event // is dropped, and ErrEventQFull is returned. @@ -112,7 +119,7 @@ type Screen interface { // EnablePaste enables bracketed paste mode, if supported. EnablePaste() - // DisablePaste() disables bracketed paste mode. + // DisablePaste disables bracketed paste mode. DisablePaste() // HasMouse returns true if the terminal (apparently) supports a @@ -151,7 +158,7 @@ type Screen interface { CharacterSet() string // RegisterRuneFallback adds a fallback for runes that are not - // part of the character set -- for example one coudld register + // part of the character set -- for example one could register // o as a fallback for ΓΈ. This should be done cautiously for // characters that might be displayed ordinarily in language // specific text -- characters that could change the meaning of @@ -162,7 +169,7 @@ type Screen interface { // character set, those are used in preference. Also, standard // fallbacks for graphical characters in the ACSC terminfo string // are registered implicitly. - + // // The display string should be the same width as original rune. // This makes it possible to register two character replacements // for full width East Asian characters, for example. diff --git a/simulation.go b/simulation.go index 7cb720cb..468aeebf 100644 --- a/simulation.go +++ b/simulation.go @@ -360,6 +360,10 @@ func (s *simscreen) PollEvent() Event { } } +func (s *simscreen) HasPendingEvent() bool { + return len(s.evch) > 0 +} + func (s *simscreen) PostEventWait(ev Event) { s.evch <- ev } diff --git a/tscreen.go b/tscreen.go index a0ffd701..98d81d87 100644 --- a/tscreen.go +++ b/tscreen.go @@ -933,6 +933,11 @@ func (t *tScreen) PollEvent() Event { } } +func (t *tScreen) HasPendingEvent() bool { + return len(t.evch) > 0 +} + + // vtACSNames is a map of bytes defined by terminfo that are used in // the terminals Alternate Character Set to represent other glyphs. // For example, the upper left corner of the box drawing set can be