From 4f7816774b85edf70d54e2a65c9669734a385f9f Mon Sep 17 00:00:00 2001 From: Maxi_Mega <52792549+Maxi-Mega@users.noreply.github.com> Date: Tue, 2 Aug 2022 14:23:14 +0200 Subject: [PATCH] :art: Add black colors to default overriding function (#1993) * 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 --- color.go | 4 ++++ listen.go | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/color.go b/color.go index f982b379..2dbf831a 100644 --- a/color.go +++ b/color.go @@ -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 } diff --git a/listen.go b/listen.go index 8bd6f0dd..89a6fba6 100644 --- a/listen.go +++ b/listen.go @@ -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 @@ -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 +=