Skip to content

Commit

Permalink
Fix status length calc bug with new status emojis
Browse files Browse the repository at this point in the history
Emojis messed up the string length calculation resulting in truncation of status line way shorter than the terminal width.

commit-id:24456c06
  • Loading branch information
ejoffe authored and Eitan Joffe committed Feb 23, 2022
1 parent ee95de7 commit afc9dc7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions github/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ const (
func statusBitIcons(config *config.Config) map[string]string {
if config.User.StatusBitsEmojis {
return map[string]string{
"checkmark": colorGreen + emojiCheckmark + colorReset,
"crossmark": colorRed + emojiCrossmark + colorReset,
"pending": colorBlue + emojiPending + colorReset,
"checkmark": emojiCheckmark,
"crossmark": emojiCrossmark,
"pending": emojiPending,
"questionmark": emojiQuestionmark,
"empty": emojiEmpty,
}
Expand Down Expand Up @@ -217,11 +217,14 @@ func (pr *PullRequest) String(config *config.Config) string {
if err != nil {
terminalWidth = 1000
}
lineByteLength := len(line)
lineLength := utf8.RuneCountInString(line)
if config.User.StatusBitsEmojis {
// each emoji consumes 2 chars in the terminal
lineLength += 4
}
diff := lineLength - terminalWidth
if diff > 0 {
line = line[:lineByteLength-diff-3] + "..."
line = line[:terminalWidth-3] + "..."
}

return line
Expand Down

0 comments on commit afc9dc7

Please sign in to comment.