draw poll meter with no colour when required
This commit is contained in:
parent
04ebc4e5bd
commit
a5e1c4ac79
1 changed files with 19 additions and 10 deletions
|
@ -80,7 +80,7 @@ func displayPollContent(writer io.StringWriter, poll Poll, noColor bool, indent
|
|||
}
|
||||
|
||||
writer.WriteString("\n\n" + indent + "[" + strconv.Itoa(ind) + "] " + option.Title)
|
||||
drawPollMeter(writer, calculate, 80, indent)
|
||||
drawPollMeter(writer, noColor, calculate, 80, indent)
|
||||
|
||||
writer.WriteString(
|
||||
"\n" + indent + strconv.Itoa(option.VotesCount) + " votes " +
|
||||
|
@ -96,15 +96,24 @@ func displayPollContent(writer io.StringWriter, poll Poll, noColor bool, indent
|
|||
)
|
||||
}
|
||||
|
||||
func drawPollMeter(writer io.StringWriter, calculated float64, limit int, indent string) {
|
||||
colouredBlocks := int(math.Floor(float64(limit) * calculated))
|
||||
backgroundBlocks := limit - colouredBlocks
|
||||
func drawPollMeter(writer io.StringWriter, noColor bool, calculated float64, limit int, indent string) {
|
||||
numVoteBlocks := int(math.Floor(float64(limit) * calculated))
|
||||
numBackgroundBlocks := limit - numVoteBlocks
|
||||
blockChar := "\u2501"
|
||||
voteBlockColor := "\033[32;1m"
|
||||
backgroundBlockColor := "\033[90m"
|
||||
|
||||
writer.WriteString(
|
||||
"\n" +
|
||||
indent +
|
||||
"\033[32m" + strings.Repeat(blockChar, colouredBlocks) + "\033[0m" +
|
||||
strings.Repeat(blockChar, backgroundBlocks),
|
||||
)
|
||||
if noColor {
|
||||
voteBlockColor = "\033[0m"
|
||||
|
||||
if numVoteBlocks == 0 {
|
||||
numVoteBlocks = 1
|
||||
}
|
||||
}
|
||||
|
||||
writer.WriteString("\n" + indent + voteBlockColor + strings.Repeat(blockChar, numVoteBlocks) + "\033[0m")
|
||||
|
||||
if !noColor {
|
||||
writer.WriteString(backgroundBlockColor + strings.Repeat(blockChar, numBackgroundBlocks) + "\033[0m")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue