Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Fix padding around app name in startup message when containing non-ascii characters #1987

Merged
merged 4 commits into from Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions app_test.go
Expand Up @@ -1401,6 +1401,16 @@ func Test_App_Master_Process_Show_Startup_MessageWithAppName(t *testing.T) {
utils.AssertEqual(t, true, strings.Contains(startupMessage, app.Config().AppName))
}

func Test_App_Master_Process_Show_Startup_MessageWithAppNameNonAscii(t *testing.T) {
efectn marked this conversation as resolved.
Show resolved Hide resolved
appName := "Serveur de vérification des données"
app := New(Config{Prefork: true, AppName: appName})
startupMessage := captureOutput(func() {
app.startupMessage(":3000", false, "")
})
fmt.Println(startupMessage)
utils.AssertEqual(t, true, strings.Contains(startupMessage, "│ Serveur de vérification des données │"))
}

func Test_App_Server(t *testing.T) {
app := New()

Expand Down
5 changes: 3 additions & 2 deletions listen.go
Expand Up @@ -208,11 +208,12 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
}

centerValue := func(s string, width int) string {
pad := strconv.Itoa((width - len(s)) / 2)
pad := strconv.Itoa((width - len([]rune(s))) / 2)
str := fmt.Sprintf("%"+pad+"s", " ")
str += fmt.Sprintf("%s%s%s", colors.Cyan, s, colors.Black)
str += fmt.Sprintf("%"+pad+"s", " ")
if len(str)-10 < width {
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
str += " "
}
return str
Expand Down