|
@@ -11,68 +11,72 @@ door.Line - Display a line of text
|
|
|
|
|
|
Example:
|
|
Example:
|
|
|
|
|
|
- var basicLine door.Line = {Text: "Welcome",
|
|
|
|
- DefaultColor: door.Color("BRIGHT YELLOW"),
|
|
|
|
- }
|
|
|
|
|
|
+ var basicLine door.Line = {Text: "Welcome",
|
|
|
|
+ DefaultColor: door.Color("BRIGHT YELLOW"),
|
|
|
|
+ }
|
|
|
|
|
|
- d.Write(basicLine.Output() + door.Reset + door.CRNL)
|
|
|
|
|
|
+ d.Write(basicLine.Output() + door.Reset + door.CRNL)
|
|
|
|
|
|
This outputs Welcome in Bright/Bold Yellow.
|
|
This outputs Welcome in Bright/Bold Yellow.
|
|
|
|
|
|
Example Render:
|
|
Example Render:
|
|
|
|
|
|
- var renderAlphaDigit func(string) string = func(text string) string {
|
|
|
|
- var r door.Render{Text: text}
|
|
|
|
- var alpha string = door.ColorText("BOLD YELLOW")
|
|
|
|
- var digit string = door.ColorText("BOLD GREEN")
|
|
|
|
- var other string = door.Reset
|
|
|
|
- for _, letter := range text {
|
|
|
|
- if unicode.IsAlpha(letter) {
|
|
|
|
- r.Append(alpha, 1)
|
|
|
|
- } else {
|
|
|
|
- if unicode.IsDigit(letter) {
|
|
|
|
- r.Append(digit, 1)
|
|
|
|
|
|
+ var renderAlphaDigit func(string) string = func(text string) string {
|
|
|
|
+ var r door.Render{Text: text}
|
|
|
|
+ var alpha string = door.ColorText("BOLD YELLOW")
|
|
|
|
+ var digit string = door.ColorText("BOLD GREEN")
|
|
|
|
+ var other string = door.Reset
|
|
|
|
+ for _, letter := range text {
|
|
|
|
+ if unicode.IsAlpha(letter) {
|
|
|
|
+ r.Append(alpha, 1)
|
|
} else {
|
|
} else {
|
|
- r.Append(other, 1)
|
|
|
|
|
|
+ if unicode.IsDigit(letter) {
|
|
|
|
+ r.Append(digit, 1)
|
|
|
|
+ } else {
|
|
|
|
+ r.Append(other, 1)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ return r.Result
|
|
}
|
|
}
|
|
- return r.Result
|
|
|
|
- }
|
|
|
|
- var renderLine door.Line = {Text: "Render - 12345",
|
|
|
|
- RenderF: renderAlphaDigit,
|
|
|
|
- }
|
|
|
|
- d.Write(renderLine.Output() + door.Reset + door.CRNL)
|
|
|
|
|
|
+ var renderLine door.Line = {Text: "Render - 12345",
|
|
|
|
+ RenderF: renderAlphaDigit,
|
|
|
|
+ }
|
|
|
|
+ d.Write(renderLine.Output() + door.Reset + door.CRNL)
|
|
|
|
|
|
This outputs "Render" in Yellow, "12345" in Green, and " - " in White.
|
|
This outputs "Render" in Yellow, "12345" in Green, and " - " in White.
|
|
|
|
|
|
Example Update:
|
|
Example Update:
|
|
|
|
|
|
- var updateTime() string {
|
|
|
|
- var now time.Time = time.Now()
|
|
|
|
- var result string = now.Format("3:04:05 PM")
|
|
|
|
- return result
|
|
|
|
- }
|
|
|
|
- var timeLine door.Line = {Text: updateTime(),
|
|
|
|
- UpdateF: updateTime,
|
|
|
|
- }
|
|
|
|
- d.Write(timeLine.Output() + door.CRNL)
|
|
|
|
- time.Sleep(time.Second)
|
|
|
|
-
|
|
|
|
- // Check timeLine for update
|
|
|
|
- if timeLine.Update() {
|
|
|
|
- // Yes, there's an update to the time, output it.
|
|
|
|
|
|
+ var updateTime() string {
|
|
|
|
+ var now time.Time = time.Now()
|
|
|
|
+ var result string = now.Format("3:04:05 PM")
|
|
|
|
+ return result
|
|
|
|
+ }
|
|
|
|
+ var timeLine door.Line = {Text: updateTime(),
|
|
|
|
+ UpdateF: updateTime,
|
|
|
|
+ }
|
|
d.Write(timeLine.Output() + door.CRNL)
|
|
d.Write(timeLine.Output() + door.CRNL)
|
|
- }
|
|
|
|
|
|
+ time.Sleep(time.Second)
|
|
|
|
|
|
- if timeLine.Update() {
|
|
|
|
- // This isn't called. There were no changes.
|
|
|
|
- d.Write(timeLine.Output() + door.CRNL)
|
|
|
|
- }
|
|
|
|
|
|
+ // Check timeLine for update
|
|
|
|
+ if timeLine.Update() {
|
|
|
|
+ // Yes, there's an update to the time, output it.
|
|
|
|
+ d.Write(timeLine.Output() + door.CRNL)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if timeLine.Update() {
|
|
|
|
+ // This isn't called. There were no changes.
|
|
|
|
+ d.Write(timeLine.Output() + door.CRNL)
|
|
|
|
+ }
|
|
|
|
|
|
This outputs the Current time in 12 hour format. It pauses for a second,
|
|
This outputs the Current time in 12 hour format. It pauses for a second,
|
|
and outputs the new time.
|
|
and outputs the new time.
|
|
*/
|
|
*/
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+Line of text to display.
|
|
|
|
+*/
|
|
type Line struct {
|
|
type Line struct {
|
|
Text string // Text to be displayed
|
|
Text string // Text to be displayed
|
|
DefaultColor string // Default Color to use
|
|
DefaultColor string // Default Color to use
|
|
@@ -99,17 +103,19 @@ func (l *Line) Update() bool {
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// If a line Width has been set, make sure we match it.
|
|
func (l *Line) LineLength(text *string) {
|
|
func (l *Line) LineLength(text *string) {
|
|
- var length int
|
|
|
|
if l.Width == 0 {
|
|
if l.Width == 0 {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-
|
|
|
|
- if Unicode {
|
|
|
|
- length = len([]rune(*text))
|
|
|
|
- } else {
|
|
|
|
- length = len([]byte(*text))
|
|
|
|
- }
|
|
|
|
|
|
+ var length int = StringLen(*text)
|
|
|
|
+ /*
|
|
|
|
+ if Unicode {
|
|
|
|
+ length = len([]rune(*text))
|
|
|
|
+ } else {
|
|
|
|
+ length = len([]byte(*text))
|
|
|
|
+ }
|
|
|
|
+ */
|
|
if length > l.Width {
|
|
if length > l.Width {
|
|
log.Printf("ERROR: Line Width %d: Have %d\n", l.Width, length)
|
|
log.Printf("ERROR: Line Width %d: Have %d\n", l.Width, length)
|
|
} else {
|
|
} else {
|
|
@@ -136,6 +142,7 @@ func (l *Line) Output() string {
|
|
door.Render - Helper for Line RenderF (Render Function)
|
|
door.Render - Helper for Line RenderF (Render Function)
|
|
|
|
|
|
Example:
|
|
Example:
|
|
|
|
+
|
|
// RenderStatus - KEY_COLOR[key] COLON_COLOR[:] VALUE_COLOR[value]
|
|
// RenderStatus - KEY_COLOR[key] COLON_COLOR[:] VALUE_COLOR[value]
|
|
func RenderStatus(text string) string {
|
|
func RenderStatus(text string) string {
|
|
var r door.Render = Render{Line: text}
|
|
var r door.Render = Render{Line: text}
|