Revert "Minor Fixes & Make Linter Happy"
diff --git a/.gitignore b/.gitignore
index f5003ca..b66cec6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,7 +13,3 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
-
-# folders
-.idea
-.vscode
diff --git a/README.md b/README.md
index aa8ef05..46fa458 100644
--- a/README.md
+++ b/README.md
@@ -69,7 +69,7 @@
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Date", "Description", "CV2", "Amount"})
table.SetFooter([]string{"", "", "Total", "$146.93"}) // Add Footer
-table.EnableBorder(false) // Set Border to false
+table.SetBorder(false) // Set Border to false
table.AppendBulk(data) // Add Bulk Data
table.Render()
```
@@ -245,7 +245,7 @@
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Date", "Description", "CV2", "Amount"})
table.SetFooter([]string{"", "", "Total", "$146.93"}) // Add Footer
-table.EnableBorder(false) // Set Border to false
+table.SetBorder(false) // Set Border to false
table.SetHeaderColor(tablewriter.Colors{tablewriter.Bold, tablewriter.BgGreenColor},
tablewriter.Colors{tablewriter.FgHiRedColor, tablewriter.Bold, tablewriter.BgBlackColor},
@@ -289,7 +289,7 @@
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Col1", "Col2", "Col3", "Col4"})
table.SetFooter([]string{"", "", "Footer3", "Footer4"})
-table.EnableBorder(false)
+table.SetBorder(false)
table.SetHeaderColor(tablewriter.Colors{tablewriter.Bold, tablewriter.BgGreenColor},
tablewriter.Colors{tablewriter.FgHiRedColor, tablewriter.Bold, tablewriter.BgBlackColor},
@@ -371,13 +371,13 @@
table.SetHeader([]string{"Name", "Status", "Role", "Version"})
table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(true)
-table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
-table.SetAlignment(tablewriter.ALIGN_LEFT)
+table.SetHeaderAlignment(ALIGN_LEFT)
+table.SetAlignment(ALIGN_LEFT)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
-table.EnableBorder(false)
+table.SetBorder(false)
table.SetTablePadding("\t") // pad with tabs
table.SetNoWhiteSpace(true)
table.AppendBulk(data) // Add Bulk Data
diff --git a/csv.go b/csv.go
index 78052e0..9887830 100644
--- a/csv.go
+++ b/csv.go
@@ -13,7 +13,7 @@
"os"
)
-// NewCSV Start A new table by importing from a CSV file
+// Start A new table by importing from a CSV file
// Takes io.Writer and csv File name
func NewCSV(writer io.Writer, fileName string, hasHeader bool) (*Table, error) {
file, err := os.Open(fileName)
@@ -26,7 +26,7 @@
return t, err
}
-// NewCSVReader Start a New Table Writer with csv.Reader
+// Start a New Table Writer with csv.Reader
// This enables customisation such as reader.Comma = ';'
// See http://golang.org/src/pkg/encoding/csv/reader.go?s=3213:3671#L94
func NewCSVReader(writer io.Writer, csvReader *csv.Reader, hasHeader bool) (*Table, error) {
diff --git a/csv2table/csv2table.go b/csv2table/csv2table.go
index eed52d7..05c0b09 100644
--- a/csv2table/csv2table.go
+++ b/csv2table/csv2table.go
@@ -20,7 +20,6 @@
border = flag.Bool("b", true, "Enable / disable table border")
)
-// main go function
func main() {
flag.Parse()
fmt.Println()
@@ -38,7 +37,6 @@
fmt.Println()
}
-// check if argument exists
func hasArg(name string) bool {
for _, v := range os.Args {
if name == v {
@@ -47,8 +45,6 @@
}
return false
}
-
-// simple file processing
func processFile() {
r, err := os.Open(*fileName)
if err != nil {
@@ -57,8 +53,6 @@
defer r.Close()
process(r)
}
-
-// process file
func process(r io.Reader) {
csvReader := csv.NewReader(r)
rune, size := utf8.DecodeRuneInString(*delimiter)
@@ -85,7 +79,6 @@
table.Render()
}
-// exit
func exit(err error) {
fmt.Fprintf(os.Stderr, "#Error : %s", err)
os.Exit(1)
diff --git a/table.go b/table.go
index bc5567f..0d50876 100644
--- a/table.go
+++ b/table.go
@@ -5,7 +5,7 @@
// This module is a Table Writer API for the Go Programming Language.
// The protocols were written in pure Go and works on windows and unix systems
-// Package tablewriter Create & Generate text based table
+// Create & Generate text based table
package tablewriter
import (
@@ -106,7 +106,7 @@
columnsAlign []int
}
-// NewWriter Start New Table
+// Start New Table
// Take io.Writer Directly
func NewWriter(writer io.Writer) *Table {
t := &Table{
@@ -170,7 +170,7 @@
footerRowIdx = -2
)
-// SetHeader Set table header
+// Set table header
func (t *Table) SetHeader(keys []string) {
t.colSize = len(keys)
for i, v := range keys {
@@ -179,7 +179,7 @@
}
}
-// SetFooter Set table Footer
+// Set table Footer
func (t *Table) SetFooter(keys []string) {
//t.colSize = len(keys)
for i, v := range keys {
@@ -188,7 +188,7 @@
}
}
-// SetCaption Set table Caption
+// Set table Caption
func (t *Table) SetCaption(caption bool, captionText ...string) {
t.caption = caption
if len(captionText) == 1 {
@@ -196,75 +196,74 @@
}
}
-// SetAutoFormatHeaders Turn header autoformatting on/off. Default is on (true).
+// Turn header autoformatting on/off. Default is on (true).
func (t *Table) SetAutoFormatHeaders(auto bool) {
t.autoFmt = auto
}
-// SetAutoWrapText Turn automatic multiline text adjustment on/off. Default is on (true).
+// Turn automatic multiline text adjustment on/off. Default is on (true).
func (t *Table) SetAutoWrapText(auto bool) {
t.autoWrap = auto
}
-// SetReflowDuringAutoWrap Turn automatic reflowing of multiline text when rewrapping. Default is on (true).
+// Turn automatic reflowing of multiline text when rewrapping. Default is on (true).
func (t *Table) SetReflowDuringAutoWrap(auto bool) {
t.reflowText = auto
}
-// SetColWidth Set the Default column width
+// Set the Default column width
func (t *Table) SetColWidth(width int) {
t.mW = width
}
-// SetColMinWidth Set the minimal width for a column
+// Set the minimal width for a column
func (t *Table) SetColMinWidth(column int, width int) {
t.cs[column] = width
}
-// SetColumnSeparator Set the Column Separator
+// Set the Column Separator
func (t *Table) SetColumnSeparator(sep string) {
t.pColumn = sep
t.syms = simpleSyms(t.pCenter, t.pRow, t.pColumn)
}
-// SetRowSeparator Set the Row Separator
+// Set the Row Separator
func (t *Table) SetRowSeparator(sep string) {
t.pRow = sep
t.syms = simpleSyms(t.pCenter, t.pRow, t.pColumn)
}
-// SetCenterSeparator Set the center Separator
+// Set the center Separator
func (t *Table) SetCenterSeparator(sep string) {
t.pCenter = sep
t.syms = simpleSyms(t.pCenter, t.pRow, t.pColumn)
}
-// SetHeaderAlignment Set Header Alignment
+// Set Header Alignment
func (t *Table) SetHeaderAlignment(hAlign int) {
t.hAlign = hAlign
}
-// SetFooterAlignment Set Footer Alignment
+// Set Footer Alignment
func (t *Table) SetFooterAlignment(fAlign int) {
t.fAlign = fAlign
}
-// SetAlignment Set Table Alignment
+// Set Table Alignment
func (t *Table) SetAlignment(align int) {
t.align = align
}
-// SetNoWhiteSpace Set No White Space
+// Set No White Space
func (t *Table) SetNoWhiteSpace(allow bool) {
t.noWhiteSpace = allow
}
-// SetTablePadding Set Table Padding
+// Set Table Padding
func (t *Table) SetTablePadding(padding string) {
t.tablePadding = padding
}
-// SetColumnAlignment Set Column Alignment
func (t *Table) SetColumnAlignment(keys []int) {
for _, v := range keys {
switch v {
@@ -281,34 +280,35 @@
}
}
-// SetNewLine Set New Line
+// Set New Line
func (t *Table) SetNewLine(nl string) {
t.newLine = nl
}
-// SetHeaderLine Set Header Line
+// Set Header Line
// This would enable / disable a line after the header
func (t *Table) SetHeaderLine(line bool) {
t.hdrLine = line
}
-// SetRowLine Set Row Line
+// Set Row Line
// This would enable / disable a line on each row of the table
func (t *Table) SetRowLine(line bool) {
t.rowLine = line
}
-// SetAutoMergeCells Set Auto Merge Cells
+// Set Auto Merge Cells
// This would enable / disable the merge of cells with identical values
func (t *Table) SetAutoMergeCells(auto bool) {
t.autoMergeCells = auto
}
-// SetAutoMergeCellsByColumnIndex Set Auto Merge Cells By Column Index
+// Set Auto Merge Cells By Column Index
// This would enable / disable the merge of cells with identical values for specific columns
// If cols is empty, it is the same as `SetAutoMergeCells(true)`.
func (t *Table) SetAutoMergeCellsByColumnIndex(cols []int) {
t.autoMergeCells = true
+
if len(cols) > 0 {
m := make(map[int]bool)
for _, col := range cols {
@@ -318,20 +318,12 @@
}
}
-// SetBorder Set Table Border
+// Set Table Border
// This would enable / disable line around the table
-// Deprecated: use EnableBorder
func (t *Table) SetBorder(border bool) {
- t.EnableBorder(border)
-}
-
-// EnableBorder Set Table Border
-// This would enable / disable line around the table
-func (t *Table) EnableBorder(border bool) {
t.SetBorders(Border{border, border, border, border})
}
-// SetBorders SetBorder Set Custom Table Border
func (t *Table) SetBorders(border Border) {
t.borders = border
}
@@ -447,7 +439,7 @@
t.lines = append(t.lines, line)
}
-// Rich Append row to table with color attributes
+// Append row to table with color attributes
func (t *Table) Rich(row []string, colors []Colors) {
rowSize := len(t.headers)
if rowSize > t.colSize {
@@ -474,7 +466,7 @@
t.lines = append(t.lines, line)
}
-// AppendBulk Allow Support for Bulk Append
+// Allow Support for Bulk Append
// Eliminates repeated for loops
func (t *Table) AppendBulk(rows [][]string) {
for _, row := range rows {
@@ -487,12 +479,12 @@
return len(t.lines)
}
-// ClearRows Clear rows
+// Clear rows
func (t *Table) ClearRows() {
t.lines = [][][]string{}
}
-// ClearFooter Clear footer
+// Clear footer
func (t *Table) ClearFooter() {
t.footers = [][]string{}
}
@@ -808,7 +800,7 @@
}
// Print caption text
-func (t *Table) printCaption() {
+func (t Table) printCaption() {
width := t.getTableWidth()
paragraph, _ := WrapString(t.captionText, width)
for linecount := 0; linecount < len(paragraph); linecount++ {
@@ -817,7 +809,7 @@
}
// Calculate the total number of characters in a row
-func (t *Table) getTableWidth() int {
+func (t Table) getTableWidth() int {
var chars int
for _, v := range t.cs {
chars += v
@@ -831,14 +823,12 @@
return (chars + (3 * t.colSize) + 2)
}
-// printRows - print all the rows
-func (t *Table) printRows() {
+func (t Table) printRows() {
for i, lines := range t.lines {
t.printRow(lines, i)
}
}
-// fillAlignment - fill the alignment
func (t *Table) fillAlignment(num int) {
if len(t.columnsAlign) < num {
t.columnsAlign = make([]int, num)
@@ -850,6 +840,7 @@
// Print Row Information
// Adjust column alignment based on type
+
func (t *Table) printRow(columns [][]string, rowIdx int) {
// Get Maximum Height
max := t.rs[rowIdx]
@@ -964,6 +955,7 @@
// Print Row Information to a writer and merge identical cells.
// Adjust column alignment based on type
+
func (t *Table) printRowMergeCells(writer io.Writer, columns [][]string, rowIdx int, previousLine []string) ([]string, []bool) {
// Get Maximum Height
max := t.rs[rowIdx]
@@ -973,9 +965,9 @@
pads := []int{}
// Checking for ANSI escape sequences for columns
- isEscSeq := false
+ is_esc_seq := false
if len(t.columnsParams) > 0 {
- isEscSeq = true
+ is_esc_seq = true
}
for i, line := range columns {
length := len(line)
@@ -999,7 +991,7 @@
str := columns[y][x]
// Embedding escape sequence with column value
- if isEscSeq {
+ if is_esc_seq {
str = format(str, t.columnsParams[y])
}
@@ -1059,7 +1051,6 @@
return previousLine, displayCellBorder
}
-// parseDimension - parse table dimensions
func (t *Table) parseDimension(str string, colKey, rowKey int) []string {
var (
raw []string
diff --git a/table_test.go b/table_test.go
index ec3af2a..9bb188e 100644
--- a/table_test.go
+++ b/table_test.go
@@ -98,7 +98,7 @@
// *============*===========*=========*
}
-func ExampleTable_SetUnicodeHV() {
+func ExampleUnicode() {
data := [][]string{
{"Regular", "regular line", "1"},
{"Thick", "particularly thick line", "2"},
@@ -161,7 +161,7 @@
table.SetHeader([]string{"Constant", "Meaning", "Seq"})
table.SetFooter([]string{"Constant", "Meaning", "Seq"})
table.SetUnicodeHV(Regular, Regular)
- table.EnableBorder(false)
+ table.SetBorder(false)
table.AppendBulk(data)
table.Render()
@@ -213,7 +213,7 @@
table := NewWriter(buf)
table.SetUnicodeHV(Regular, Regular)
- table.EnableBorder(false)
+ table.SetBorder(false)
table.AppendBulk(data)
table.Render()
@@ -254,7 +254,7 @@
return
}
table.SetAlignment(ALIGN_LEFT)
- table.EnableBorder(false)
+ table.SetBorder(false)
table.Render()
got := buf.String()
@@ -310,7 +310,7 @@
table.SetAutoWrapText(false)
table.SetHeader([]string{"Date", "Description", "CV2", "Amount"})
table.SetFooter([]string{"", "", "Total", "$145.93"}) // Add Footer
- table.EnableBorder(false) // Set Border to false
+ table.SetBorder(false) // Set Border to false
table.AppendBulk(data) // Add Bulk Data
table.Render()
@@ -347,7 +347,7 @@
table.SetAutoWrapText(false)
table.SetHeader([]string{"Date", "Description", "CV2", "Amount"})
table.SetFooter([]string{"", "", "Total", "$145.93"}) // Add Footer
- table.EnableBorder(false) // Set Border to false
+ table.SetBorder(false) // Set Border to false
table.AppendBulk(data) // Add Bulk Data
table.SetUnicodeHV(Regular, Regular)
table.Render()
@@ -629,7 +629,7 @@
table.SetHeader([]string{"Date", "Description", "CV2", "Amount"})
table.SetFooter([]string{"", "", "Total", "$146.93"}) // Add Footer
table.SetCaption(true, "This is a very long caption. The text should wrap to the width of the table.") // Add caption
- table.EnableBorder(false) // Set Border to false
+ table.SetBorder(false) // Set Border to false
table.AppendBulk(data) // Add Bulk Data
table.Render()
@@ -978,7 +978,7 @@
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
- table.EnableBorder(false)
+ table.SetBorder(false)
table.SetAlignment(ALIGN_LEFT)
table.SetHeader([]string{})
return table
@@ -1477,7 +1477,7 @@
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
- table.EnableBorder(false)
+ table.SetBorder(false)
table.SetTablePadding("\t") // pad with tabs
table.SetNoWhiteSpace(true)
table.AppendBulk(data) // Add Bulk Data
diff --git a/util.go b/util.go
index 6056bee..380e7ab 100644
--- a/util.go
+++ b/util.go
@@ -21,7 +21,7 @@
return runewidth.StringWidth(ansi.ReplaceAllLiteralString(str, ""))
}
-// ConditionString Simple Condition for string
+// Simple Condition for string
// Returns value based on condition
func ConditionString(cond bool, valid, inValid string) string {
if cond {
@@ -34,7 +34,7 @@
return ('0' <= r && r <= '9') || r == ' '
}
-// Title Format Table Header
+// Format Table Header
// Replace _ , . and spaces
func Title(name string) string {
origLen := len(name)
@@ -72,7 +72,7 @@
return s
}
-// PadRight Pad String Right position
+// Pad String Right position
// This would place string at the left side of the screen
func PadRight(s, pad string, width int) string {
gap := width - DisplayWidth(s)
@@ -82,7 +82,7 @@
return s
}
-// PadLeft Pad String Left position
+// Pad String Left position
// This would place string at the right side of the screen
func PadLeft(s, pad string, width int) string {
gap := width - DisplayWidth(s)
diff --git a/wrap.go b/wrap.go
index a5a24da..a092ee1 100644
--- a/wrap.go
+++ b/wrap.go
@@ -21,7 +21,7 @@
const defaultPenalty = 1e5
-// WrapString Wrap wraps s into a paragraph of lines of length lim, with minimal
+// Wrap wraps s into a paragraph of lines of length lim, with minimal
// raggedness.
func WrapString(s string, lim int) ([]string, int) {
words := strings.Split(strings.Replace(s, nl, sp, -1), sp)