summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-24 00:58:07 -0500
committerJeff Carr <[email protected]>2025-10-24 00:58:07 -0500
commit7bec8b594e0e3f567b8a5bfe3ec3a03706c56c4b (patch)
tree4a3e2a21dee1ec56f51e3d5435373c1409f28fc3
parent9ef254b7d90e59daea73f6d0b08eaa0e7eb1dc8d (diff)
some other simple tables
-rw-r--r--dumbTable.go59
1 files changed, 58 insertions, 1 deletions
diff --git a/dumbTable.go b/dumbTable.go
index 1e09caa..fe972a8 100644
--- a/dumbTable.go
+++ b/dumbTable.go
@@ -7,7 +7,10 @@ import (
"strings"
)
-func DumbTable(data string) {
+func DumbTable(data string) string {
+ if cursize, ok := getTerminalWidth(); ok {
+ TERMSIZE = cursize
+ }
lines := strings.Split(data, "\n")
var sizes []int
for _, line := range lines {
@@ -32,6 +35,60 @@ func DumbTable(data string) {
_ = fmtline
fmt.Println(line)
}
+ footer := fmt.Sprintf("DumbTable len=(%d) w=(%d) sizes=(%v)", len(data), TERMSIZE, sizes)
+ return footer
+}
+
+func SimpleTable(data [][]string) string {
+ if cursize, ok := getTerminalWidth(); ok {
+ TERMSIZE = cursize
+ }
+ var sizes []int
+ for _, parts := range data {
+ for i, part := range parts {
+ if i >= len(sizes) {
+ sizes = append(sizes, 0)
+ }
+ if sizes[i] < len(part) {
+ sizes[i] = len(part)
+ }
+ }
+ }
+ if (len(data) > 0) && (len(sizes) > 0) {
+ sizes[len(sizes)-1] = -1
+ SimpleTableSizes(data, sizes)
+ }
+ footer := fmt.Sprintf("SimpleTable() len=(%d) w=(%d) sizes=(%v)", len(data), TERMSIZE, sizes)
+ return footer
+}
+
+func SimpleTableSizes(data [][]string, sizes []int) string {
+ if cursize, ok := getTerminalWidth(); ok {
+ TERMSIZE = cursize
+ }
+ if (len(data) > 0) && (len(sizes) > 0) {
+ sizes[len(sizes)-1] = -1
+ for _, parts := range data {
+ line, fmtline := StandardTableRow(sizes, parts)
+ _ = fmtline
+ fmt.Println(line)
+ }
+ }
+ footer := fmt.Sprintf("SimpleTableSizes() len=(%d) w=(%d) sizes=(%v)", len(data), TERMSIZE, sizes)
+ return footer
+}
+
+func SimpleTableSizesDebug(data [][]string, sizes []int) string {
+ if cursize, ok := getTerminalWidth(); ok {
+ TERMSIZE = cursize
+ }
+ for _, parts := range data {
+ line, fmtline := StandardTableRowDebug(sizes, parts)
+ _ = fmtline
+ fmt.Println(line)
+ }
+ footer := fmt.Sprintf("records (%d) TERMSIZE (%d)", len(data), TERMSIZE)
+ return footer
}
func DumbTable3(lines []string) {