From 81a4d7bdd14350b7f66294a2d64be10b08be961a Mon Sep 17 00:00:00 2001 From: andrewsun2898 Date: Tue, 11 Jul 2023 19:16:33 -0700 Subject: [PATCH] Only update size when values are valid In some environments the ioctl call for window size will return 0x0, for instance in serial console setups. This causes the input to be truncated making it hard for users to see what they are typing. This performs a check to see if either width or height has a non-zero value before updating the size. --- editline/testdata/bad_resize | 10 ++++++++++ getline.go | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 editline/testdata/bad_resize diff --git a/editline/testdata/bad_resize b/editline/testdata/bad_resize new file mode 100644 index 0000000..84ac1e8 --- /dev/null +++ b/editline/testdata/bad_resize @@ -0,0 +1,10 @@ +run +reset +resize 40 25 +resize 0 0 +---- +TEA WINDOW SIZE: {40 25} +TEA WINDOW SIZE: {0 0} +-- view: +>   ␤ +M-? toggle key help • C-d erase/stop🛇 \ No newline at end of file diff --git a/getline.go b/getline.go index 597ac99..027167a 100644 --- a/getline.go +++ b/getline.go @@ -33,8 +33,9 @@ var _ tea.Model = (*Editor)(nil) func (m *Editor) Update(imsg tea.Msg) (tea.Model, tea.Cmd) { switch msg := imsg.(type) { case tea.WindowSizeMsg: - m.Model.SetSize(msg.Width, msg.Height) - + if msg.Width > 0 && msg.Height > 0 { + m.Model.SetSize(msg.Width, msg.Height) + } case editline.InputCompleteMsg: return m, tea.Quit }