default constructor

master
bel 2023-03-01 22:55:11 -07:00
parent 4c78f40f0f
commit 011e37a8fa
4 changed files with 20 additions and 3 deletions

View File

@ -1,5 +1,9 @@
package input
type Input interface {
Read() []byte
Read() []Button
}
func New() Input {
return NewRandom('a', 'g')
}

View File

@ -0,0 +1,7 @@
package input
import "testing"
func TestInput(t *testing.T) {
var _ Input = &Random{}
}

View File

@ -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}
}

View File

@ -1,6 +1,12 @@
package output
import "os"
type Output interface {
Close()
Press(...Key)
}
func New() Output {
return NewWriter(os.Stderr)
}