Family Day update

This commit is contained in:
Ingy döt Net 2020-02-17 23:21:07 -08:00
parent aac6731f2c
commit 9ad63ea473
2442 changed files with 39761 additions and 8255 deletions

View file

@ -21,21 +21,3 @@ func main() {
s.Refresh()
time.Sleep(500 * time.Millisecond)
}
s.Println()
gc.Echo(false)
// task requirement next two lines
s.Timeout(0)
k := s.GetChar()
if k == 0 {
s.Println("No key pressed")
} else {
s.Println("You pressed", gc.KeyString(k))
}
s.Refresh()
s.Timeout(-1)
gc.FlushInput()
gc.Cursor(1)
s.GetChar()
}

View file

@ -0,0 +1,31 @@
package main
// stackoverflow.com/questions/43965556/how-to-read-a-key-in-go-but-continue-application-if-no-key-pressed-within-x-seco
import (
"bufio"
"os"
"log"
"fmt"
"time"
)
var reader = bufio.NewReader(os.Stdin)
func readKey(input chan rune) {
char, _, err := reader.ReadRune()
if err != nil {
log.Fatal(err)
}
input <- char
}
func main() {
input := make(chan rune, 1)
fmt.Println("Checking keyboard input...")
go readKey(input)
select {
case i := <-input:
fmt.Printf("Input : %v\n", i)
case <-time.After(5000 * time.Millisecond):
fmt.Println("Time out!")
}
}