diff options
| author | Jeff Carr <[email protected]> | 2025-10-18 09:23:28 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-18 09:23:28 -0500 | 
| commit | 4a74e4af615b6f264c795cb664c55359f588c7c0 (patch) | |
| tree | 101e95331b66608b560e6e75ebd170a25833f96e | |
| parent | 0adadf274d3038074979a9a795d87f49575ff1e5 (diff) | |
make a smart totally useful DumbTable()v0.0.26
| -rw-r--r-- | dumbTable.go | 75 | ||||
| -rw-r--r-- | humanTable.go | 4 | 
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, " ")  }  | 
