Skip to content

Commit

Permalink
release: v1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Jul 26, 2020
1 parent eca6c8f commit b51eaf2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
20 changes: 10 additions & 10 deletions box.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Box struct {
BottomRight string // BottomRight corner used for Symbols
BottomLeft string // BotromLeft corner used for Symbols
Horizontal string // Symbols used for Horizontal Bars
Con Config // Config for Box struct
Con Config // Config for the Box struct
}

// Config is the configuration for the Box struct
Expand Down Expand Up @@ -57,7 +57,7 @@ func (b Box) String(title, lines string) string {
if b.Con.TitlePos == "" {
b.Con.TitlePos = "Inside"
}

// if Title is empty then TitlePos should be Inside
if title != "" {
if b.Con.TitlePos != "Inside" && strings.Contains(title, "\n") {
panic("Multilines are only supported inside only")
Expand All @@ -71,7 +71,7 @@ func (b Box) String(title, lines string) string {
return b.toString(title, lines2)
}

// toString is same as String except this is for printing Boxes
// toString is same as String except that it is used for printing Boxes
func (b Box) toString(title string, lines []string) string {
titleLen := len(strings.Split(title, n1))
sideMargin := strings.Repeat(" ", b.Con.Px)
Expand All @@ -98,7 +98,7 @@ func (b Box) toString(title string, lines []string) string {
} else if b.Con.TitlePos == "Bottom" {
BottomBar = b.BottomLeft + TitleBar + b.BottomRight
} else {
fmt.Fprintln(os.Stderr, "Invalid TitlePos provided, using default")
fmt.Fprintln(os.Stderr, color.RedString("[error]: invalid value provided for TitlePos, using default"))
}
}

Expand All @@ -115,12 +115,12 @@ func (b Box) toString(title string, lines []string) string {
TopBar = Style(TopBar)
BottomBar = Style(BottomBar)
} else {
fmt.Fprintln(os.Stderr, "Invalid Color Type provided, using default color")
fmt.Fprintln(os.Stderr, color.RedString("[error]: invalid value provided to Color, using default"))
}
}

if b.Con.TitlePos == "Inside" && runewidth.StringWidth(TopBar) != runewidth.StringWidth(BottomBar) {
panic("Cannot create a Box with different sizes of Top and Bottom Bars")
panic("cannot create a Box with different sizes of Top and Bottom Bars")
}

// create lines to print
Expand Down Expand Up @@ -156,7 +156,7 @@ func (b Box) toString(title string, lines []string) string {
if i < titleLen && title != "" {
format = centerAlign
}

// obtain color
sep := b.obtainColor()

// TODO: find a better way
Expand All @@ -179,7 +179,7 @@ func (b Box) obtainColor() string {
Style := color.New(fgColors[b.Con.Color]).SprintfFunc()
return Style(b.Vertical)
}
fmt.Fprintln(os.Stderr, "Invalid Color Type provided, using default color")
fmt.Fprintln(os.Stderr, color.RedString("[error]: invalid value provided to Color, using default"))
return b.Vertical
}

Expand All @@ -191,7 +191,7 @@ func (b Box) Print(title, lines string) {
if b.Con.TitlePos == "" {
b.Con.TitlePos = "Inside"
}

// if Title is empty then TitlePos should be Inside
if title != "" {
if b.Con.TitlePos != "Inside" && strings.Contains(title, "\n") {
panic("Multilines are only supported inside only")
Expand All @@ -213,7 +213,7 @@ func (b Box) Println(title, lines string) {
if b.Con.TitlePos == "" {
b.Con.TitlePos = "Inside"
}

// if Title is empty then TitlePos should be Inside
if title != "" {
if b.Con.TitlePos != "Inside" && strings.Contains(title, "\n") {
panic("Multilines are only supported inside only")
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.14

require (
github.com/fatih/color v1.9.0
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-colorable v0.1.7 // indirect
github.com/mattn/go-runewidth v0.0.9
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaa
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw=
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
Expand All @@ -20,3 +22,5 @@ golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 h1:YTzHMGlqJu67/uEo1lBv0n3wB
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200523222454-059865788121 h1:rITEj+UZHYC927n8GT97eC3zrpzXdb/voyeOuVKS46o=
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c h1:UIcGWL6/wpCfyGuJnRFJRurA+yj8RrW7Q6x2YMCXt6c=
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3 changes: 2 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"strings"

"github.com/fatih/color"
"github.com/mattn/go-runewidth"
)

Expand All @@ -29,7 +30,7 @@ func (b Box) findAlign() string {
} else if b.Con.ContentAlign == "Left" {
return leftAlign
} else {
fmt.Fprintln(os.Stderr, "Invalid Alignment provided, using default Alignment")
fmt.Fprintln(os.Stderr, color.RedString("[error]: invalid value provided to Alignment, using default"))
return leftAlign
}
}
Expand Down

0 comments on commit b51eaf2

Please sign in to comment.