can exit while reading from keyboard

This commit is contained in:
Bel LaPointe
2023-03-02 15:21:34 -07:00
parent 5c5a371f55
commit b0767818e2
6 changed files with 22 additions and 11 deletions

View File

@@ -1,20 +1,26 @@
package input
import "os"
import (
"context"
"os"
)
type Input interface {
Read() []Button
Close()
}
func New() Input {
func New(ctx context.Context) Input {
foo := randomCharFromRange('a', 'g')
if p, ok := os.LookupEnv("INPUT_RANDOM_WEIGHT_FILE"); ok {
foo = randomCharFromWeightFile(p)
}
var result Input = NewRandom(foo)
if os.Getenv("INPUT_KEYBOARD") == "true" {
result = NewKeyboard()
}
if os.Getenv("INPUT_BUFFERED") == "true" {
result = NewBuffered(result)
result = NewBuffered(ctx, result)
}
return result
}