wrap accepts button.Parser

master
bel 2023-03-24 20:50:58 -06:00
parent b319ed7e6d
commit 896f5e9c92
3 changed files with 15 additions and 22 deletions

View File

@ -1,7 +1,6 @@
package wrap
import (
"mayhem-party/src/device/input/raw"
"os"
"syscall"
"testing"
@ -12,7 +11,7 @@ func TestRefresh(t *testing.T) {
b := byte('a')
generator := func() Wrap {
b += byte(1)
return explicit{src: raw.NewRandom(func() byte { return b })}
return dummyParser{Char: b}
}
ch := make(chan os.Signal, 1)
defer close(ch)

View File

@ -3,7 +3,6 @@ package wrap
import (
"context"
"mayhem-party/src/device/input/button"
"mayhem-party/src/device/input/raw"
"os"
"syscall"
)
@ -13,14 +12,9 @@ type Wrap interface {
Close()
}
func New(ctx context.Context, src raw.Raw) Wrap {
func New(ctx context.Context, src button.Parser) Wrap {
maker := func() Wrap {
return explicit{src: src}
}
if os.Getenv("WRAP_PROTOCOL") == "true" {
maker = func() Wrap {
return NewProtocol(src)
}
return src
}
if os.Getenv("WRAP_BUFFERED") == "true" {
oldMaker := maker
@ -43,13 +37,3 @@ func New(ctx context.Context, src raw.Raw) Wrap {
}
return maker()
}
type explicit struct {
src raw.Raw
}
func (e explicit) Close() {
e.src.Close()
}
func (e explicit) Read() []button.Button {

View File

@ -1,11 +1,21 @@
package wrap
import "testing"
import (
"mayhem-party/src/device/input/button"
"testing"
)
func TestWrap(t *testing.T) {
var _ Wrap = explicit{}
var _ Wrap = dummyParser{}
var _ Wrap = &Refresh{}
var _ Wrap = &Buffered{}
var _ Wrap = &Remap{}
var _ Wrap = Protocol{}
}
type dummyParser button.Button
func (d dummyParser) Close() {}
func (d dummyParser) Read() []button.Button {
return []button.Button{button.Button(d)}
}