From b816a4abf583d70ae3b262583509d657e4ecdfb1 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 14 Nov 2022 23:09:31 -0500 Subject: [PATCH] Added a Printable method to button --- examples/type/main.go | 10 +++++++--- input.go | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/type/main.go b/examples/type/main.go index 92ebfb3..cfac4dc 100644 --- a/examples/type/main.go +++ b/examples/type/main.go @@ -38,10 +38,14 @@ func main () { os.Exit(0) case stone.EventPress: - event := event.(stone.EventPress) - if stone.event.Printable() { - application.SetRune(caret, 0, rune(stone.event)) + button := stone.Button(event.(stone.EventPress)) + if button.Printable() { + application.SetRune(caret, 0, rune(button)) caret ++ + width, _ := application.Size() + if caret >= width { + caret = 0 + } application.Draw() } diff --git a/input.go b/input.go index d18ea7b..5476ab1 100644 --- a/input.go +++ b/input.go @@ -1,5 +1,7 @@ package stone +import "unicode" + type Button int const ( @@ -69,3 +71,8 @@ const ( KeyF11 Button = 154 KeyF12 Button = 155 ) + +func (button Button) Printable () (printable bool) { + printable = unicode.IsPrint(rune(button)) + return +}