From 3c0985979908d4d725d5d90fdc936dabb24c9b3e Mon Sep 17 00:00:00 2001 From: Mark Gascoyne Date: Wed, 20 Mar 2024 10:22:59 +0000 Subject: [PATCH] fix buffer cutoff mid escape Fix issue when buffer cuts off mid escape sequence --- color_test.go | 27 +++++++++++++++++++++++++++ output.go | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/color_test.go b/color_test.go index 29d12fac..01ef4ad4 100644 --- a/color_test.go +++ b/color_test.go @@ -5,6 +5,10 @@ import ( "image/color" "reflect" "testing" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/widget" + "github.com/stretchr/testify/assert" ) func esc(s string) string { @@ -902,3 +906,26 @@ func TestHandleOutput_24_bit_colour(t *testing.T) { testColor(t, tests) } + +func TestHandleOutput_BufferCutoff(t *testing.T) { + term := New() + termsize := fyne.NewSize(80, 50) + term.Resize(termsize) + term.handleOutput([]byte("\x1b[38;5;64")) + term.handleOutput([]byte("m40\x1b[38;5;65m41")) + tg := widget.NewTextGrid() + tg.Resize(termsize) + c1 := &color.RGBA{R: 95, G: 135, A: 255} + c2 := &color.RGBA{R: 95, G: 135, B: 95, A: 255} + tg.Rows = []widget.TextGridRow{ + { + Cells: []widget.TextGridCell{ + {Rune: '4', Style: &widget.CustomTextGridStyle{FGColor: c1, BGColor: nil}}, + {Rune: '0', Style: &widget.CustomTextGridStyle{FGColor: c1, BGColor: nil}}, + {Rune: '4', Style: &widget.CustomTextGridStyle{FGColor: c2, BGColor: nil}}, + {Rune: '1', Style: &widget.CustomTextGridStyle{FGColor: c2, BGColor: nil}}, + }, + }, + } + assert.Equal(t, tg.Rows, term.content.Rows) +} diff --git a/output.go b/output.go index 3d54b817..00396d74 100644 --- a/output.go +++ b/output.go @@ -153,7 +153,7 @@ func (t *Terminal) handleOutput(buf []byte) []byte { // record progress for next chunk of buffer if t.state.esc != noEscape { - t.state.esc = -1 + t.state.esc = t.state.esc - i } return buf }