Skip to content

Instantly share code, notes, and snippets.

@mattn
Created June 15, 2017 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/529f93ee4cf868712287b37d5ff3bf42 to your computer and use it in GitHub Desktop.
Save mattn/529f93ee4cf868712287b37d5ff3bf42 to your computer and use it in GitHub Desktop.
diff --git a/table.go b/table.go
index 3314bfb..d983d96 100644
--- a/table.go
+++ b/table.go
@@ -72,6 +72,7 @@ type Table struct {
hdrLine bool
borders Border
colSize int
+ space bool
}
// Start New Table
@@ -100,7 +101,8 @@ func NewWriter(writer io.Writer) *Table {
rowLine: false,
hdrLine: true,
borders: Border{Left: true, Right: true, Bottom: true, Top: true},
- colSize: -1}
+ colSize: -1,
+ space: true}
return t
}
@@ -327,7 +329,12 @@ func (t Table) printHeading() {
h = Title(h)
}
pad := ConditionString((i == end && !t.borders.Left), SPACE, t.pColumn)
- fmt.Fprintf(t.out, " %s %s",
+ if t.space {
+ fmt.Fprint(t.out, " ")
+ } else {
+ pad = ""
+ }
+ fmt.Fprintf(t.out, "%s %s",
padFunc(h, SPACE, v),
pad)
}
@@ -371,7 +378,12 @@ func (t Table) printFooter() {
if len(t.footers[i]) == 0 {
pad = SPACE
}
- fmt.Fprintf(t.out, " %s %s",
+ if t.space {
+ fmt.Fprint(t.out, " ")
+ } else {
+ pad = ""
+ }
+ fmt.Fprintf(t.out, "%s %s",
padFunc(f, SPACE, v),
pad)
}
@@ -473,7 +485,9 @@ func (t Table) printRow(columns [][]string, colKey int) {
// Check if border is set
fmt.Fprint(t.out, ConditionString((!t.borders.Left && y == 0), SPACE, t.pColumn))
- fmt.Fprintf(t.out, SPACE)
+ if t.space {
+ fmt.Fprint(t.out, SPACE)
+ }
str := columns[y][x]
// This would print alignment
@@ -561,7 +575,9 @@ func (t Table) printRowMergeCells(writer io.Writer, columns [][]string, colKey i
// Check if border is set
fmt.Fprint(writer, ConditionString((!t.borders.Left && y == 0), SPACE, t.pColumn))
- fmt.Fprintf(writer, SPACE)
+ if t.space {
+ fmt.Fprint(writer, SPACE)
+ }
str := columns[y][x]
@@ -660,3 +676,8 @@ func (t *Table) parseDimension(str string, colKey, rowKey int) []string {
//fmt.Printf("Raw %+v %d\n", raw, len(raw))
return raw
}
+
+// Set table space between border
+func (t *Table) SetSpace(space bool) {
+ t.space = space
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment