From b737910813d42352dc9514c9aee11be35519c4fe Mon Sep 17 00:00:00 2001 From: Aleksey Savchuk Date: Thu, 15 Aug 2024 00:51:41 +0300 Subject: [PATCH] [#1223] lens/tui: Fix records view update Signed-off-by: Aleksey Savchuk --- cmd/frostfs-lens/internal/tuiutil/input.go | 5 ----- cmd/frostfs-lens/internal/tuiutil/records.go | 21 ++++++++++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/cmd/frostfs-lens/internal/tuiutil/input.go b/cmd/frostfs-lens/internal/tuiutil/input.go index c5ba8c0e9..96b5a5afe 100644 --- a/cmd/frostfs-lens/internal/tuiutil/input.go +++ b/cmd/frostfs-lens/internal/tuiutil/input.go @@ -1,9 +1,6 @@ package tuiutil import ( - "fmt" - "os" - "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) @@ -41,8 +38,6 @@ func (f *InputFieldWithHistory) AddToHistory(s string) { func (f *InputFieldWithHistory) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) { return f.WrapInputHandler(func(event *tcell.EventKey, _ func(tview.Primitive)) { - fmt.Fprintln(os.Stderr, len(f.history)) - switch event.Key() { case tcell.KeyDown: if len(f.history) == 0 { diff --git a/cmd/frostfs-lens/internal/tuiutil/records.go b/cmd/frostfs-lens/internal/tuiutil/records.go index c128c63df..d38ed023a 100644 --- a/cmd/frostfs-lens/internal/tuiutil/records.go +++ b/cmd/frostfs-lens/internal/tuiutil/records.go @@ -84,7 +84,7 @@ func (v *RecordsView) Unmount() { v.onUnmount = nil } -func (v *RecordsView) Update(ctx context.Context) error { +func (v *RecordsView) Update(_ context.Context) error { _, _, _, recordsPerPage := v.GetInnerRect() newLastRecordIndex := v.firstRecordIndex + recordsPerPage @@ -98,15 +98,11 @@ func (v *RecordsView) Update(ctx context.Context) error { } for len(v.records) < newLastRecordIndex { - select { - case <-ctx.Done(): - return nil - case record, ok := <-v.buffer: - if !ok { - break - } - v.records = append(v.records, record) + record, ok := <-v.buffer + if !ok { + break } + v.records = append(v.records, record) } v.lastRecordIndex = min(len(v.records), newLastRecordIndex) @@ -115,7 +111,12 @@ func (v *RecordsView) Update(ctx context.Context) error { func (v *RecordsView) GetInnerRect() (int, int, int, int) { x, y, width, height := v.Box.GetInnerRect() - return x + 3, y + 1, width - 3, height - 1 + + // Padding. + x = min(x+3, x+width-1) + width = max(width-3, 0) + + return x, y, width, height } func (v *RecordsView) Draw(screen tcell.Screen) {