diff --git a/src/device/output/output.go b/src/device/output/output.go new file mode 100644 index 0000000..2093ad6 --- /dev/null +++ b/src/device/output/output.go @@ -0,0 +1,6 @@ +package output + +type Output interface { + Close() + Press(...int) +} diff --git a/src/device/output/output_test.go b/src/device/output/output_test.go new file mode 100644 index 0000000..4496275 --- /dev/null +++ b/src/device/output/output_test.go @@ -0,0 +1,8 @@ +package output + +import "testing" + +func TestOutput(t *testing.T) { + var _ Output = &Keyboard{} + var _ Output = &Writer{} +} diff --git a/src/device/output/writer.go b/src/device/output/writer.go new file mode 100644 index 0000000..7c9cf1d --- /dev/null +++ b/src/device/output/writer.go @@ -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) +} diff --git a/src/device/output/writer_test.go b/src/device/output/writer_test.go new file mode 100644 index 0000000..9060a26 --- /dev/null +++ b/src/device/output/writer_test.go @@ -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()) +}