WithPadding pads a string as much as you want
(str string, padding int, alignment Alignment)
| 36 | |
| 37 | // WithPadding pads a string as much as you want |
| 38 | func WithPadding(str string, padding int, alignment Alignment) string { |
| 39 | uncoloredStr := Decolorise(str) |
| 40 | width := StringWidth(uncoloredStr) |
| 41 | if padding < width { |
| 42 | return str |
| 43 | } |
| 44 | space := strings.Repeat(" ", padding-width) |
| 45 | if alignment == AlignLeft { |
| 46 | return str + space |
| 47 | } |
| 48 | return space + str |
| 49 | } |
| 50 | |
| 51 | // defaults to left-aligning each column. If you want to set the alignment of |
| 52 | // each column, pass in a slice of Alignment values. |