mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 04:54:18 +02:00
fix too wide tables when in !tty mode
This commit is contained in:
@@ -155,12 +155,16 @@ func (table *Table) PrintTSV() error {
|
||||
|
||||
for _, entries := range table.rows {
|
||||
currentWidth := 0
|
||||
columns := len(entries)
|
||||
|
||||
for idx, entry := range entries {
|
||||
length := visibleLen(entry)
|
||||
|
||||
if length+currentWidth > table.maxwidth && table.maxwidth-currentWidth > 1 {
|
||||
// // text is too wide to be put into one line, wrap it
|
||||
if length+currentWidth > table.maxwidth &&
|
||||
table.maxwidth-currentWidth > 1 &&
|
||||
idx == columns-1 {
|
||||
// text is too wide to be put into one line, and
|
||||
// it's the last cell, so wrap it
|
||||
entry = wrap(table.maxwidth-currentWidth, currentWidth+2, entry)
|
||||
}
|
||||
|
||||
@@ -193,6 +197,10 @@ func (table *Table) PrintTSV() error {
|
||||
// further lines will be indented. Used within Print() to print large
|
||||
// cell text.
|
||||
func wrap(width, indent int, text string) string {
|
||||
if len(text) <= width {
|
||||
return text
|
||||
}
|
||||
|
||||
wrapped := ""
|
||||
line := ""
|
||||
|
||||
@@ -267,7 +275,7 @@ func (table *Table) Addheaders(headers ...string) {
|
||||
case "json", "yaml":
|
||||
table.Headers[idx] = strings.ReplaceAll(strings.ToLower(header), " ", "_")
|
||||
default:
|
||||
table.Headers[idx] = bold(strings.ReplaceAll(strings.ToUpper(header), " ", "-"))
|
||||
table.Headers[idx] = Bold(strings.ReplaceAll(strings.ToUpper(header), " ", "-"))
|
||||
}
|
||||
|
||||
table.RawHeaders[idx] = header
|
||||
|
||||
Reference in New Issue
Block a user