1package theme23import "math"45// Data bars are drawn with the left eighth blocks, so a bar ends within6// a column and reads without color: the blank columns it covers are7// blocks in its color (RuleText), and text it runs under is drawn in8// reverse video in its color (BarOn).910// blocks are a column covered from the left by 0 to 8 eighths.11var blocks = [9]string{" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█"}1213// Block is the glyph of a column a bar covers n eighths of, from the14// left: a space for none, a full block for all.15func Block(n int) string { return blocks[min(max(n, 0), 8)] }1617// BarCover is how much of each of w columns a bar frac (0 to 1) of18// their width long covers, in eighths. A bar of a number above its19// shortest point is at least an eighth long, so it shows.20func BarCover(frac float64, w int) []int {21 out := make([]int, max(w, 0))22 n := int(math.Round(min(max(frac, 0), 1) * float64(8*w)))23 if n == 0 && frac > 0 {24 n = 125 }26 for i := range out {27 out[i] = min(max(n-8*i, 0), 8)28 }29 return out30}