diff --git a/src/device/input/input.go b/src/device/input/input.go index e2c35d8..6ca127d 100644 --- a/src/device/input/input.go +++ b/src/device/input/input.go @@ -1,5 +1,9 @@ package input type Input interface { - Read() []byte + Read() []Button +} + +func New() Input { + return NewRandom('a', 'g') } diff --git a/src/device/input/input_test.go b/src/device/input/input_test.go new file mode 100644 index 0000000..3537a11 --- /dev/null +++ b/src/device/input/input_test.go @@ -0,0 +1,7 @@ +package input + +import "testing" + +func TestInput(t *testing.T) { + var _ Input = &Random{} +} diff --git a/src/device/input/random.go b/src/device/input/random.go index 9fd6d00..8825936 100644 --- a/src/device/input/random.go +++ b/src/device/input/random.go @@ -18,7 +18,7 @@ type Random struct { func NewRandom(start, stop byte) *Random { rand.Seed(time.Now().UnixNano()) - return &Random{start: start, stop: stop + 1} + return &Random{start: start, stop: stop} } func (r *Random) Read() []Button { @@ -30,7 +30,7 @@ func (r *Random) Read() []Button { r.down = r.down[:0] return was } else { - c := Button{Char: r.start + byte(rand.Int()%int(r.stop-r.start)), Down: true} + c := Button{Char: r.start + byte(rand.Int()%int(1+r.stop-r.start)), Down: true} r.down = append(r.down, c) return []Button{c} } diff --git a/src/device/output/output.go b/src/device/output/output.go index c33f66a..7e695ab 100644 --- a/src/device/output/output.go +++ b/src/device/output/output.go @@ -1,6 +1,12 @@ package output +import "os" + type Output interface { Close() Press(...Key) } + +func New() Output { + return NewWriter(os.Stderr) +}