diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-08 22:35:34 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-08 22:35:34 +0200 |
| commit | d8bf918e83515f48564e0d0b98d30907944a1e0d (patch) | |
| tree | ed155b0c365b0d322494a96ff799c3a59a1d9ec8 /internal/tui/dashboard/table.go | |
| parent | 9f21f1004beeac10be9223bc8c5514261e397b6e (diff) | |
tui: unify table navigation and rendering
Diffstat (limited to 'internal/tui/dashboard/table.go')
| -rw-r--r-- | internal/tui/dashboard/table.go | 46 |
1 files changed, 46 insertions, 0 deletions
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 +} |
