summaryrefslogtreecommitdiff
path: root/humanTable.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-01 17:06:10 -0500
committerJeff Carr <[email protected]>2025-09-01 17:06:10 -0500
commit8e0697d0321a2d29da9b36f4320aa2fbdd4b8278 (patch)
tree0a9885b9c84caa9db0fe5cbf7a4c5b4f75e4a55c /humanTable.go
Diffstat (limited to 'humanTable.go')
-rw-r--r--humanTable.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/humanTable.go b/humanTable.go
new file mode 100644
index 0000000..3b3f8c3
--- /dev/null
+++ b/humanTable.go
@@ -0,0 +1,72 @@
+// Copyright 2025 WIT.COM Inc Licensed GPL 3.0
+
+package cobol
+
+import (
+ "fmt"
+)
+
+// TODO: make this more generic
+
+// print the header
+// args := []string{"namespace", "cur br", "age", "master", "devel", "last tag", "", "", "", ""}
+// sizes := []int{40, 12, 6, 12, 16, 16, 16, 12, 12, 8}
+// log.Info(standardTableSize10(sizes, args))
+
+func StandardTableSize5(sizes []int, args []string) string {
+ var s string
+ for i, si := range sizes {
+ if si == 0 {
+ s += "%-s "
+ } else {
+ s += "%-" + fmt.Sprintf("%d", si) + "s "
+ if len(args[i]) > sizes[i] {
+ args[i] = args[i][:sizes[i]]
+ }
+ }
+ }
+ // there must be a better syntax for this
+ arg1 := args[0]
+ arg2 := args[1]
+ arg3 := args[2]
+ arg4 := args[3]
+ arg5 := args[4]
+
+ return fmt.Sprintf(s, arg1, arg2, arg3, arg4, arg5)
+}
+
+/*
+func standardTable10(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 string) string {
+ args := []string{arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10}
+ sizes := []int{40, 12, 6, 12, 16, 16, 16, 12, 12, 8}
+
+ return standardTableSize10(sizes, args)
+}
+*/
+
+func StandardTableSize10(sizes []int, args []string) string {
+ var s string
+ for i, si := range sizes {
+ if si == 0 {
+ s += "%-s "
+ } else {
+ s += "%-" + fmt.Sprintf("%d", si) + "s "
+ if len(args[i]) > sizes[i] {
+ args[i] = args[i][:sizes[i]]
+ }
+ }
+ }
+ // there must be a better syntax for this
+ arg1 := args[0]
+ arg2 := args[1]
+ arg3 := args[2]
+ arg4 := args[3]
+ arg5 := args[4]
+ arg6 := args[5]
+ arg7 := args[6]
+ arg8 := args[7]
+ arg9 := args[8]
+ arg10 := args[9]
+
+ return fmt.Sprintf(s, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)
+}