Skip to content

Commit

Permalink
Add Support for SetRowLine
Browse files Browse the repository at this point in the history
  • Loading branch information
olekukonko committed Feb 5, 2014
1 parent 3717491 commit 27d3cff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ Generate ASCII table on the fly ... Installation is simple as
- Automatic Alignment of numbers & percentage
- Write Directly to http , file etc via `io.Reader`
- Read directly from CSV file
- Optional Row line via `SetRowLine`
- Optional Row line via `SetRowLine` - `new`
- Normalise Table Header - `new`

#### TODO
- ~~Import Directly from CSV~~
- ~~Import Directly from CSV~~ - `done`
- Support custom alignment
- Support table with uneven elements
- Support pyramid structure
- ~~ISupport table with uneven rows ~~ - `done`
- General Improvement & Optimisation
- `NewHTML` Parse table from HTML

Expand Down
11 changes: 6 additions & 5 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ type table struct {
pCenter string
pRow string
pColumn string

tColumn int
tRow int
align int
rowLine bool
colSize int
}

// Start New Table
Expand All @@ -73,8 +73,8 @@ func NewWriter(writer io.Writer) *table {
tColumn: -1,
tRow: -1,
align: ALIGN_DEFAULT,
rowLine: false}

rowLine: false,
colSize: -1}
return t
}

Expand All @@ -83,7 +83,6 @@ func (t table) Render() {
t.printLine(true)
t.printHeading()
t.printRows()

if !t.rowLine {
t.printLine(true)
}
Expand All @@ -92,6 +91,8 @@ func (t table) Render() {

// Set table header
func (t *table) SetHeader(keys []string) {

t.colSize = len(keys)
for i, v := range keys {
t.parseDimension(v, i, -1)
t.headers = append(t.headers, Title(v))
Expand Down Expand Up @@ -124,13 +125,13 @@ func (t *table) SetAlignment(align int) {
}

// Set Row Line
// This would enable / disable a line on each row of the table
func (t *table) SetRowLine(line bool) {
t.rowLine = line
}

// Append row to table
func (t *table) Append(row []string) error {

h := len(t.headers)
if h > 0 && h != len(row) {
return errors.New("Heder length does not match")
Expand Down
4 changes: 2 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
"unicode/utf8"
)

// Format Table title
// Format Table Header
// Replace _ , . and spaces
func Title(name string) string {
name = strings.Replace(name, "_", " ", -1)
name = strings.Replace(name, ".", " ", -1)
name = strings.TrimSpace(name)
return strings.ToUpper(name)
}


// Pad String
// Attempts to play string in the center
func Pad(s, pad string, width int) string {
Expand Down

0 comments on commit 27d3cff

Please sign in to comment.