🎨 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
pull/1994/head
Maxi_Mega 2022-08-02 14:23:14 +02:00 committed by GitHub
parent 1cca495c7b
commit 4f7816774b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -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
}

View File

@ -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 +=