mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
| datasource | package | from | to | | ---------- | ------------------------------- | ------ | ------ | | go | github.com/jedib0t/go-pretty/v6 | v6.7.5 | v6.7.8 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com>
71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
package table
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func (t *Table) RenderTSV() string {
|
|
t.initForRender(renderModeTSV)
|
|
|
|
var out strings.Builder
|
|
|
|
if t.numColumns > 0 {
|
|
if t.title != "" {
|
|
out.WriteString(t.title)
|
|
}
|
|
|
|
if t.autoIndex && len(t.rowsHeader) == 0 {
|
|
t.tsvRenderRow(&out, t.getAutoIndexColumnIDs(), renderHint{isAutoIndexRow: true, isHeaderRow: true})
|
|
}
|
|
|
|
t.tsvRenderRows(&out, t.rowsHeader, renderHint{isHeaderRow: true})
|
|
t.tsvRenderRows(&out, t.rows, renderHint{})
|
|
t.tsvRenderRows(&out, t.rowsFooter, renderHint{isFooterRow: true})
|
|
|
|
if t.caption != "" {
|
|
out.WriteRune('\n')
|
|
out.WriteString(t.caption)
|
|
}
|
|
}
|
|
|
|
return t.render(&out)
|
|
}
|
|
|
|
func (t *Table) tsvRenderRow(out *strings.Builder, row rowStr, hint renderHint) {
|
|
if out.Len() > 0 {
|
|
out.WriteRune('\n')
|
|
}
|
|
|
|
for idx, col := range row {
|
|
if idx == 0 && t.autoIndex {
|
|
if hint.isRegularRow() {
|
|
fmt.Fprint(out, hint.rowNumber)
|
|
}
|
|
out.WriteRune('\t')
|
|
}
|
|
|
|
if idx > 0 {
|
|
out.WriteRune('\t')
|
|
}
|
|
|
|
if strings.ContainsAny(col, "\t\n\"") || strings.Contains(col, " ") {
|
|
col = strings.ReplaceAll(col, "\"", "\"\"") // fix double-quotes
|
|
fmt.Fprintf(out, "\"%s\"", col)
|
|
} else {
|
|
out.WriteString(col)
|
|
}
|
|
}
|
|
|
|
for colIdx := len(row); colIdx < t.numColumns; colIdx++ {
|
|
out.WriteRune('\t')
|
|
}
|
|
}
|
|
|
|
func (t *Table) tsvRenderRows(out *strings.Builder, rows []rowStr, hint renderHint) {
|
|
for idx, row := range rows {
|
|
hint.rowNumber = idx + 1
|
|
t.tsvRenderRow(out, row, hint)
|
|
}
|
|
}
|