added StringNoHead method
This commit is contained in:
parent
5be0ec3905
commit
4331b2ac29
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
table_header_test.go
|
25
table.go
25
table.go
@ -60,6 +60,31 @@ func (t *Table) AddRow(row ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Table) StringNoHead() string {
|
||||
b := new(strings.Builder)
|
||||
|
||||
b.WriteRune('┏')
|
||||
for i, colwidth := range t.colwidth {
|
||||
b.WriteString(strings.Repeat("━", colwidth))
|
||||
if i < len(t.colwidth)-1 {
|
||||
b.WriteRune('┯')
|
||||
}
|
||||
}
|
||||
b.WriteRune('┓')
|
||||
b.WriteRune('\n')
|
||||
|
||||
for i, row := range t.data {
|
||||
t.printRow(b, row, t.rowheight[i])
|
||||
if t.rowSep && i < len(t.data)-1 {
|
||||
t.addNextCellLine(b)
|
||||
}
|
||||
}
|
||||
|
||||
t.addLastCellLine(b)
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func (t *Table) String() string {
|
||||
b := new(strings.Builder)
|
||||
|
||||
|
@ -6,14 +6,21 @@ import (
|
||||
"git.milar.in/milarin/slices"
|
||||
)
|
||||
|
||||
// TODO FormatHeaderTable is a quick hack
|
||||
func FormatHeaderTable(header string, table *Table) string {
|
||||
return formatHeaderTableStr(header, table.String())
|
||||
}
|
||||
|
||||
func FormatHeaderTableNoHead(header string, table *Table) string {
|
||||
return formatHeaderTableStr(header, table.StringNoHead())
|
||||
}
|
||||
|
||||
// TODO formatHeaderTableStr is a quick hack
|
||||
// a better solution would be to support nested tables.
|
||||
// in that case, a header table is just a table with a singe col, single header row and single data row
|
||||
|
||||
func FormatHeaderTable(header string, table *Table) string {
|
||||
func formatHeaderTableStr(header string, tab string) string {
|
||||
b := new(strings.Builder)
|
||||
|
||||
tab := table.String()
|
||||
splits := strings.Split(tab, "\n")
|
||||
tabwidth := strLen(splits[0])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user