From d8bf918e83515f48564e0d0b98d30907944a1e0d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 8 Mar 2026 22:35:34 +0200 Subject: tui: unify table navigation and rendering --- internal/tui/dashboard/table.go | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 internal/tui/dashboard/table.go (limited to 'internal/tui/dashboard/table.go') diff --git a/internal/tui/dashboard/table.go b/internal/tui/dashboard/table.go new file mode 100644 index 0000000..c47b305 --- /dev/null +++ b/internal/tui/dashboard/table.go @@ -0,0 +1,46 @@ +package dashboard + +import ( + "fmt" + "strings" + + common "ior/internal/tui/common" + + "charm.land/lipgloss/v2" +) + +func renderSelectableTable(columns []common.TableColumn, rows [][]string, height, selectedRow, selectedCol int, rowHint string, extraHints ...string) string { + if len(rows) == 0 { + return "" + } + + selectedRow = clampOffset(selectedRow, len(rows)) + selectedCol = common.ClampTableCol(selectedCol, len(columns)) + start, end := common.VisibleTableWindow(selectedRow, len(rows), syscallTableHeight(height)) + + lines := make([]string, 0, end-start+2) + lines = append(lines, common.RenderTableHeader(columns)) + for idx := start; idx < end; idx++ { + col := -1 + if idx == selectedRow { + col = selectedCol + } + lines = append(lines, common.RenderTableRow(columns, rows[idx], idx == selectedRow, col, lipgloss.Style{})) + } + + hints := []string{fmt.Sprintf("Row %d/%d Col %d/%d", selectedRow+1, len(rows), selectedCol+1, len(columns))} + if rowHint != "" { + hints = append(hints, rowHint) + } + hints = append(hints, extraHints...) + lines = append(lines, "["+strings.Join(hints, "] [")+"]") + return strings.Join(lines, "\n") +} + +func tablePageStep(height int) int { + rows := syscallTableHeight(height) + if rows <= 1 { + return 1 + } + return rows - 1 +} -- cgit v1.2.3