From 1b5f599f2dfc2b265792696293789207fb314288 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Fri, 30 Oct 2020 23:49:01 -0400 Subject: [PATCH] Update key usage examples --- key.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/key.go b/key.go index d07a270..46b64e8 100644 --- a/key.go +++ b/key.go @@ -11,31 +11,31 @@ import ( // the program's update function. There are a couple general patterns you could // use to check for keypresses: // -// // Switch on the type (safer) -// switch msg := msg.(type) { -// case KeyMsg: -// switch msg.Type { -// case KeyEnter: -// fmt.Println("you pressed enter!") -// case KeyRune: -// switch msg.Rune { -// case 'a': -// fmt.Println("you pressed a!") -// } -// } -// } -// // // Switch on the string representation of the key (shorter) // switch msg := msg.(type) { // case KeyMsg: // switch msg.String() { // case "enter": // fmt.Println("you pressed enter!") -// case "a': +// case "a": // fmt.Println("you pressed a!") // } // } // +// // Switch on the key type (more foolproof) +// switch msg := msg.(type) { +// case KeyMsg: +// switch msg.Type { +// case KeyEnter: +// fmt.Println("you pressed enter!") +// case KeyRunes: +// switch string(msg.Runes) { +// case "a": +// fmt.Println("you pressed a!") +// } +// } +// } +// // Note that Key.Runes will always contain at least one character, so you can // always safely call Key.Runes[0]. In most cases Key.Runes will only contain // one character, though certain input method editors (most notably Chinese