mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-11 03:13:46 +00:00
fix(wheelofnames): center spoiler winner between underscores instead of blank padding
This commit is contained in:
1 parent
529da3621d
commit
f727bc6b5c
2 files changed
+6
-8
No files matched your search
@@ -168,7 +168,7 @@ func TestWheelOfNames_ResultCaptionTruncatesLongResult(t *testing.T) {
|
||||
func TestWheelOfNames_ResultCaptionPadsShortWinnerToLongestOption(t *testing.T) {
|
||||
options := []string{"Bob", "Alexandria"}
|
||||
got := wheelResultCaption(options, 0)
|
||||
want := `Result: <span class="tg-spoiler">` + strings.Repeat(wheelCaptionPad, 7) + "Bob" + `</span>`
|
||||
want := `Result: <span class="tg-spoiler">___Bob____</span>`
|
||||
if got != want {
|
||||
t.Fatalf("wheelResultCaption() = %q, want %q", got, want)
|
||||
}
|
||||
|
||||
@@ -71,13 +71,9 @@ func wheelResultCaption(options []string, winner int) string {
|
||||
return `Result: <span class="tg-spoiler">` + html.EscapeString(result) + `</span>`
|
||||
}
|
||||
|
||||
// Figure space: blank, non-breaking, and as wide as a digit, so in
|
||||
// Telegram's proportional font one pad char roughly matches one letter;
|
||||
// a regular space is far narrower and the spoiler width would still hint
|
||||
// at the winner's length.
|
||||
const wheelCaptionPad = "\u2007"
|
||||
const wheelCaptionPad = "_"
|
||||
|
||||
// padWheelResultCaption prefixes shorter winners with blank padding so every
|
||||
// padWheelResultCaption centers shorter winners between underscores so every
|
||||
// option renders a spoiler of equal length; otherwise the spoiler width
|
||||
// reveals the winner. The longest option is returned unpadded.
|
||||
func padWheelResultCaption(options []string, result string) string {
|
||||
@@ -87,7 +83,9 @@ func padWheelResultCaption(options []string, result string) string {
|
||||
longest = n
|
||||
}
|
||||
}
|
||||
return strings.Repeat(wheelCaptionPad, longest-len([]rune(result))) + result
|
||||
missing := longest - len([]rune(result))
|
||||
left := missing / 2
|
||||
return strings.Repeat(wheelCaptionPad, left) + result + strings.Repeat(wheelCaptionPad, missing-left)
|
||||
}
|
||||
|
||||
func truncateWheelResultCaption(result string) string {
|
||||
|
||||
Reference in new issue
Block a user