[#1223] lens/tui: Fix records view update
All checks were successful
DCO action / DCO (pull_request) Successful in 1m28s
Tests and linters / Run gofumpt (pull_request) Successful in 1m28s
Build / Build Components (1.21) (pull_request) Successful in 2m3s
Build / Build Components (1.22) (pull_request) Successful in 2m25s
Vulncheck / Vulncheck (pull_request) Successful in 2m10s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m4s
Tests and linters / Tests (1.22) (pull_request) Successful in 3m14s
Tests and linters / Staticcheck (pull_request) Successful in 3m17s
Tests and linters / Tests (1.21) (pull_request) Successful in 3m27s
Tests and linters / Lint (pull_request) Successful in 3m42s
Tests and linters / Tests with -race (pull_request) Successful in 3m52s
Tests and linters / gopls check (pull_request) Successful in 3m52s

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
Aleksey Savchuk 2024-08-15 00:51:41 +03:00
parent 79050140c6
commit b737910813
No known key found for this signature in database
2 changed files with 11 additions and 15 deletions

View file

@ -1,9 +1,6 @@
package tuiutil package tuiutil
import ( import (
"fmt"
"os"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/rivo/tview" "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)) { func (f *InputFieldWithHistory) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
return f.WrapInputHandler(func(event *tcell.EventKey, _ func(tview.Primitive)) { return f.WrapInputHandler(func(event *tcell.EventKey, _ func(tview.Primitive)) {
fmt.Fprintln(os.Stderr, len(f.history))
switch event.Key() { switch event.Key() {
case tcell.KeyDown: case tcell.KeyDown:
if len(f.history) == 0 { if len(f.history) == 0 {

View file

@ -84,7 +84,7 @@ func (v *RecordsView) Unmount() {
v.onUnmount = nil v.onUnmount = nil
} }
func (v *RecordsView) Update(ctx context.Context) error { func (v *RecordsView) Update(_ context.Context) error {
_, _, _, recordsPerPage := v.GetInnerRect() _, _, _, recordsPerPage := v.GetInnerRect()
newLastRecordIndex := v.firstRecordIndex + recordsPerPage newLastRecordIndex := v.firstRecordIndex + recordsPerPage
@ -98,15 +98,11 @@ func (v *RecordsView) Update(ctx context.Context) error {
} }
for len(v.records) < newLastRecordIndex { for len(v.records) < newLastRecordIndex {
select { record, ok := <-v.buffer
case <-ctx.Done(): if !ok {
return nil break
case record, ok := <-v.buffer:
if !ok {
break
}
v.records = append(v.records, record)
} }
v.records = append(v.records, record)
} }
v.lastRecordIndex = min(len(v.records), newLastRecordIndex) 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) { func (v *RecordsView) GetInnerRect() (int, int, int, int) {
x, y, width, height := v.Box.GetInnerRect() 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) { func (v *RecordsView) Draw(screen tcell.Screen) {