Compare commits
No commits in common. "main" and "v0.0.7" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
table_header_test.go
|
|
25
table.go
25
table.go
@ -60,31 +60,6 @@ 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 {
|
func (t *Table) String() string {
|
||||||
b := new(strings.Builder)
|
b := new(strings.Builder)
|
||||||
|
|
||||||
|
@ -6,21 +6,14 @@ import (
|
|||||||
"git.milar.in/milarin/slices"
|
"git.milar.in/milarin/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FormatHeaderTable(header string, table *Table) string {
|
// TODO FormatHeaderTable is a quick hack
|
||||||
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.
|
// 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
|
// in that case, a header table is just a table with a singe col, single header row and single data row
|
||||||
|
|
||||||
func formatHeaderTableStr(header string, tab string) string {
|
func FormatHeaderTable(header string, table *Table) string {
|
||||||
b := new(strings.Builder)
|
b := new(strings.Builder)
|
||||||
|
|
||||||
|
tab := table.String()
|
||||||
splits := strings.Split(tab, "\n")
|
splits := strings.Split(tab, "\n")
|
||||||
tabwidth := strLen(splits[0])
|
tabwidth := strLen(splits[0])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user