42 lines
705 B
Go
42 lines
705 B
Go
package button
|
|
|
|
import (
|
|
"mayhem-party/src/device/input/raw"
|
|
"os"
|
|
)
|
|
|
|
type Plaintext struct {
|
|
src raw.Raw
|
|
release byte
|
|
}
|
|
|
|
func NewPlaintext(src raw.Raw) Plaintext {
|
|
releaseChar := byte('!')
|
|
if v := os.Getenv("BUTTON_PLAINTEXT_RELEASE"); v != "" {
|
|
releaseChar = byte(v[0])
|
|
}
|
|
return Plaintext{
|
|
src: src,
|
|
release: releaseChar,
|
|
}
|
|
}
|
|
|
|
func (p Plaintext) Close() { p.src.Close() }
|
|
|
|
func (p Plaintext) Read() []Button {
|
|
b := p.src.Read()
|
|
buttons := make([]Button, 0, len(b))
|
|
down := true
|
|
for i := range b {
|
|
if b[i] == p.release {
|
|
down = false
|
|
} else {
|
|
if b[i] != '\n' {
|
|
buttons = append(buttons, Button{Char: b[i], Down: down})
|
|
}
|
|
down = true
|
|
}
|
|
}
|
|
return buttons
|
|
}
|