summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dumbTable.go75
-rw-r--r--humanTable.go4
2 files changed, 79 insertions, 0 deletions
diff --git a/dumbTable.go b/dumbTable.go
new file mode 100644
index 0000000..66e5328
--- /dev/null
+++ b/dumbTable.go
@@ -0,0 +1,75 @@
+// Copyright 2025 WIT.COM Inc Licensed GPL 3.0
+
+package cobol
+
+import (
+ "strings"
+
+ "go.wit.com/log"
+)
+
+func DumbTable(data string) {
+ lines := strings.Split(data, "\n")
+ var sizes []int
+ for _, line := range lines {
+ line = strings.TrimSpace(line)
+ if line == "" {
+ continue
+ }
+ parts := strings.Fields(line)
+ for i, part := range parts {
+ if i >= len(sizes) {
+ sizes = append(sizes, 0)
+ }
+ if sizes[i] < len(part) {
+ sizes[i] = len(part)
+ }
+ }
+ }
+ // sizes := []int{size1, size2, size3}
+ for _, line := range lines {
+ parts := strings.Fields(line)
+ line, fmtline := StandardTableRow(sizes, parts)
+ _ = fmtline
+ log.Info(line)
+ }
+}
+
+func DumbTable3(lines []string) {
+ var size1 int
+ var size2 int
+ var size3 int
+ for _, line := range lines {
+ line = strings.TrimSpace(line)
+ if line == "" {
+ continue
+ }
+ parts := strings.Fields(line)
+ if len(parts) != 3 {
+ log.Info(parts)
+ panic("not 3 things")
+ continue
+ }
+ if size1 < len(parts[0]) {
+ size1 = len(parts[0])
+ }
+ if size2 < len(parts[1]) {
+ size2 = len(parts[1])
+ }
+ if size3 < len(parts[2]) {
+ size3 = len(parts[2])
+ }
+ }
+ sizes := []int{size1, size2, size3}
+ for _, line := range lines {
+ parts := strings.Fields(line)
+ if len(parts) != 3 {
+ log.Info(parts)
+ panic("not 3 things")
+ continue
+ }
+ line, fmtline := StandardTableRow(sizes, parts)
+ _ = fmtline
+ log.Info(line)
+ }
+}
diff --git a/humanTable.go b/humanTable.go
index 6486dcd..9fe164d 100644
--- a/humanTable.go
+++ b/humanTable.go
@@ -45,7 +45,11 @@ func StandardTableRow(sizes []int, args []string) (string, string) {
if len(line) > TERMSIZE {
small = TERMSIZE
} else {
+ // todo: do something else with this
small = len(line) - 3
+ if small < 0 {
+ small = 0
+ }
}
return line[0:small], strings.Join(fmts, " ")
}