Skip to content

Commit

Permalink
Switch from len to utf8.RuneCountInString
Browse files Browse the repository at this point in the history
We need the literal number of spaces a command *is* taking up, as
opposed to the width of its unicode character, or the width that it
*should* take up on the screen. E.g. The smiley emoji, described by the
3 bytes [0xE2 0x98 0xBA] takes up 2 columns on the screen, but only
occupies 1 column, as seen below
 1234567
 ###☺###
  • Loading branch information
ian-howell committed Sep 28, 2019
1 parent 63df5f4 commit 0eae1f1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/models/onebuild-execution-plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"strings"
"text/tabwriter"
"unicode/utf8"

"github.com/codeskyblue/go-sh"
"github.com/gopinath-langote/1build/cmd/utils"
Expand Down Expand Up @@ -100,7 +101,9 @@ func dashesOfLength(text string) string {

// PrintBanner prints the CommandContext's name in a banner of the standard length
func (c *CommandContext) PrintBanner() {
centreLength := len(c.Name) + len(bannerOpen) + len(bannerClose)
centreLength := utf8.RuneCountInString(c.Name) +
utf8.RuneCountInString(bannerOpen) +
utf8.RuneCountInString(bannerClose)
totalDashes := utils.MaxOutputWidth - centreLength

// Intentional integer division
Expand Down

0 comments on commit 0eae1f1

Please sign in to comment.