From 2cae3c6d2883cd6a46e500698cf000fc6252804e Mon Sep 17 00:00:00 2001 From: bel Date: Sat, 25 Mar 2023 10:17:36 -0600 Subject: [PATCH] dont do raw.New, instead add raw.Raw.Refresh explicit --- src/device/input/button/plaintext_test.go | 2 ++ src/device/input/input.go | 3 ++- src/device/input/raw/keyboard.go | 3 +++ src/device/input/raw/random.go | 3 +++ src/device/input/raw/raw.go | 1 + src/device/input/raw/udp.go | 3 +++ 6 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/device/input/button/plaintext_test.go b/src/device/input/button/plaintext_test.go index f293aab..7370fc5 100644 --- a/src/device/input/button/plaintext_test.go +++ b/src/device/input/button/plaintext_test.go @@ -22,6 +22,8 @@ func TestPlaintext(t *testing.T) { type constSrc string +func (c constSrc) Refresh() {} + func (c constSrc) Close() {} func (c constSrc) Read() []byte { diff --git a/src/device/input/input.go b/src/device/input/input.go index c0d449f..f5d6d44 100644 --- a/src/device/input/input.go +++ b/src/device/input/input.go @@ -13,8 +13,9 @@ type Input interface { } func New(ctx context.Context) Input { + src := raw.New(ctx) return wrap.New(ctx, func() button.Parser { - src := raw.New(ctx) + src.Refresh() return button.New(ctx, src) }) } diff --git a/src/device/input/raw/keyboard.go b/src/device/input/raw/keyboard.go index f9d53ee..55ffef5 100644 --- a/src/device/input/raw/keyboard.go +++ b/src/device/input/raw/keyboard.go @@ -31,6 +31,9 @@ func NewKeyboard() Keyboard { return Keyboard{} } +func (kb Keyboard) Refresh() { +} + func (kb Keyboard) Close() { switch runtime.GOOS { case "linux": diff --git a/src/device/input/raw/random.go b/src/device/input/raw/random.go index 419041b..514f718 100644 --- a/src/device/input/raw/random.go +++ b/src/device/input/raw/random.go @@ -22,6 +22,9 @@ func NewRandom(generator func() byte) *Random { return &Random{generator: generator} } +func (r *Random) Refresh() { +} + func (r *Random) Close() { } diff --git a/src/device/input/raw/raw.go b/src/device/input/raw/raw.go index 712bb5f..cbc89ab 100644 --- a/src/device/input/raw/raw.go +++ b/src/device/input/raw/raw.go @@ -9,6 +9,7 @@ import ( type Raw interface { Read() []byte Close() + Refresh() } func New(ctx context.Context) Raw { diff --git a/src/device/input/raw/udp.go b/src/device/input/raw/udp.go index edfc7b4..148ebe0 100644 --- a/src/device/input/raw/udp.go +++ b/src/device/input/raw/udp.go @@ -55,6 +55,9 @@ func (udp UDP) Read() []byte { } } +func (udp UDP) Refresh() { +} + func (udp UDP) Close() { udp.conn.Close() }