Skip to content
Myr

Update key usage examples

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Christian Rocha · committed by Christian Rocha · parent 4f2d854 · Browse files · 1 file+13 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+13 added−13 removed

  • other:+13 added−13 removed

1 file+13 added−13 removed

modified:key.go+13 added-13 removed
9 unmodified lines
10// KeyMsg contains information about a keypress. KeyMsgs are always sent to11// the program's update function. There are a couple general patterns you could12// use to check for keypresses:13//14// // Switch on the type (safer)14// // Switch on the string representation of the key (shorter)15// switch msg := msg.(type) {16// case KeyMsg:17// switch msg.Type {18// case KeyEnter:17// switch msg.String() {18// case "enter":19// fmt.Println("you pressed enter!")20// case KeyRune:21// switch msg.Rune {22// case 'a':23// fmt.Println("you pressed a!")20// case "a":21// fmt.Println("you pressed a!")24// }22// }23// }24//28// // Switch on the string representation of the key (shorter)25// // Switch on the key type (more foolproof)26// switch msg := msg.(type) {27// case KeyMsg:31// switch msg.String() {32// case "enter":28// switch msg.Type {29// case KeyEnter:30// fmt.Println("you pressed enter!")31// case KeyRunes:32// switch string(msg.Runes) {34// case "a':35// fmt.Println("you pressed a!")33// case "a":34// fmt.Println("you pressed a!")35// }36// }37// }38//39// Note that Key.Runes will always contain at least one character, so you can
313 unmodified lines