ASCII table in golang

Related tags

tablewriter
Overview

ASCII Table Writer

ci Total views Godoc

Generate ASCII table on the fly ... Installation is simple as

go get github.com/olekukonko/tablewriter

Features

  • Automatic Padding
  • Support Multiple Lines
  • Supports Alignment
  • Support Custom Separators
  • Automatic Alignment of numbers & percentage
  • Write directly to http , file etc via io.Writer
  • Read directly from CSV file
  • Optional row line via SetRowLine
  • Normalise table header
  • Make CSV Headers optional
  • Enable or disable table border
  • Set custom footer support
  • Optional identical cells merging
  • Set custom caption
  • Optional reflowing of paragraphs in multi-line cells.

Example 1 - Basic

data := [][]string{
    []string{"A", "The Good", "500"},
    []string{"B", "The Very very Bad Man", "288"},
    []string{"C", "The Ugly", "120"},
    []string{"D", "The Gopher", "800"},
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Sign", "Rating"})

for _, v := range data {
    table.Append(v)
}
table.Render() // Send output
Output 1
+------+-----------------------+--------+
| NAME |         SIGN          | RATING |
+------+-----------------------+--------+
|  A   |       The Good        |    500 |
|  B   | The Very very Bad Man |    288 |
|  C   |       The Ugly        |    120 |
|  D   |      The Gopher       |    800 |
+------+-----------------------+--------+

Example 2 - Without Border / Footer / Bulk Append

data := [][]string{
    []string{"1/1/2014", "Domain name", "2233", "$10.98"},
    []string{"1/1/2014", "January Hosting", "2233", "$54.95"},
    []string{"1/4/2014", "February Hosting", "2233", "$51.00"},
    []string{"1/4/2014", "February Extra Bandwidth", "2233", "$30.00"},
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Date", "Description", "CV2", "Amount"})
table.SetFooter([]string{"", "", "Total", "$146.93"}) // Add Footer
table.SetBorder(false)                                // Set Border to false
table.AppendBulk(data)                                // Add Bulk Data
table.Render()
Output 2

    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
                                      --------+----------

Example 3 - CSV

table, _ := tablewriter.NewCSV(os.Stdout, "testdata/test_info.csv", true)
table.SetAlignment(tablewriter.ALIGN_LEFT)   // Set Alignment
table.Render()
Output 3
+----------+--------------+------+-----+---------+----------------+
|  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    |                |
+----------+--------------+------+-----+---------+----------------+

Example 4 - Custom Separator

table, _ := tablewriter.NewCSV(os.Stdout, "testdata/test.csv", true)
table.SetRowLine(true)         // Enable row line

// Change table lines
table.SetCenterSeparator("*")
table.SetColumnSeparator("╪")
table.SetRowSeparator("-")

table.SetAlignment(tablewriter.ALIGN_LEFT)
table.Render()
Output 4
*------------*-----------*---------*
╪ FIRST NAME ╪ LAST NAME ╪   SSN   ╪
*------------*-----------*---------*
╪ John       ╪ Barry     ╪ 123456  ╪
*------------*-----------*---------*
╪ Kathy      ╪ Smith     ╪ 687987  ╪
*------------*-----------*---------*
╪ Bob        ╪ McCornick ╪ 3979870 ╪
*------------*-----------*---------*

Example 5 - Markdown Format

data := [][]string{
	[]string{"1/1/2014", "Domain name", "2233", "$10.98"},
	[]string{"1/1/2014", "January Hosting", "2233", "$54.95"},
	[]string{"1/4/2014", "February Hosting", "2233", "$51.00"},
	[]string{"1/4/2014", "February Extra Bandwidth", "2233", "$30.00"},
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Date", "Description", "CV2", "Amount"})
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
table.AppendBulk(data) // Add Bulk Data
table.Render()
Output 5
|   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 |

Example 6 - Identical cells merging

data := [][]string{
  []string{"1/1/2014", "Domain name", "1234", "$10.98"},
  []string{"1/1/2014", "January Hosting", "2345", "$54.95"},
  []string{"1/4/2014", "February Hosting", "3456", "$51.00"},
  []string{"1/4/2014", "February Extra Bandwidth", "4567", "$30.00"},
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Date", "Description", "CV2", "Amount"})
table.SetFooter([]string{"", "", "Total", "$146.93"})
table.SetAutoMergeCells(true)
table.SetRowLine(true)
table.AppendBulk(data)
table.Render()
Output 6
+----------+--------------------------+-------+---------+
|   DATE   |       DESCRIPTION        |  CV2  | AMOUNT  |
+----------+--------------------------+-------+---------+
| 1/1/2014 | Domain name              |  1234 | $10.98  |
+          +--------------------------+-------+---------+
|          | January Hosting          |  2345 | $54.95  |
+----------+--------------------------+-------+---------+
| 1/4/2014 | February Hosting         |  3456 | $51.00  |
+          +--------------------------+-------+---------+
|          | February Extra Bandwidth |  4567 | $30.00  |
+----------+--------------------------+-------+---------+
|                                       TOTAL | $146 93 |
+----------+--------------------------+-------+---------+

Example 7 - Identical cells merging (specify the column index to merge)

data := [][]string{
  []string{"1/1/2014", "Domain name", "1234", "$10.98"},
  []string{"1/1/2014", "January Hosting", "1234", "$10.98"},
  []string{"1/4/2014", "February Hosting", "3456", "$51.00"},
  []string{"1/4/2014", "February Extra Bandwidth", "4567", "$30.00"},
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Date", "Description", "CV2", "Amount"})
table.SetFooter([]string{"", "", "Total", "$146.93"})
table.SetAutoMergeCellsByColumnIndex([]int{2, 3})
table.SetRowLine(true)
table.AppendBulk(data)
table.Render()
Output 7
+----------+--------------------------+-------+---------+
|   DATE   |       DESCRIPTION        |  CV2  | AMOUNT  |
+----------+--------------------------+-------+---------+
| 1/1/2014 | Domain name              |  1234 | $10.98  |
+----------+--------------------------+       +         +
| 1/1/2014 | January Hosting          |       |         |
+----------+--------------------------+-------+---------+
| 1/4/2014 | February Hosting         |  3456 | $51.00  |
+----------+--------------------------+-------+---------+
| 1/4/2014 | February Extra Bandwidth |  4567 | $30.00  |
+----------+--------------------------+-------+---------+
|                                       TOTAL | $146.93 |
+----------+--------------------------+-------+---------+

Table with color

data := [][]string{
	[]string{"1/1/2014", "Domain name", "2233", "$10.98"},
	[]string{"1/1/2014", "January Hosting", "2233", "$54.95"},
	[]string{"1/4/2014", "February Hosting", "2233", "$51.00"},
	[]string{"1/4/2014", "February Extra Bandwidth", "2233", "$30.00"},
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Date", "Description", "CV2", "Amount"})
table.SetFooter([]string{"", "", "Total", "$146.93"}) // Add Footer
table.SetBorder(false)                                // Set Border to 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})

table.AppendBulk(data)
table.Render()

Table with color Output

Table with Color

Example - 8 Table Cells with Color

Individual Cell Colors from func Rich take precedence over Column Colors

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

Example 9 - Set table caption

data := [][]string{
    []string{"A", "The Good", "500"},
    []string{"B", "The Very very Bad Man", "288"},
    []string{"C", "The Ugly", "120"},
    []string{"D", "The Gopher", "800"},
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Sign", "Rating"})
table.SetCaption(true, "Movie ratings.")

for _, v := range data {
    table.Append(v)
}
table.Render() // Send output

Note: Caption text will wrap with total width of rendered table.

Output 9
+------+-----------------------+--------+
| NAME |         SIGN          | RATING |
+------+-----------------------+--------+
|  A   |       The Good        |    500 |
|  B   | The Very very Bad Man |    288 |
|  C   |       The Ugly        |    120 |
|  D   |      The Gopher       |    800 |
+------+-----------------------+--------+
Movie ratings.

Example 10 - Set NoWhiteSpace and TablePadding option

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 10
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:

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
  • Support for SetBorder - done
  • Support table with uneven rows - done
  • Support custom alignment
  • General Improvement & Optimisation
  • NewHTML Parse table from HTML
Issues
  • Add SetNoWhiteSpace and SetTablePadding options to have more kubectl like output

    Add SetNoWhiteSpace and SetTablePadding options to have more kubectl like output

    Description

    This adds the ability to output table data much more like kubectl by removing the white space at the start of rows. It also introduces a padding option so you can choose either spaces or tab as the padding between columns

    An example has been added to the README, but is posted here for visibility

    A test has also been written

    Example

    ExampleSet KubeFormat option

    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(tablewriter.ALIGN_LEFT)
    table.SetAlignment(tablewriter.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
    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   	
    

    Closes

    This PR should close #129

    opened by shreddedbacon 11
  • Allow caption functionality for table

    Allow caption functionality for table

    Example - Set table caption

    data := [][]string{
        []string{"A", "The Good", "500"},
        []string{"B", "The Very very Bad Man", "288"},
        []string{"C", "The Ugly", "120"},
        []string{"D", "The Gopher", "800"},
    }
    
    table := tablewriter.NewWriter(os.Stdout)
    table.SetHeader([]string{"Name", "Sign", "Rating"})
    table.SetCaption(true, "Movie ratings.")
    
    for _, v := range data {
        table.Append(v)
    }
    table.Render() // Send output
    

    Note: Caption text will wrap with total width of rendered table.

    Output
    +------+-----------------------+--------+
    | NAME |         SIGN          | RATING |
    +------+-----------------------+--------+
    |  A   |       The Good        |    500 |
    |  B   | The Very very Bad Man |    288 |
    |  C   |       The Ugly        |    120 |
    |  D   |      The Gopher       |    800 |
    +------+-----------------------+--------+
    Movie ratings.
    
    opened by hasit 10
  • Fix unicode string width count

    Fix unicode string width count

    Unfortunately #18 did not fix the issue completely.

    Before:

    After:

    More here.

    Again thanks to @mattn

    opened by crackcomm 10
  • feature request: []string to []interface{}

    feature request: []string to []interface{}

    Append([]string) -> Append([]interface{}) This allows much more fluid table writes.

    Given:

    foo := struct{
        Foo   string
        Fizz   int
        Buzz float32
    }{
       Foo: "bar",
       Fizz: 123,
       Buzz: 3.14,
    }
    tw := tablewriter.NewWriter(os.Stdout)
    tw.SetHeader([]string{"foo", "fizz", "buzz"})
    

    this allows for

    tw.Append([]interface{}{
      foo.Foo,
      foo.Fizz,
      foo.Buzz,
    })
    

    rather than

    tw.Append([]string{}{
      foo.Foo,
      strconv.Itoa(foo.Fizz),
      strconv.FormatFloat(foo.Buzz, 'f', 2, 64),
    })
    

    This can be achieved easily by leveraging fmt.Sprint. This will cause an API break, however. All code utilizing tablewriter would require Append([]string{}) to be converted to Append([]interface{}{}).

    I'll begin a branch with this change. If you do not want to break API, then I can a new method call AppendInterface or something of that nature.

    opened by kylewolfe 9
  • ANSI colours

    ANSI colours

    Using ANSI colour codes in the header strings appears to mess up, i assume, the width calculations. Colour codes in the border strings and row columns appears to be fine.

    opened by endofunky 8
  •  Add poweron architecture ppc64le to travis build

    Add poweron architecture ppc64le to travis build

    This is part of the Ubuntu distribution for ppc64le. This helps us simplify testing later when distributions are re-building and re-releasing,For more info tag @gerrith3.

    opened by asellappen 8
  • Detect with a large number of words are in a cell, fallback to faster wrapping algorithm

    Detect with a large number of words are in a cell, fallback to faster wrapping algorithm

    We've been happily using github.com/olekukonko/tablewriter for some time to display tables of results from arbitrary database queries.

    We recently noticed that our server process was crashing due to out of memory errors even when the data returned from the database was tiny.

    We eventually tracked it down to the implementation of WrapWords() which does some N^2 memory allocation and runtime performance.

    We've written this small patch to fallback to a more performant word wrapping library call when the number of words to be wrapped exceeds an arbitrary threshold.

    This includes a test (which you should run with and without the patch to judge the impact).

    Ironically the library that it falls back to has a single issue open to Implement raggedness-aware algorithm so perhaps there's a good opportunity to collaborate there?

    opened by aeijdenberg 7
  • add custom per column align

    add custom per column align

    adds SetColumnAlignment to Table interface solves #43

    opened by pkit 7
  • Fix bug: not auto-merged if the number of lines in other columns is different

    Fix bug: not auto-merged if the number of lines in other columns is different

    Sample code:

    package main
    import (
    	"os"
    
    	"github.com/olekukonko/tablewriter"
    )
    
    func main() {
    	data := [][]string{
    		[]string{"A", "The Good", "500"},
    		[]string{"A", "The Very very very very very Bad Man", "288"},
    		[]string{"C", "The Ugly", "120"},
    		[]string{"D", "The Gopher", "800"},
    	}
    
    	table := tablewriter.NewWriter(os.Stdout)
    	table.SetHeader([]string{"Name", "Sign", "Rating"})
    	table.SetAutoMergeCells(true)
    	table.SetRowLine(true)
    
    	for _, v := range data {
    		table.Append(v)
    	}
    	table.Render()
    }
    

    Expected

    +------+--------------------------------+--------+
    | NAME |              SIGN              | RATING |
    +------+--------------------------------+--------+
    | A    | The Good                       |    500 |
    +      +--------------------------------+--------+
    |      | The Very very very very very   |    288 |
    |      | Bad Man                        |        |
    +------+--------------------------------+--------+
    | C    | The Ugly                       |    120 |
    +------+--------------------------------+--------+
    | D    | The Gopher                     |    800 |
    +------+--------------------------------+--------+
    

    Actual

    +------+--------------------------------+--------+
    | NAME |              SIGN              | RATING |
    +------+--------------------------------+--------+
    | A    | The Good                       |    500 |
    +------+--------------------------------+--------+
    | A    | The Very very very very very   |    288 |
    |      | Bad Man                        |        |
    +------+--------------------------------+--------+
    | C    | The Ugly                       |    120 |
    +------+--------------------------------+--------+
    | D    | The Gopher                     |    800 |
    +------+--------------------------------+--------+
    

    The reason for this bug is that the number of lines in the SIGN column is different. 1st line: 1 line

    The Good 
    

    2nd line: 2 lines

    The Very very very very very
    Bad Man
    

    Of course, if the number of lines is the same, it works.

    +------+----------------------------+--------+
    | NAME |            SIGN            | RATING |
    +------+----------------------------+--------+
    | A    | The Good                   |    500 |
    +      +----------------------------+--------+
    |      | The Very very very Bad Man |    288 |
    +------+----------------------------+--------+
    | C    | The Ugly                   |    120 |
    +------+----------------------------+--------+
    | D    | The Gopher                 |    800 |
    +------+----------------------------+--------+
    
    opened by knqyf263 7
  • Add Color For Individual Cells

    Add Color For Individual Cells

    @knz @mattn @hasit

    What

    This adds a new ability SetCellColor to set the Cell Colors individually, while combined with/or without Column Colors. Cell Colors with take PRIORITY over Column Colors (otherwise it wouldn't really do anything 😸 )

    Why

    Currently if you set Column coloring the entire column will be color coded that way. There are times where it would be really nice if we can maintain the color for the column but allow for individual cells to also to also take a different coloring. Maybe we have a list of files in a table and we want to color code some of them based on certain status for example.

    Testing

    I've tested this a few different ways, i've also added a section to the readme to show how to use these column cells. The readme has the code for these generated tables. I also tested what happens if the values of (col,row) passed to SetCellColors are out of range, that isn't an issue because getColorForCell just returns an emtpy string that is checked for

    • NO COLUMN COLORS WITH CELL COLORS ( NOT MERGED )

    image

    • COLUMN COLORS WITH CELL PRIORITY ( NOT MERGED )

    image

    • NO COLUMN COLORS WITH CELL COLORS ( MERGED )

    image

    • COLUMN COLORS WITH CELL PRIORITY ( MERGED )

    image

    opened by Mitsuwa 7
  • fix: column misalignment when header is empty

    fix: column misalignment when header is empty

    Calculate the empty row to use for padding instead of assuming an empty rows is always length=2

    opened by cgrinds 0
  • Column separator is misaligned when header is empty

    Column separator is misaligned when header is empty

    package main
    
    import (
    	"github.com/olekukonko/tablewriter"
    	"os"
    	"strings"
    )
    
    func main() {
    	lines := []string{
    		"Lorem ipsum dolor",
    		"quis commodo odio",
    	}
    	linesWithNewline := strings.Join(lines, "\n")
    	data := [][]string{
    		{" ", "b", "c"},
    		{" ", "e", linesWithNewline},
    	}
    	table := tablewriter.NewWriter(os.Stdout)
    	table.SetHeader([]string{"", "", "col2"})
    	table.SetAlignment(tablewriter.ALIGN_LEFT)
    	table.SetBorder(false)
    	table.SetColMinWidth(2, 15)
    	table.SetAutoWrapText(false)
    	table.SetRowLine(true)
    	table.AppendBulk(data)
    	table.Render()
    }
    

    Results in

        |   |       COL2         
    ----+---+--------------------
        | b | c                  
    ----+---+--------------------
        | e | Lorem ipsum dolor  
         |    | quis commodo odio  
    ----+---+--------------------
    

    Instead of the expected

        |   |       COL2         
    ----+---+--------------------
        | b | c                  
    ----+---+--------------------
        | e | Lorem ipsum dolor  
        |   | quis commodo odio  
    ----+---+--------------------
    
    opened by cgrinds 1
  • Can you support line merging

    Can you support line merging

    +---------+---------+ | PATH | MD5 | +---------+---------+ | -empty- | +---------+---------+

    opened by gy19961025 0
  • Fix one of the examples

    Fix one of the examples

    opened by Clivern 0
  • Add support for markdown column alignment

    Add support for markdown column alignment

    resolves #173

    This adds support for column alignment in markdown tables so that the rendered markdown table will have the same column alignment as the text version.

    An example from a test:

    |   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 |
    

    renders as:

    | 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 |

    opened by WillAbides 1
  • Render to image (png/jpg)

    Render to image (png/jpg)

    Is it possible to render the table to an image png/jpg ?

    opened by sachinbhutani 0
  • (fix) ALIGN_LEFT should have tablewriter to reference the library

    (fix) ALIGN_LEFT should have tablewriter to reference the library

    Small fix fir the README.md Hope this might be helpful.

    Signed-off-by: Rahul M Chheda [email protected]

    opened by rahulchheda 1
  • fixed col size calculation problem

    fixed col size calculation problem

    problem: image

    fixed,normal: image

    opened by wentaojin 0
  • Column separator is not aligned

    Column separator is not aligned

    package main
    
    import (
    	"os"
    
    	"github.com/olekukonko/tablewriter"
    )
    
    func main() {
    	data := [][]string{
    		{"trace", "14:25:54.123022", "192.219µs"},
    		{"  └─traceRun", "14:25:54.123035", "175.245µs"},
    		{"    ├─traceRunChild1", "14:25:54.123036", "2.075µs"},
    		{"    └─traceRunChild2", "14:25:54.123204", "784ns"},
    	}
    	table := tablewriter.NewWriter(os.Stdout)
    	table.SetHeader([]string{"operation", "startTS", "duration"})
    	table.SetAlignment(tablewriter.ALIGN_LEFT)
    	table.AppendBulk(data)
    	table.Render() // Send output
    }
    

    will got

    +------------------------+-----------------+-----------+
    |       OPERATION        |     STARTTS     | DURATION  |
    +------------------------+-----------------+-----------+
    | trace                  | 14:25:54.123022 | 192.219µs |
    |   └─traceRun         | 14:25:54.123035 | 175.245µs |
    |     ├─traceRunChild1 | 14:25:54.123036 | 2.075µs   |
    |     └─traceRunChild2 | 14:25:54.123204 | 784ns     |
    +------------------------+-----------------+-----------+
    

    which is not aligned.

    opened by choleraehyq 3
Owner
Oleku Konko
Oleku Konko
A command-line tool and library for generating regular expressions from user-provided test cases

Table of Contents What does this tool do? Do I still need to learn to write regexes then? Current features How to install? 4.1 The command-line tool 4

Peter M. Stahl 4.2k Jul 23, 2021
Utilities to prettify console output of tables, lists, progress-bars, text, etc.

go-pretty Utilities to prettify console output of tables, lists, progress-bars, text, etc. Table Pretty-print tables into ASCII/Unicode strings.

Naveen Mahalingam 899 Jul 21, 2021
Sloc, Cloc and Code: scc is a very fast accurate code counter with complexity calculations and COCOMO estimates written in pure Go

Sloc Cloc and Code (scc) A tool similar to cloc, sloccount and tokei. For counting physical the lines of code, blank lines, comment lines, and physica

Ben Boyter 2.6k Jul 20, 2021
weather app for the terminal

wego is a weather client for the terminal. Features show forecast for 1 to 7 days nice ASCII art icons displayed info (metric or imperial units): temp

null 6.8k Jul 16, 2021
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Rohit Gupta 1.7k Jul 21, 2021
Advanced ANSI style & color support for your terminal applications

termenv lets you safely use advanced styling options on the terminal. It gathers information about the terminal environment in terms of its ANSI & col

Christian Muehlhaeuser 718 Jul 20, 2021
Another CLI framework for Go. It works on my machine.

Command line interface framework Go framework for rapid command line application development

Ulrich Kautz 108 May 24, 2021
Draw images in your ANSI terminal with true color

___ _____ ____ / _ \/ _/ |/_/ /____ ______ _ Made with love by Eliuk Blau / ___// /_> </ __/ -_) __/ ' \ https://github.com/eliukblau/pix

Eliuk Blau 816 Jul 20, 2021
Command Line Interface for Terraform Enterprise/Cloud ( tecli )

In a world where everything is Terraform, teams use Terraform Cloud API to manage their workloads. TECLI increases teams productivity by facilitating such interaction and by providing easy commands that can be executed on a terminal or on CI/CD systems.

Amazon Web Services - Labs 187 Jul 20, 2021
Simple time tracking CLI

⏰ timetrace timetrace is a simple CLI for tracking your working time. Installation Homebrew brew tap dominikbraun/timetrace brew install timetrace Do

Dominik Braun 426 Jul 24, 2021
Simplistic interactive filtering tool

peco Simplistic interactive filtering tool NOTE: If you are viewing this on GitHub, this document refers to the state of peco in whatever current bran

null 6.5k Jul 27, 2021
🔥 [WIP] Interactive Jira Command Line

JiraCLI Interactive Jira CLI ?? This project is still a work in progress ?? This tool mostly focuses on issue search and navigation at the moment. How

Ankit Pokhrel 105 Jul 18, 2021
Fully featured Go (golang) command line option parser with built-in auto-completion support.

go-getoptions Go option parser inspired on the flexibility of Perl’s GetOpt::Long. Table of Contents Quick overview Examples Simple script Program wit

David Gamba 36 Jul 6, 2021
Make Highly Customized Boxes for your CLI

Box CLI Maker ?? Box CLI Maker is a Highly Customized Terminal Box Creator. Features Make Terminal Box in 8️⃣ inbuilt different styles 16 Inbuilt Colo

Swastik Baranwal 138 Jul 18, 2021