|
@@ -13,6 +13,10 @@ func init() {
|
|
|
FindANSIColor = regexp.MustCompile("\x1b\\[([0-9;]*)m")
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
+find \x1b[0;1;37;40m codes.
|
|
|
+return array of start/end positions in the given string.
|
|
|
+*/
|
|
|
func find_ansicolor(text string) [][]int {
|
|
|
var color_codes [][]int
|
|
|
|
|
@@ -49,6 +53,7 @@ type ANSIColorParts struct {
|
|
|
BG int
|
|
|
}
|
|
|
|
|
|
+// Parse an array of codes into their ANSIColorParts.
|
|
|
func ParseColorArray(colorarray []int) ANSIColorParts {
|
|
|
var acp ANSIColorParts
|
|
|
acp.FG = -1
|
|
@@ -72,7 +77,8 @@ func ParseColorArray(colorarray []int) ANSIColorParts {
|
|
|
return acp
|
|
|
}
|
|
|
|
|
|
-func (d *Door) ParseLastColor(output string) {
|
|
|
+// Update the LastColor with the latest codes.
|
|
|
+func (d *Door) UpdateLastColor(output string) {
|
|
|
// use the last color information + whatever is in the string to
|
|
|
// track the last color set
|
|
|
updated := ParseColorArray(d.LastColor)
|
|
@@ -137,30 +143,21 @@ func (d *Door) Write(output string) {
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
+ // Updating some other part of the screen.
|
|
|
+ // Use SavePos/RestorePos in the same string.
|
|
|
+ // We'll append the LastColor to the string,
|
|
|
+ // allowing the update to not mess up current color.
|
|
|
if strings.HasSuffix(output, RestorePos) {
|
|
|
output += Color(d.LastColor...)
|
|
|
} else {
|
|
|
- d.ParseLastColor(output)
|
|
|
+ d.UpdateLastColor(output)
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
+ // Output the string, translating the ESC code to ^[ for outputting.
|
|
|
temp := strings.Replace(output, "\x1b", "^[", -1)
|
|
|
log.Printf("Parse: [%s]\n", temp)
|
|
|
*/
|
|
|
|
|
|
writerChannel <- output
|
|
|
-
|
|
|
- /*
|
|
|
- buffer := []byte(output)
|
|
|
- n, err := syscall.Write(d.WRITEFD, buffer)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Write error/HANGUP?", n)
|
|
|
- d.Disconnected = true
|
|
|
- }
|
|
|
- // No, this isn't it. The # of bytes in buffer == bytes written.
|
|
|
- if n != len(buffer) {
|
|
|
- fmt.Printf("Write fail: %d != %d\n", len(buffer), n)
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
}
|