Skip to content

Commit

Permalink
🎨 Add black colors to default overriding function (gofiber#1993)
Browse files Browse the repository at this point in the history
* Fix padding around app name in startup message when it contains non-ascii characters

* fix conflict, allow ending space only for odd length strings

* move startup message tests to listen_test.go

* add black color to defaultColors overriding function, fix (again) padding in startupMessage
  • Loading branch information
Maxi-Mega authored and trim21 committed Aug 15, 2022
1 parent edad6df commit 9ba6d88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ var DefaultColors = Colors{

// defaultColors is a function to override default colors to config
func defaultColors(colors Colors) Colors {
if colors.Black == "" {
colors.Black = DefaultColors.Black
}

if colors.Red == "" {
colors.Red = DefaultColors.Red
}
Expand Down
6 changes: 3 additions & 3 deletions listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
str := fmt.Sprintf("%"+pad+"s", " ")
str += fmt.Sprintf("%s%s%s", colors.Cyan, s, colors.Black)
str += fmt.Sprintf("%"+pad+"s", " ")
if len([]rune(str))-10 < width && len([]rune(str))%2 != 0 {
// add an ending space if the length of str is odd and str is not too long
if len([]rune(s))-10 < width && len([]rune(s))%2 == 0 {
// add an ending space if the length of str is even and str is not too long
str += " "
}
return str
Expand Down Expand Up @@ -256,7 +256,7 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
if app.config.AppName != "" {
mainLogo += " │ " + centerValue(app.config.AppName, 49) + " │\n"
}
mainLogo += " │ " + centerValue(" Fiber v"+Version, 49) + " │\n"
mainLogo += " │ " + centerValue("Fiber v"+Version, 49) + " │\n"

if host == "0.0.0.0" {
mainLogo +=
Expand Down

0 comments on commit 9ba6d88

Please sign in to comment.