Bläddra i källkod

Let m & n for ESC[nG & ESC[m;nH start with 1 (not 0)

HAYAMA_Kaoru 9 år sedan
förälder
incheckning
ed5ddd806a
2 ändrade filer med 18 tillägg och 3 borttagningar
  1. 15 0
      _example2/main.go
  2. 3 3
      colorable_windows.go

+ 15 - 0
_example2/main.go

@@ -0,0 +1,15 @@
+package main
+
+import (
+	"bufio"
+	"fmt"
+	".."
+)
+
+func main(){
+	stdOut := bufio.NewWriter(colorable.NewColorableStdout())
+
+	fmt.Fprint(stdOut,"\x1B[3GMove to 3rd Column\n")
+	fmt.Fprint(stdOut,"\x1B[1;2HMove to 2nd Column on 1st Line\n")
+	stdOut.Flush()
+}

+ 3 - 3
colorable_windows.go

@@ -466,7 +466,7 @@ loop:
 				continue
 			}
 			procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
-			csbi.cursorPosition.x = short(n)
+			csbi.cursorPosition.x = short(n-1)
 			procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
 		case 'H':
 			token := strings.Split(buf.String(), ";")
@@ -481,8 +481,8 @@ loop:
 			if err != nil {
 				continue
 			}
-			csbi.cursorPosition.x = short(n2)
-			csbi.cursorPosition.y = short(n1)
+			csbi.cursorPosition.x = short(n2-1)
+			csbi.cursorPosition.y = short(n1-1)
 			procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
 		case 'J':
 			n, err := strconv.Atoi(buf.String())