Skip to content

Commit

Permalink
fixes #422 RFE: Handling events in batches
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed May 16, 2021
1 parent 0bfa151 commit 7a0b45c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions console_win.go
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions screen.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions simulation.go
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions tscreen.go
Expand Up @@ -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
Expand Down

0 comments on commit 7a0b45c

Please sign in to comment.