package output

import (
	"fmt"
	"io"
	"mayhem-party/src/device/output/key"
)

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 ...key.Key) {
	result := make([]byte, len(keys))
	for i := range keys {
		result[i] = key.ToChar(keys[i])
	}
	fmt.Fprintf(w.w, "%s\n", result)
}
