default constructor
parent
4c78f40f0f
commit
011e37a8fa
|
|
@ -1,5 +1,9 @@
|
|||
package input
|
||||
|
||||
type Input interface {
|
||||
Read() []byte
|
||||
Read() []Button
|
||||
}
|
||||
|
||||
func New() Input {
|
||||
return NewRandom('a', 'g')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package input
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestInput(t *testing.T) {
|
||||
var _ Input = &Random{}
|
||||
}
|
||||
|
|
@ -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}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
package output
|
||||
|
||||
import "os"
|
||||
|
||||
type Output interface {
|
||||
Close()
|
||||
Press(...Key)
|
||||
}
|
||||
|
||||
func New() Output {
|
||||
return NewWriter(os.Stderr)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue