output.Output and output.Writer

master
bel 2023-03-01 22:23:31 -07:00
parent b2bea80c4c
commit c4c1f11f2a
4 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,6 @@
package output
type Output interface {
Close()
Press(...int)
}

View File

@ -0,0 +1,8 @@
package output
import "testing"
func TestOutput(t *testing.T) {
var _ Output = &Keyboard{}
var _ Output = &Writer{}
}

View File

@ -0,0 +1,24 @@
package output
import (
"fmt"
"io"
)
type Writer struct {
w io.Writer
}
func NewWriter(w io.Writer) Writer {
return Writer{w: w}
}
func (w Writer) Close() {
if wc, ok := w.w.(io.WriteCloser); ok {
wc.Close()
}
}
func (w Writer) Press(keys ...int) {
fmt.Fprintf(w.w, "%+v\n", keys)
}

View File

@ -0,0 +1,14 @@
package output_test
import (
"bytes"
"mayhem-party/src/device/output"
"testing"
)
func TestWriter(t *testing.T) {
b := bytes.NewBuffer(nil)
w := output.NewWriter(b)
w.Press(1, 2, 3, 1)
t.Logf("%s", b.Bytes())
}