From fd723be612d8760b34d541f03a023573577c4954 Mon Sep 17 00:00:00 2001 From: Mark Gascoyne Date: Sun, 3 Nov 2024 15:37:47 +0000 Subject: [PATCH] Prevent keypresses panic prevent panic when a keystoke is made before the input steam is ready. This typically happens during ssh connections (slow ssh connections), The input stream is nil before the connection is established. --- input.go | 10 ++++++++++ term.go | 1 + 2 files changed, 11 insertions(+) diff --git a/input.go b/input.go index 58951aef..4dced848 100644 --- a/input.go +++ b/input.go @@ -232,3 +232,13 @@ func (t *Terminal) typeCursorKey(key fyne.KeyName) { _, _ = t.in.Write([]byte{asciiEscape, cursorPrefix, 'C'}) } } + +type discardWriter struct{} + +func (d discardWriter) Write(p []byte) (n int, err error) { + return len(p), nil +} + +func (d discardWriter) Close() error { + return nil +} diff --git a/term.go b/term.go index 227665e8..cdcc963b 100644 --- a/term.go +++ b/term.go @@ -465,6 +465,7 @@ func New() *Terminal { t := &Terminal{ mouseCursor: desktop.DefaultCursor, highlightBitMask: 0x55, + in: discardWriter{}, } t.ExtendBaseWidget(t) t.content = widget2.NewTermGrid()