Skip to content

Commit

Permalink
Prevent keypresses panic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mgazza authored and andydotxyz committed Dec 4, 2024
1 parent 9755d1f commit fd723be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions term.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ func New() *Terminal {
t := &Terminal{
mouseCursor: desktop.DefaultCursor,
highlightBitMask: 0x55,
in: discardWriter{},
}
t.ExtendBaseWidget(t)
t.content = widget2.NewTermGrid()
Expand Down

0 comments on commit fd723be

Please sign in to comment.