diff -Nru golang-github-olekukonko-tablewriter-0.0.1/debian/changelog golang-github-olekukonko-tablewriter-0.0.4/debian/changelog --- golang-github-olekukonko-tablewriter-0.0.1/debian/changelog 2018-11-26 13:19:45.000000000 +0000 +++ golang-github-olekukonko-tablewriter-0.0.4/debian/changelog 2020-02-21 12:10:01.000000000 +0000 @@ -1,3 +1,18 @@ +golang-github-olekukonko-tablewriter (0.0.4-1) unstable; urgency=medium + + * New upstream version 0.0.4 + * debian/gbp.conf: Set debian-branch to debian/sid for DEP-14 conformance + * Update debian/watch to version=4 and to use filenamemangle + * Apply "cme fix dpkg" fixes: + - Change Priority from "extra" to "optional" + - Update debhelper dependency to "Build-Depends: debhelper-compat (= 12)" + - Bump Standards-Version to 4.5.0 (no change) + * Update dependency on golang-github-mattn-go-runewidth-dev + to (>= 0.7.0~) according to go.mod + * Simplify debian/rules with "dh_auto_install -- --no-binaries" + + -- Anthony Fok Fri, 21 Feb 2020 05:10:01 -0700 + golang-github-olekukonko-tablewriter (0.0.1-1) unstable; urgency=medium [ Alexandre Viau ] diff -Nru golang-github-olekukonko-tablewriter-0.0.1/debian/compat golang-github-olekukonko-tablewriter-0.0.4/debian/compat --- golang-github-olekukonko-tablewriter-0.0.1/debian/compat 2018-11-26 13:19:45.000000000 +0000 +++ golang-github-olekukonko-tablewriter-0.0.4/debian/compat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -10 diff -Nru golang-github-olekukonko-tablewriter-0.0.1/debian/control golang-github-olekukonko-tablewriter-0.0.4/debian/control --- golang-github-olekukonko-tablewriter-0.0.1/debian/control 2018-11-26 13:19:45.000000000 +0000 +++ golang-github-olekukonko-tablewriter-0.0.4/debian/control 2020-02-21 12:07:25.000000000 +0000 @@ -1,24 +1,26 @@ Source: golang-github-olekukonko-tablewriter -Section: devel -Priority: extra Maintainer: Debian Go Packaging Team -Uploaders: Tim Potter , Anthony Fok , Nobuhiro Iwamatsu -Build-Depends: debhelper (>= 10), +Uploaders: Tim Potter , + Anthony Fok , + Nobuhiro Iwamatsu +Section: devel +Testsuite: autopkgtest-pkg-go +Priority: optional +Build-Depends: debhelper-compat (= 12), dh-golang (>= 1.17~), golang-any, - golang-github-mattn-go-runewidth-dev -Standards-Version: 4.2.1 -Homepage: https://github.com/olekukonko/tablewriter + golang-github-mattn-go-runewidth-dev (>= 0.0.7~) +Standards-Version: 4.5.0 Vcs-Browser: https://salsa.debian.org/go-team/packages/golang-github-olekukonko-tablewriter Vcs-Git: https://salsa.debian.org/go-team/packages/golang-github-olekukonko-tablewriter.git +Homepage: https://github.com/olekukonko/tablewriter XS-Go-Import-Path: github.com/olekukonko/tablewriter -Testsuite: autopkgtest-pkg-go Package: golang-github-olekukonko-tablewriter-dev Architecture: all Depends: ${shlibs:Depends}, ${misc:Depends}, - golang-github-mattn-go-runewidth-dev + golang-github-mattn-go-runewidth-dev (>= 0.0.7~) Description: generate ASCII tables in Golang Library to generate ASCII tables using Go. Features automatic padding, multiple lines, alignment, custom separators, and much diff -Nru golang-github-olekukonko-tablewriter-0.0.1/debian/gbp.conf golang-github-olekukonko-tablewriter-0.0.4/debian/gbp.conf --- golang-github-olekukonko-tablewriter-0.0.1/debian/gbp.conf 2018-11-26 13:19:45.000000000 +0000 +++ golang-github-olekukonko-tablewriter-0.0.4/debian/gbp.conf 2020-02-21 12:01:39.000000000 +0000 @@ -1,2 +1,4 @@ [DEFAULT] +debian-branch = debian/sid +dist = DEP14 pristine-tar = True diff -Nru golang-github-olekukonko-tablewriter-0.0.1/debian/rules golang-github-olekukonko-tablewriter-0.0.4/debian/rules --- golang-github-olekukonko-tablewriter-0.0.1/debian/rules 2018-11-26 13:19:45.000000000 +0000 +++ golang-github-olekukonko-tablewriter-0.0.4/debian/rules 2020-02-21 12:09:15.000000000 +0000 @@ -7,5 +7,4 @@ dh $@ --buildsystem=golang --with=golang override_dh_auto_install: - dh_auto_install -O--buildsystem=golang - rm -rf debian/golang-github-olekukonko-tablewriter-dev/usr/bin/ + dh_auto_install -- --no-binaries diff -Nru golang-github-olekukonko-tablewriter-0.0.1/debian/watch golang-github-olekukonko-tablewriter-0.0.4/debian/watch --- golang-github-olekukonko-tablewriter-0.0.1/debian/watch 2018-11-26 13:19:45.000000000 +0000 +++ golang-github-olekukonko-tablewriter-0.0.4/debian/watch 2020-02-21 12:06:05.000000000 +0000 @@ -1,5 +1,5 @@ # uscan(1) configuration file. -version=3 - - https://github.com/olekukonko/tablewriter/releases \ - .*/archive/v?(\d[\d\.]+)\.tar\.gz +version=4 +opts="filenamemangle=s%(?:.*?)?v?(\d[\d.]*)\.tar\.gz%golang-github-olekukonko-tablewriter-$1.tar.gz%" \ + https://github.com/olekukonko/tablewriter/tags \ + (?:.*?/)?v?(\d[\d.]*)\.tar\.gz debian diff -Nru golang-github-olekukonko-tablewriter-0.0.1/go.mod golang-github-olekukonko-tablewriter-0.0.4/go.mod --- golang-github-olekukonko-tablewriter-0.0.1/go.mod 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-olekukonko-tablewriter-0.0.4/go.mod 2019-12-05 07:26:27.000000000 +0000 @@ -0,0 +1,5 @@ +module github.com/olekukonko/tablewriter + +go 1.12 + +require github.com/mattn/go-runewidth v0.0.7 diff -Nru golang-github-olekukonko-tablewriter-0.0.1/go.sum golang-github-olekukonko-tablewriter-0.0.4/go.sum --- golang-github-olekukonko-tablewriter-0.0.1/go.sum 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-olekukonko-tablewriter-0.0.4/go.sum 2019-12-05 07:26:27.000000000 +0000 @@ -0,0 +1,2 @@ +github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54= +github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= diff -Nru golang-github-olekukonko-tablewriter-0.0.1/README.md golang-github-olekukonko-tablewriter-0.0.4/README.md --- golang-github-olekukonko-tablewriter-0.0.1/README.md 2018-10-26 07:14:10.000000000 +0000 +++ golang-github-olekukonko-tablewriter-0.0.4/README.md 2019-12-05 07:26:27.000000000 +0000 @@ -78,14 +78,14 @@ ``` DATE | DESCRIPTION | CV2 | AMOUNT -+----------+--------------------------+-------+---------+ +-----------+--------------------------+-------+---------- 1/1/2014 | Domain name | 2233 | $10.98 1/1/2014 | January Hosting | 2233 | $54.95 1/4/2014 | February Hosting | 2233 | $51.00 1/4/2014 | February Extra Bandwidth | 2233 | $30.00 -+----------+--------------------------+-------+---------+ +-----------+--------------------------+-------+---------- TOTAL | $146 93 - +-------+---------+ + --------+---------- ``` @@ -233,7 +233,63 @@ #### Table with color Output ![Table with Color](https://cloud.githubusercontent.com/assets/6460392/21101956/bbc7b356-c0a1-11e6-9f36-dba694746efc.png) -#### Example 6 - Set table caption +#### Example - 7 Table Cells with Color + +Individual Cell Colors from `func Rich` take precedence over Column Colors + +```go +data := [][]string{ + []string{"Test1Merge", "HelloCol2 - 1", "HelloCol3 - 1", "HelloCol4 - 1"}, + []string{"Test1Merge", "HelloCol2 - 2", "HelloCol3 - 2", "HelloCol4 - 2"}, + []string{"Test1Merge", "HelloCol2 - 3", "HelloCol3 - 3", "HelloCol4 - 3"}, + []string{"Test2Merge", "HelloCol2 - 4", "HelloCol3 - 4", "HelloCol4 - 4"}, + []string{"Test2Merge", "HelloCol2 - 5", "HelloCol3 - 5", "HelloCol4 - 5"}, + []string{"Test2Merge", "HelloCol2 - 6", "HelloCol3 - 6", "HelloCol4 - 6"}, + []string{"Test2Merge", "HelloCol2 - 7", "HelloCol3 - 7", "HelloCol4 - 7"}, + []string{"Test3Merge", "HelloCol2 - 8", "HelloCol3 - 8", "HelloCol4 - 8"}, + []string{"Test3Merge", "HelloCol2 - 9", "HelloCol3 - 9", "HelloCol4 - 9"}, + []string{"Test3Merge", "HelloCol2 - 10", "HelloCol3 -10", "HelloCol4 - 10"}, +} + +table := tablewriter.NewWriter(os.Stdout) +table.SetHeader([]string{"Col1", "Col2", "Col3", "Col4"}) +table.SetFooter([]string{"", "", "Footer3", "Footer4"}) +table.SetBorder(false) + +table.SetHeaderColor(tablewriter.Colors{tablewriter.Bold, tablewriter.BgGreenColor}, + tablewriter.Colors{tablewriter.FgHiRedColor, tablewriter.Bold, tablewriter.BgBlackColor}, + tablewriter.Colors{tablewriter.BgRedColor, tablewriter.FgWhiteColor}, + tablewriter.Colors{tablewriter.BgCyanColor, tablewriter.FgWhiteColor}) + +table.SetColumnColor(tablewriter.Colors{tablewriter.Bold, tablewriter.FgHiBlackColor}, + tablewriter.Colors{tablewriter.Bold, tablewriter.FgHiRedColor}, + tablewriter.Colors{tablewriter.Bold, tablewriter.FgHiBlackColor}, + tablewriter.Colors{tablewriter.Bold, tablewriter.FgBlackColor}) + +table.SetFooterColor(tablewriter.Colors{}, tablewriter.Colors{}, + tablewriter.Colors{tablewriter.Bold}, + tablewriter.Colors{tablewriter.FgHiRedColor}) + +colorData1 := []string{"TestCOLOR1Merge", "HelloCol2 - COLOR1", "HelloCol3 - COLOR1", "HelloCol4 - COLOR1"} +colorData2 := []string{"TestCOLOR2Merge", "HelloCol2 - COLOR2", "HelloCol3 - COLOR2", "HelloCol4 - COLOR2"} + +for i, row := range data { + if i == 4 { + table.Rich(colorData1, []tablewriter.Colors{tablewriter.Colors{}, tablewriter.Colors{tablewriter.Normal, tablewriter.FgCyanColor}, tablewriter.Colors{tablewriter.Bold, tablewriter.FgWhiteColor}, tablewriter.Colors{}}) + table.Rich(colorData2, []tablewriter.Colors{tablewriter.Colors{tablewriter.Normal, tablewriter.FgMagentaColor}, tablewriter.Colors{}, tablewriter.Colors{tablewriter.Bold, tablewriter.BgRedColor}, tablewriter.Colors{tablewriter.FgHiGreenColor, tablewriter.Italic, tablewriter.BgHiCyanColor}}) + } + table.Append(row) +} + +table.SetAutoMergeCells(true) +table.Render() + +``` + +##### Table cells with color Output +![Table cells with Color](https://user-images.githubusercontent.com/9064687/63969376-bcd88d80-ca6f-11e9-9466-c3d954700b25.png) + +#### Example 8 - Set table caption ```go data := [][]string{ []string{"A", "The Good", "500"}, @@ -254,7 +310,7 @@ Note: Caption text will wrap with total width of rendered table. -##### Output 6 +##### Output 7 ``` +------+-----------------------+--------+ | NAME | SIGN | RATING | @@ -267,6 +323,69 @@ Movie ratings. ``` +#### Example 8 - Set NoWhiteSpace and TablePadding option +```go +data := [][]string{ + {"node1.example.com", "Ready", "compute", "1.11"}, + {"node2.example.com", "Ready", "compute", "1.11"}, + {"node3.example.com", "Ready", "compute", "1.11"}, + {"node4.example.com", "NotReady", "compute", "1.11"}, +} + +table := tablewriter.NewWriter(os.Stdout) +table.SetHeader([]string{"Name", "Status", "Role", "Version"}) +table.SetAutoWrapText(false) +table.SetAutoFormatHeaders(true) +table.SetHeaderAlignment(ALIGN_LEFT) +table.SetAlignment(ALIGN_LEFT) +table.SetCenterSeparator("") +table.SetColumnSeparator("") +table.SetRowSeparator("") +table.SetHeaderLine(false) +table.SetBorder(false) +table.SetTablePadding("\t") // pad with tabs +table.SetNoWhiteSpace(true) +table.AppendBulk(data) // Add Bulk Data +table.Render() +``` + +##### Output 8 +``` +NAME STATUS ROLE VERSION +node1.example.com Ready compute 1.11 +node2.example.com Ready compute 1.11 +node3.example.com Ready compute 1.11 +node4.example.com NotReady compute 1.11 +``` + +#### Render table into a string + +Instead of rendering the table to `io.Stdout` you can also render it into a string. Go 1.10 introduced the `strings.Builder` type which implements the `io.Writer` interface and can therefore be used for this task. Example: + +```go +package main + +import ( + "strings" + "fmt" + + "github.com/olekukonko/tablewriter" +) + +func main() { + tableString := &strings.Builder{} + table := tablewriter.NewWriter(tableString) + + /* + * Code to fill the table + */ + + table.Render() + + fmt.Println(tableString.String()) +} +``` + #### TODO - ~~Import Directly from CSV~~ - `done` - ~~Support for `SetFooter`~~ - `done` diff -Nru golang-github-olekukonko-tablewriter-0.0.1/table.go golang-github-olekukonko-tablewriter-0.0.4/table.go --- golang-github-olekukonko-tablewriter-0.0.1/table.go 2018-10-26 07:14:10.000000000 +0000 +++ golang-github-olekukonko-tablewriter-0.0.4/table.go 2019-12-05 07:26:27.000000000 +0000 @@ -72,6 +72,8 @@ newLine string rowLine bool autoMergeCells bool + noWhiteSpace bool + tablePadding string hdrLine bool borders Border colSize int @@ -225,6 +227,16 @@ t.align = align } +// Set No White Space +func (t *Table) SetNoWhiteSpace(allow bool) { + t.noWhiteSpace = allow +} + +// Set Table Padding +func (t *Table) SetTablePadding(padding string) { + t.tablePadding = padding +} + func (t *Table) SetColumnAlignment(keys []int) { for _, v := range keys { switch v { @@ -296,6 +308,33 @@ t.lines = append(t.lines, line) } +// Append row to table with color attributes +func (t *Table) Rich(row []string, colors []Colors) { + rowSize := len(t.headers) + if rowSize > t.colSize { + t.colSize = rowSize + } + + n := len(t.lines) + line := [][]string{} + for i, v := range row { + + // Detect string width + // Detect String height + // Break strings into words + out := t.parseDimension(v, i, n) + + if len(colors) > i { + color := colors[i] + out[0] = format(out[0], color) + } + + // Append broken words + line = append(line, out) + } + t.lines = append(t.lines, line) +} + // Allow Support for Bulk Append // Eliminates repeated for loops func (t *Table) AppendBulk(rows [][]string) { @@ -319,16 +358,29 @@ t.footers = [][]string{} } +// Center based on position and border. +func (t *Table) center(i int) string { + if i == -1 && !t.borders.Left { + return t.pRow + } + + if i == len(t.cs)-1 && !t.borders.Right { + return t.pRow + } + + return t.pCenter +} + // Print line based on row width func (t *Table) printLine(nl bool) { - fmt.Fprint(t.out, t.pCenter) + fmt.Fprint(t.out, t.center(-1)) for i := 0; i < len(t.cs); i++ { v := t.cs[i] fmt.Fprintf(t.out, "%s%s%s%s", t.pRow, strings.Repeat(string(t.pRow), v), t.pRow, - t.pCenter) + t.center(i)) } if nl { fmt.Fprint(t.out, t.newLine) @@ -398,11 +450,14 @@ for x := 0; x < max; x++ { // Check if border is set // Replace with space if not set - fmt.Fprint(t.out, ConditionString(t.borders.Left, t.pColumn, SPACE)) + if !t.noWhiteSpace { + fmt.Fprint(t.out, ConditionString(t.borders.Left, t.pColumn, SPACE)) + } for y := 0; y <= end; y++ { v := t.cs[y] h := "" + if y < len(t.headers) && x < len(t.headers[y]) { h = t.headers[y][x] } @@ -410,15 +465,30 @@ h = Title(h) } pad := ConditionString((y == end && !t.borders.Left), SPACE, t.pColumn) - + if t.noWhiteSpace { + pad = ConditionString((y == end && !t.borders.Left), SPACE, t.tablePadding) + } if is_esc_seq { - fmt.Fprintf(t.out, " %s %s", - format(padFunc(h, SPACE, v), - t.headerParams[y]), pad) + if !t.noWhiteSpace { + fmt.Fprintf(t.out, " %s %s", + format(padFunc(h, SPACE, v), + t.headerParams[y]), pad) + } else { + fmt.Fprintf(t.out, "%s %s", + format(padFunc(h, SPACE, v), + t.headerParams[y]), pad) + } } else { - fmt.Fprintf(t.out, " %s %s", - padFunc(h, SPACE, v), - pad) + if !t.noWhiteSpace { + fmt.Fprintf(t.out, " %s %s", + padFunc(h, SPACE, v), + pad) + } else { + // the spaces between breaks the kube formatting + fmt.Fprintf(t.out, "%s%s", + padFunc(h, SPACE, v), + pad) + } } } // Next line @@ -517,6 +587,9 @@ // Print first junction if i == 0 { + if length > 0 && !t.borders.Left { + center = t.pRow + } fmt.Fprint(t.out, center) } @@ -524,16 +597,27 @@ if length == 0 { pad = SPACE } - // Ignore left space of it has printed before + // Ignore left space as it has printed before if hasPrinted || t.borders.Left { pad = t.pRow center = t.pCenter } + // Change Center end position + if center != SPACE { + if i == end && !t.borders.Right { + center = t.pRow + } + } + // Change Center start position if center == SPACE { if i < end && len(t.footers[i+1][0]) != 0 { - center = t.pCenter + if !t.borders.Left { + center = t.pRow + } else { + center = t.pCenter + } } } @@ -627,9 +711,11 @@ for y := 0; y < total; y++ { // Check if border is set - fmt.Fprint(t.out, ConditionString((!t.borders.Left && y == 0), SPACE, t.pColumn)) + if !t.noWhiteSpace { + fmt.Fprint(t.out, ConditionString((!t.borders.Left && y == 0), SPACE, t.pColumn)) + fmt.Fprintf(t.out, SPACE) + } - fmt.Fprintf(t.out, SPACE) str := columns[y][x] // Embedding escape sequence with column value @@ -661,11 +747,17 @@ } } - fmt.Fprintf(t.out, SPACE) + if !t.noWhiteSpace { + fmt.Fprintf(t.out, SPACE) + } else { + fmt.Fprintf(t.out, t.tablePadding) + } } // Check if border is set // Replace with space if not set - fmt.Fprint(t.out, ConditionString(t.borders.Left, t.pColumn, SPACE)) + if !t.noWhiteSpace { + fmt.Fprint(t.out, ConditionString(t.borders.Left, t.pColumn, SPACE)) + } fmt.Fprint(t.out, t.newLine) } @@ -706,6 +798,11 @@ // Pad Each Height pads := []int{} + // Checking for ANSI escape sequences for columns + is_esc_seq := false + if len(t.columnsParams) > 0 { + is_esc_seq = true + } for i, line := range columns { length := len(line) pad := max - length @@ -727,9 +824,14 @@ str := columns[y][x] + // Embedding escape sequence with column value + if is_esc_seq { + str = format(str, t.columnsParams[y]) + } + if t.autoMergeCells { //Store the full line to merge mutli-lines cells - fullLine := strings.Join(columns[y], " ") + fullLine := strings.TrimRight(strings.Join(columns[y], " "), " ") if len(previousLine) > y && fullLine == previousLine[y] && fullLine != "" { // If this cell is identical to the one above but not empty, we don't display the border and keep the cell empty. displayCellBorder = append(displayCellBorder, false) @@ -767,7 +869,7 @@ //The new previous line is the current one previousLine = make([]string, total) for y := 0; y < total; y++ { - previousLine[y] = strings.Join(columns[y], " ") //Store the full line for multi-lines cells + previousLine[y] = strings.TrimRight(strings.Join(columns[y], " "), " ") //Store the full line for multi-lines cells } //Returns the newly added line and wether or not a border should be displayed above. return previousLine, displayCellBorder diff -Nru golang-github-olekukonko-tablewriter-0.0.1/table_test.go golang-github-olekukonko-tablewriter-0.0.4/table_test.go --- golang-github-olekukonko-tablewriter-0.0.1/table_test.go 2018-10-26 07:14:10.000000000 +0000 +++ golang-github-olekukonko-tablewriter-0.0.4/table_test.go 2019-12-05 07:26:27.000000000 +0000 @@ -131,7 +131,7 @@ got := buf.String() want := ` FIELD | TYPE | NULL | KEY | DEFAULT | EXTRA -+----------+--------------+------+-----+---------+----------------+ +-----------+--------------+------+-----+---------+----------------- user_id | smallint(5) | NO | PRI | NULL | auto_increment username | varchar(10) | NO | | NULL | password | varchar(100) | NO | | NULL | @@ -187,7 +187,7 @@ table.Render() want := ` DATE | DESCRIPTION | CV2 | AMOUNT -+----------+--------------------------+-------+---------+ +-----------+--------------------------+-------+---------- 1/1/2014 | Domain name | 2233 | $10.98 1/1/2014 | January Hosting | 2233 | $54.95 | (empty) | | @@ -195,9 +195,9 @@ 1/4/2014 | February Hosting | 2233 | $51.00 1/4/2014 | February Extra Bandwidth | 2233 | $30.00 1/4/2014 | (Discount) | 2233 | -$1.00 -+----------+--------------------------+-------+---------+ +-----------+--------------------------+-------+---------- TOTAL | $145.93 - +-------+---------+ + --------+---------- ` checkEqual(t, buf.String(), want, "border table rendering failed") @@ -395,14 +395,14 @@ table.Render() want := ` DATE | DESCRIPTION | CV2 | AMOUNT -+----------+--------------------------+-------+---------+ +-----------+--------------------------+-------+---------- 1/1/2014 | Domain name | 2233 | $10.98 1/1/2014 | January Hosting | 2233 | $54.95 1/4/2014 | February Hosting | 2233 | $51.00 1/4/2014 | February Extra Bandwidth | 2233 | $30.00 -+----------+--------------------------+-------+---------+ +-----------+--------------------------+-------+---------- TOTAL | $146.93 - +-------+---------+ + --------+---------- This is a very long caption. The text should wrap to the width of the table. ` @@ -841,8 +841,8 @@ | NAME | SIGN | RATING | +------+--------------------------------+--------+ | A | The Good | 500 | -+------+--------------------------------+--------+ -| A | The Very very very very very | 288 | ++ +--------------------------------+--------+ +| | The Very very very very very | 288 | | | Bad Man | | +------+ +--------+ | B | | 120 | @@ -852,6 +852,32 @@ +------+--------------------------------+--------+ ` checkEqual(t, buf.String(), want) + + buf.Reset() + table = NewWriter(&buf) + table.SetHeader([]string{"Name", "Sign", "Rating"}) + + dataWithlongText2 := [][]string{ + {"A", "The Good", "500"}, + {"A", "The Very very very very very Bad Man", "288"}, + {"B", "The Very very Bad Man", "120"}, + } + table.AppendBulk(dataWithlongText2) + table.SetAutoMergeCells(true) + table.SetRowLine(true) + table.Render() + want = `+------+--------------------------------+--------+ +| NAME | SIGN | RATING | ++------+--------------------------------+--------+ +| A | The Good | 500 | ++ +--------------------------------+--------+ +| | The Very very very very very | 288 | +| | Bad Man | | ++------+--------------------------------+--------+ +| B | The Very very Bad Man | 120 | ++------+--------------------------------+--------+ +` + checkEqual(t, buf.String(), want) } func TestClearRows(t *testing.T) { @@ -1119,3 +1145,38 @@ } } } + +func TestKubeFormat(t *testing.T) { + data := [][]string{ + {"1/1/2014", "jan_hosting", "2233", "$10.98"}, + {"1/1/2014", "feb_hosting", "2233", "$54.95"}, + {"1/4/2014", "feb_extra_bandwidth", "2233", "$51.00"}, + {"1/4/2014", "mar_hosting", "2233", "$30.00"}, + } + + var buf bytes.Buffer + table := NewWriter(&buf) + table.SetHeader([]string{"Date", "Description", "CV2", "Amount"}) + table.SetAutoWrapText(false) + table.SetAutoFormatHeaders(true) + table.SetHeaderAlignment(ALIGN_LEFT) + table.SetAlignment(ALIGN_LEFT) + table.SetCenterSeparator("") + table.SetColumnSeparator("") + table.SetRowSeparator("") + table.SetHeaderLine(false) + table.SetBorder(false) + table.SetTablePadding("\t") // pad with tabs + table.SetNoWhiteSpace(true) + table.AppendBulk(data) // Add Bulk Data + table.Render() + + want := `DATE DESCRIPTION CV2 AMOUNT +1/1/2014 jan_hosting 2233 $10.98 +1/1/2014 feb_hosting 2233 $54.95 +1/4/2014 feb_extra_bandwidth 2233 $51.00 +1/4/2014 mar_hosting 2233 $30.00 +` + + checkEqual(t, buf.String(), want, "kube format rendering failed") +} diff -Nru golang-github-olekukonko-tablewriter-0.0.1/table_with_color.go golang-github-olekukonko-tablewriter-0.0.4/table_with_color.go --- golang-github-olekukonko-tablewriter-0.0.1/table_with_color.go 2018-10-26 07:14:10.000000000 +0000 +++ golang-github-olekukonko-tablewriter-0.0.4/table_with_color.go 2019-12-05 07:26:27.000000000 +0000 @@ -89,6 +89,8 @@ seq = v case []int: seq = makeSequence(v) + case Colors: + seq = makeSequence(v) default: return s } diff -Nru golang-github-olekukonko-tablewriter-0.0.1/util.go golang-github-olekukonko-tablewriter-0.0.4/util.go --- golang-github-olekukonko-tablewriter-0.0.1/util.go 2018-10-26 07:14:10.000000000 +0000 +++ golang-github-olekukonko-tablewriter-0.0.4/util.go 2019-12-05 07:26:27.000000000 +0000 @@ -61,7 +61,7 @@ } // Pad String -// Attempts to play string in the center +// Attempts to place string in the center func Pad(s, pad string, width int) string { gap := width - DisplayWidth(s) if gap > 0 { @@ -73,7 +73,7 @@ } // Pad String Right position -// This would pace string at the left side fo the screen +// This would place string at the left side of the screen func PadRight(s, pad string, width int) string { gap := width - DisplayWidth(s) if gap > 0 { @@ -83,7 +83,7 @@ } // Pad String Left position -// This would pace string at the right side fo the screen +// This would place string at the right side of the screen func PadLeft(s, pad string, width int) string { gap := width - DisplayWidth(s) if gap > 0 {