default constructor
parent
4c78f40f0f
commit
011e37a8fa
|
|
@ -1,5 +1,9 @@
|
||||||
package input
|
package input
|
||||||
|
|
||||||
type Input interface {
|
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 {
|
func NewRandom(start, stop byte) *Random {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
return &Random{start: start, stop: stop + 1}
|
return &Random{start: start, stop: stop}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Random) Read() []Button {
|
func (r *Random) Read() []Button {
|
||||||
|
|
@ -30,7 +30,7 @@ func (r *Random) Read() []Button {
|
||||||
r.down = r.down[:0]
|
r.down = r.down[:0]
|
||||||
return was
|
return was
|
||||||
} else {
|
} 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)
|
r.down = append(r.down, c)
|
||||||
return []Button{c}
|
return []Button{c}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
package output
|
package output
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
type Output interface {
|
type Output interface {
|
||||||
Close()
|
Close()
|
||||||
Press(...Key)
|
Press(...Key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func New() Output {
|
||||||
|
return NewWriter(os.Stderr)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue