|
@@ -5,6 +5,10 @@ import (
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
+// TODO: Break out the progress bar characters into stuctures.
|
|
|
+// Write tests to verify that CP437 matches Unicode.
|
|
|
+// See box_test. ;)
|
|
|
+
|
|
|
type BarStyle int8
|
|
|
|
|
|
const (
|
|
@@ -36,6 +40,26 @@ type BarLine struct {
|
|
|
Line
|
|
|
}
|
|
|
|
|
|
+type BarCharacters struct {
|
|
|
+ solid string
|
|
|
+ half [2]string
|
|
|
+ gradient [4]string
|
|
|
+}
|
|
|
+
|
|
|
+var BARS BarCharacters
|
|
|
+
|
|
|
+var BARS_CP437 = BarCharacters{
|
|
|
+ "\xdb",
|
|
|
+ [2]string{"\xdb", "\xdd"},
|
|
|
+ [4]string{"\xdb", "\xb0", "\xb1", "\xb2"},
|
|
|
+}
|
|
|
+
|
|
|
+var BARS_UNICODE = BarCharacters{
|
|
|
+ "\u2588",
|
|
|
+ [2]string{"\u2588", "\u258c"},
|
|
|
+ [4]string{"\u2588", "\u2591", "\u2592", "\u2593"},
|
|
|
+}
|
|
|
+
|
|
|
func (bl *BarLine) CheckRange() {
|
|
|
if len(bl.ColorRange) != 0 {
|
|
|
// Ok, there is a color range. Get checking
|
|
@@ -64,11 +88,7 @@ func (bl *BarLine) Output() string {
|
|
|
step_width = int64(100 * 100 / bl.Width)
|
|
|
var steps int = int(bl.Percent / step_width)
|
|
|
|
|
|
- if Unicode {
|
|
|
- output += strings.Repeat("\u2588", steps)
|
|
|
- } else {
|
|
|
- output += strings.Repeat("\xdb", steps)
|
|
|
- }
|
|
|
+ output += strings.Repeat(BARS.solid, steps)
|
|
|
// This will work, because we aren't trying to len(output) with unicode.
|
|
|
output += strings.Repeat(" ", int(bl.Width-steps))
|
|
|
|
|
@@ -76,17 +96,9 @@ func (bl *BarLine) Output() string {
|
|
|
step_width = int64(100 * 100 / bl.Width)
|
|
|
var steps int = int(bl.Percent * 2 / step_width)
|
|
|
|
|
|
- if Unicode {
|
|
|
- output += strings.Repeat("\u2588", steps/2)
|
|
|
- } else {
|
|
|
- output += strings.Repeat("\xdb", steps/2)
|
|
|
- }
|
|
|
+ output += strings.Repeat(BARS.half[0], steps/2)
|
|
|
if steps%2 == 1 {
|
|
|
- if Unicode {
|
|
|
- output += "\u258c"
|
|
|
- } else {
|
|
|
- output += "\xdd"
|
|
|
- }
|
|
|
+ output += BARS.half[1]
|
|
|
steps++
|
|
|
}
|
|
|
output += strings.Repeat(" ", bl.Width-(steps/2))
|
|
@@ -94,31 +106,12 @@ func (bl *BarLine) Output() string {
|
|
|
case GRADIENT:
|
|
|
step_width = int64(100 * 100 / bl.Width)
|
|
|
var steps int = int(bl.Percent * 4 / step_width)
|
|
|
- if Unicode {
|
|
|
- output += strings.Repeat("\u2588", steps/4)
|
|
|
- } else {
|
|
|
- output += strings.Repeat("\xdb", steps/4)
|
|
|
- }
|
|
|
+
|
|
|
+ output += strings.Repeat(BARS.gradient[0], steps/4)
|
|
|
if steps%4 != 0 {
|
|
|
switch steps % 4 {
|
|
|
- case 1:
|
|
|
- if Unicode {
|
|
|
- output += "\u2591"
|
|
|
- } else {
|
|
|
- output += "\xb0"
|
|
|
- }
|
|
|
- case 2:
|
|
|
- if Unicode {
|
|
|
- output += "\u2592"
|
|
|
- } else {
|
|
|
- output += "\xb1"
|
|
|
- }
|
|
|
- case 3:
|
|
|
- if Unicode {
|
|
|
- output += "\u2593"
|
|
|
- } else {
|
|
|
- output += "\xb2"
|
|
|
- }
|
|
|
+ case 1, 2, 3:
|
|
|
+ output += BARS.gradient[steps%4]
|
|
|
}
|
|
|
for steps%4 != 0 {
|
|
|
steps++
|