Procházet zdrojové kódy

Better func names in write. Fixed misnamed var.

Steve Thielemann před 3 roky
rodič
revize
70c11e3a0e
2 změnil soubory, kde provedl 14 přidání a 17 odebrání
  1. 1 1
      door/input_linux.go
  2. 13 16
      door/write.go

+ 1 - 1
door/input_linux.go

@@ -10,7 +10,7 @@ func Reader(handle int) {
 
 	buffer := make([]byte, 1)
 	for {
-		r, err := syscall.Read(d.READFD, buffer)
+		read, err := syscall.Read(handle, buffer)
 		if err != nil {
 			log.Printf("Reader ERR: %#v\n", err)
 			close(readerChannel)

+ 13 - 16
door/write.go

@@ -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)
-		}
-	*/
-
 }