io/key: [API] add InputHintOp for specifying the input hint for a tag

We're about to replace key.InputOp with a filter; this change separates
the input hint into its own operation.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-10-19 18:10:49 -05:00
parent ef8171b971
commit 12a0ad7038
5 changed files with 43 additions and 14 deletions
+14 -2
View File
@@ -23,8 +23,6 @@ import (
// focused key handler.
type InputOp struct {
Tag event.Tag
// Hint describes the type of text expected by Tag.
Hint InputHint
// Keys is the set of keys Tag can handle. That is, Tag will only
// receive an Event if its key and modifiers are accepted by Keys.Contains.
// As a special case, the topmost (first added) InputOp handler receives all
@@ -32,6 +30,12 @@ type InputOp struct {
Keys Set
}
// InputHintOp describes the type of text expected by a tag.
type InputHintOp struct {
Tag event.Tag
Hint InputHint
}
// SoftKeyboardCmd shows or hides the on-screen keyboard, if available.
type SoftKeyboardCmd struct {
Show bool
@@ -331,6 +335,14 @@ func (h InputOp) Add(o *op.Ops) {
}
data := ops.Write2String(&o.Internal, ops.TypeKeyInputLen, h.Tag, string(h.Keys))
data[0] = byte(ops.TypeKeyInput)
}
func (h InputHintOp) Add(o *op.Ops) {
if h.Tag == nil {
panic("Tag must be non-nil")
}
data := ops.Write1(&o.Internal, ops.TypeKeyInputHintLen, h.Tag)
data[0] = byte(ops.TypeKeyInputHint)
data[1] = byte(h.Hint)
}