olekukonko / tablewriter

ASCII table in golang
MIT License
4.31k stars 368 forks source link

README documenting missing features #77

Open neilmcgibbon opened 7 years ago

neilmcgibbon commented 7 years ago

The README has an example for table colour formatting, where it includes the following snippet as a code example:


/// ... excerpt only, for brevity
table.SetHeaderAttributes(tablewriter.Add(tablewriter.Bold, tablewriter.BgGreenColor),
              tablewriter.Add(tablewriter.FgHiRedColor, tablewriter.Bold, tablewriter.BgBlackColor),
              tablewriter.Add(tablewriter.BgRedColor, tablewriter.FgWhiteColor),
              tablewriter.Add(tablewriter.BgCyanColor, tablewriter.FgWhiteColor))

table.SetColumnAttributes(tablewriter.Add(tablewriter.Bold, tablewriter.FgHiBlackColor),
              tablewriter.Add(tablewriter.Bold, tablewriter.FgHiRedColor),
              tablewriter.Add(tablewriter.Bold, tablewriter.FgHiBlackColor),
              tablewriter.Add(tablewriter.Bold, tablewriter.FgBlackColor))

However when using the code my IDE warns me that SetColumnAttributes does not exist, and indeed I can't see it in the source code. Is this an upcoming feature that is not yet available?

ansrivas commented 7 years ago

Stumbled upon this issue as well. Apparently during the merge request the APIs were renamed. I have sent a pull request to fix this. You can use it this way:

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