|
@@ -1,6 +1,7 @@
|
|
|
package door
|
|
|
|
|
|
import (
|
|
|
+ "strings"
|
|
|
"unicode"
|
|
|
)
|
|
|
|
|
@@ -76,6 +77,7 @@ type Line struct {
|
|
|
DefaultColor string // Default Color to use
|
|
|
RenderF func(string) string // Render function (displays string with colors)
|
|
|
UpdateF func() string // Update function updates the text
|
|
|
+ Width int // Line length
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -88,6 +90,7 @@ func (l *Line) Update() bool {
|
|
|
return false
|
|
|
}
|
|
|
var NewText string = l.UpdateF()
|
|
|
+ l.LineLength(&NewText)
|
|
|
if NewText != l.Text {
|
|
|
l.Text = NewText
|
|
|
return true
|
|
@@ -95,6 +98,20 @@ func (l *Line) Update() bool {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
+func (l *Line) LineLength(text *string) {
|
|
|
+ var length int
|
|
|
+ if l.Width == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if Unicode {
|
|
|
+ length = len([]rune(*text))
|
|
|
+ } else {
|
|
|
+ length = len([]byte(*text))
|
|
|
+ }
|
|
|
+ *text += strings.Repeat(" ", l.Width-length)
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
Line Output - returns a string with ANSI Color codes.
|
|
|
|
|
@@ -102,6 +119,7 @@ If there is no RenderF, we use the DefaultColor. Otherwise we pass the text
|
|
|
to RenderF and return what it returns.
|
|
|
*/
|
|
|
func (l *Line) Output() string {
|
|
|
+ l.LineLength(&l.Text)
|
|
|
if l.RenderF == nil {
|
|
|
return l.DefaultColor + l.Text
|
|
|
} else {
|