summaryrefslogtreecommitdiff
path: root/humanTable.go
diff options
context:
space:
mode:
Diffstat (limited to 'humanTable.go')
-rw-r--r--humanTable.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/humanTable.go b/humanTable.go
index 09c9ff2..6c94a60 100644
--- a/humanTable.go
+++ b/humanTable.go
@@ -4,6 +4,7 @@ package cobol
import (
"fmt"
+ "strings"
)
// TODO: make this more generic
@@ -15,33 +16,38 @@ import (
// returns the line and the Sprintf fmt string
func StandardTableRow(sizes []int, args []string) (string, string) {
- var fmtline string
- var line string
+ var fmts []string
+ var parts []string
for i, si := range sizes {
var cell string
var sfmt string
- if si == 0 {
- sfmt = "%-s "
+ if si < 0 {
+ sfmt = "%-s"
+ } else if si == 0 {
+ sfmt = "%-8.8s"
} else {
sfmt = "%-" + fmt.Sprintf("%d", si) + "." + fmt.Sprintf("%d", si) + "s "
}
- fmtline += sfmt
+ fmts = append(fmts, sfmt)
if len(args) > i {
val := args[i]
cell = fmt.Sprintf(sfmt, val)
- line += cell
+ parts = append(parts, cell)
} else {
break
}
}
+ // todo: change pad based on total size(?)
+ line := strings.Join(parts, " ")
+
var small int
if len(line) > WIDTH {
small = WIDTH
} else {
small = len(line) - 3
}
- return line[0:small], fmtline
+ return line[0:small], strings.Join(fmts, " ")
}
func StandardTableSize5(sizes []int, args []string) string {