Skip to content

Commit

Permalink
Added support for right aligned columns
Browse files Browse the repository at this point in the history
  • Loading branch information
IsThisEvenCode committed Jun 6, 2024
1 parent 36f0991 commit f087678
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/utils/asciiTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
const maxLineLength = 120

type ASCIITableHeader struct {
Name string // name in table header
Field string // attribute name in data row
Centered bool // flag wether column is centered
size int // calculated max size of column
Name string // name in table header
Field string // attribute name in data row
Centered bool // flag whether column is centered
RightAligned bool // flag whether column is aligned to the right
size int // calculated max size of column

}

// ASCIITable creates an ascii table from columns and data rows
Expand Down Expand Up @@ -49,7 +51,11 @@ func ASCIITable(header []ASCIITableHeader, rows interface{}, escapePipes bool) (
rowVal := dataRows.Index(i)
for _, head := range header {
value, _ := asciiTableRowValue(escapePipes, rowVal, head)
out += fmt.Sprintf(fmt.Sprintf("| %%-%ds ", head.size), value)
if head.RightAligned {
out += fmt.Sprintf(fmt.Sprintf("| %%%ds ", head.size), value)
} else {
out += fmt.Sprintf(fmt.Sprintf("| %%-%ds ", head.size), value)
}
}
out += "|\n"
}
Expand Down

0 comments on commit f087678

Please sign in to comment.