Browse Source

Treat unicode as []rune.

Steve Thielemann 3 years ago
parent
commit
6d59479920
1 changed files with 9 additions and 1 deletions
  1. 9 1
      door/line.go

+ 9 - 1
door/line.go

@@ -36,6 +36,7 @@ func (l *Line) Output() string {
 //
 // Sample RenderF function
 // Upcase is BOLD Blue, everything else is Yellow
+/*
 func Render_BlueYellow(text string) string {
 	var output string
 	var lastColor string
@@ -60,6 +61,7 @@ func Render_BlueYellow(text string) string {
 	}
 	return output
 }
+*/
 
 type Render struct {
 	Line      string
@@ -73,7 +75,13 @@ func (r *Render) Append(color string, len int) {
 		r.LastColor = color
 		r.Result += color
 	}
-	r.Result += r.Line[r.Pos : r.Pos+len]
+
+	if Unicode {
+		// Treat unicode as []rune.
+		r.Result += string([]rune(r.Line)[r.Pos : r.Pos+len])
+	} else {
+		r.Result += r.Line[r.Pos : r.Pos+len]
+	}
 	r.Pos += len
 }