summaryrefslogtreecommitdiff
path: root/humanTable.go
diff options
context:
space:
mode:
Diffstat (limited to 'humanTable.go')
-rw-r--r--humanTable.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/humanTable.go b/humanTable.go
index 050e7ec..09c9ff2 100644
--- a/humanTable.go
+++ b/humanTable.go
@@ -13,6 +13,37 @@ import (
// sizes := []int{40, 12, 6, 12, 16, 16, 16, 12, 12, 8}
// log.Info(standardTableSize10(sizes, args))
+// returns the line and the Sprintf fmt string
+func StandardTableRow(sizes []int, args []string) (string, string) {
+ var fmtline string
+ var line string
+ for i, si := range sizes {
+ var cell string
+ var sfmt string
+ if si == 0 {
+ sfmt = "%-s "
+ } else {
+ sfmt = "%-" + fmt.Sprintf("%d", si) + "." + fmt.Sprintf("%d", si) + "s "
+ }
+ fmtline += sfmt
+ if len(args) > i {
+ val := args[i]
+ cell = fmt.Sprintf(sfmt, val)
+ line += cell
+ } else {
+ break
+ }
+ }
+
+ var small int
+ if len(line) > WIDTH {
+ small = WIDTH
+ } else {
+ small = len(line) - 3
+ }
+ return line[0:small], fmtline
+}
+
func StandardTableSize5(sizes []int, args []string) string {
WIDTH, _ := getTerminalWidth()
var s string