output.Output and output.Writer
parent
b2bea80c4c
commit
c4c1f11f2a
|
|
@ -0,0 +1,6 @@
|
||||||
|
package output
|
||||||
|
|
||||||
|
type Output interface {
|
||||||
|
Close()
|
||||||
|
Press(...int)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package output
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestOutput(t *testing.T) {
|
||||||
|
var _ Output = &Keyboard{}
|
||||||
|
var _ Output = &Writer{}
|
||||||
|
}
|
||||||
|
|
@ -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)
|
||||||
|
}
|
||||||
|
|
@ -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())
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue