Browse Source

Fixed spinrite (CP437).

Steve Thielemann 1 year ago
parent
commit
aad8c6065f
2 changed files with 12 additions and 11 deletions
  1. 5 10
      door/spinrite.go
  2. 7 1
      door/write.go

+ 5 - 10
door/spinrite.go

@@ -223,19 +223,14 @@ func (sr *SpinRiteMsg) Output() string {
 	// Bug:  If we're changing to next message (sr.Next == True) ... but the
 	// message is > SpinRite.Length, it shows the text beyond what it should.
 
-	var texthalf int
-	if Unicode {
-		texthalf = len([]rune(msg)) / 2
-	} else {
-		texthalf = len(msg) / 2
-	}
+	var texthalf int = StringLen(msg) / 2
 
 	// Place text center, outwards.  Stopping if there's no space.
 
 	for i := 0; i < texthalf+1; i++ {
 		if Unicode {
 			if sr.OutputR[pos+i] == ' ' {
-				if texthalf+i < len(msg) {
+				if texthalf+i < StringLen(msg) {
 					sr.OutputR[pos+i] = []rune(msg)[texthalf+i]
 				}
 			} else {
@@ -250,15 +245,15 @@ func (sr *SpinRiteMsg) Output() string {
 			}
 		} else {
 			if sr.OutputB[pos+i] == ' ' {
-				if texthalf+i < len(msg) {
+				if texthalf+i < StringLen(msg) {
 					sr.OutputB[pos+i] = byte(msg[texthalf+i])
 				}
 			} else {
 				break
 			}
 			if i != 0 {
-				if sr.OutputB[pos-1] == ' ' {
-					sr.OutputB[pos-1] = byte(msg[texthalf-i])
+				if sr.OutputB[pos-i] == ' ' {
+					sr.OutputB[pos-i] = byte(msg[texthalf-i])
 				} else {
 					break
 				}

+ 7 - 1
door/write.go

@@ -128,12 +128,18 @@ ok == false
 writing to a closed channel is a panic.
 
 Have the Write manage itself.
-if
 */
 
+// For now, update is SavePos + output + RestorePos.
+// FUTURE: Access the screen struct to "save" Color+Attr+Pos.
+func (d *Door) Update(output string) {
+	d.Write(SAVE_POS + output + RESTORE_POS)
+}
+
 // Write string to client.
 func (d *Door) Write(output string) {
 	if output == "" {
+		// That was easy.
 		return
 	}