Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func main() {
table.MaxColWidth = 80
table.Wrap = true
for _, hacker := range hackers {
table.AddRow("Name:", hacker.Name)
table.AddRow("Birthday:", hacker.Birthday)
table.AddRow("Bio:", hacker.Bio)
table.AddRow("1. Name:", hacker.Name)
table.AddRow("2. Birthday:", hacker.Birthday)
table.AddRow("3. Bio:", hacker.Bio)
table.AddRow("") // blank
}
fmt.Println(table)
Expand All @@ -44,9 +44,9 @@ func main() {
table.MaxColWidth = 80
table.Wrap = true
for _, hacker := range hackers {
table.AddRow(color.RedString("Name:"), color.WhiteString(hacker.Name))
table.AddRow(color.BlueString("Birthday:"), hacker.Birthday)
table.AddRow(color.GreenString("Bio:"), hacker.Bio)
table.AddRow(color.RedString("1. Name:"), color.WhiteString(hacker.Name))
table.AddRow(color.BlueString("2. Birthday:"), hacker.Birthday)
table.AddRow(color.GreenString("3. Bio:"), hacker.Bio)
table.AddRow("") // blank
}
fmt.Println(table)
Expand Down
7 changes: 2 additions & 5 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"
"sync"

"github.com/fatih/color"
"github.com/gosuri/uitable/util/strutil"
"github.com/gosuri/uitable/util/wordwrap"
)
Expand Down Expand Up @@ -191,11 +190,9 @@ func (c *Cell) String() string {
if c.Data == nil {
return strutil.PadLeft(" ", int(c.Width), ' ')
}
col := color.New(color.FgBlack)
col.DisableColor()
s := fmt.Sprintf("%v", col.Sprint(c.Data))
s := fmt.Sprint(c.Data)
if c.Width > 0 {
if c.Wrap && uint(len(s)) > c.Width {
if c.Wrap && uint(strutil.StringWidth(s)) > c.Width {
return wordwrap.WrapString(s, c.Width)
} else {
return strutil.Resize(s, c.Width, c.RightAlign)
Expand Down
1 change: 1 addition & 0 deletions util/wordwrap/wordwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func WrapString(s string, lim uint) string {
var wordBuf, spaceBuf bytes.Buffer
var wordWidth, spaceWidth int

lim = lim + uint(len(s)) - uint(strutil.StringWidth(s))
for _, char := range s {
if char == '\n' {
if wordBuf.Len() == 0 {
Expand Down