From b51eaf250f99684ff922845f807735ef6f08dc65 Mon Sep 17 00:00:00 2001 From: Delta456 Date: Sun, 26 Jul 2020 12:34:16 +0530 Subject: [PATCH] release: v1.3.2 --- box.go | 20 ++++++++++---------- go.mod | 4 ++-- go.sum | 4 ++++ util.go | 3 ++- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/box.go b/box.go index ab39208..af67da4 100644 --- a/box.go +++ b/box.go @@ -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 @@ -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") @@ -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) @@ -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")) } } @@ -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 @@ -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 @@ -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 } @@ -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") @@ -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") diff --git a/go.mod b/go.mod index 5d56ee6..94bb74c 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index ab6fe99..240b0bf 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/util.go b/util.go index c979ab1..f99acf0 100644 --- a/util.go +++ b/util.go @@ -5,6 +5,7 @@ import ( "os" "strings" + "github.com/fatih/color" "github.com/mattn/go-runewidth" ) @@ -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 } }