ui: change Queue to return all events at once

The Queue interface was changed from

	type Queue interface {
		Events(k Key) []Event
	}

to the more complex single-step protocol

	type Queue interface {
		Next(k Key) (Event, bool)
	}

to cater for a particular use case: Editor's SubmitEvent. When a
SubmitEvent is passed to a caller of Editor.Next, the Editor state,
in particular the current text, must not have changed by edits
later in the command stream. For example, pressing the keys <E>,
<Enter>, <E> should result in a SubmitEvent where the Editor has
a single 'e' in Text(), not two.

However, there is no reason to push the more complex Queue to every user.
Rather, store remaining input events inside Editor and process them as
Editor.Event (or Layout) is called.

Finally, revert the Queue interface to the simpler Events method.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-09-26 15:50:51 +02:00
parent 578b169279
commit dc6fedc163
6 changed files with 38 additions and 28 deletions
+3 -3
View File
@@ -5,9 +5,9 @@ package ui
// Queue maps an event handler key to the events
// available to the handler.
type Queue interface {
// Next returns the next available event, or
// false if none are available.
Next(k Key) (Event, bool)
// Events returns the available events for a
// Key.
Events(k Key) []Event
}
// Key is the stable identifier for an event handler.