output.Output and output.Writer
This commit is contained in:
6
src/device/output/output.go
Normal file
6
src/device/output/output.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package output
|
||||
|
||||
type Output interface {
|
||||
Close()
|
||||
Press(...int)
|
||||
}
|
||||
8
src/device/output/output_test.go
Normal file
8
src/device/output/output_test.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package output
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestOutput(t *testing.T) {
|
||||
var _ Output = &Keyboard{}
|
||||
var _ Output = &Writer{}
|
||||
}
|
||||
24
src/device/output/writer.go
Normal file
24
src/device/output/writer.go
Normal 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)
|
||||
}
|
||||
14
src/device/output/writer_test.go
Normal file
14
src/device/output/writer_test.go
Normal 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())
|
||||
}
|
||||
Reference in New Issue
Block a user