|
@@ -2,7 +2,6 @@ package colorable
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"bytes"
|
|
"bytes"
|
|
|
- "fmt"
|
|
|
|
|
"io"
|
|
"io"
|
|
|
"math"
|
|
"math"
|
|
|
"os"
|
|
"os"
|
|
@@ -362,6 +361,7 @@ func (w *Writer) Write(data []byte) (n int, err error) {
|
|
|
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
|
|
|
|
|
|
er := bytes.NewBuffer(data)
|
|
er := bytes.NewBuffer(data)
|
|
|
|
|
+ var bw [1]byte
|
|
|
loop:
|
|
loop:
|
|
|
for {
|
|
for {
|
|
|
r1, _, err := procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
r1, _, err := procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
@@ -369,32 +369,33 @@ loop:
|
|
|
break loop
|
|
break loop
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- c1, _, err := er.ReadRune()
|
|
|
|
|
|
|
+ c1, err := er.ReadByte()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
break loop
|
|
break loop
|
|
|
}
|
|
}
|
|
|
if c1 != 0x1b {
|
|
if c1 != 0x1b {
|
|
|
- fmt.Fprint(w.out, string(c1))
|
|
|
|
|
|
|
+ bw[0] = c1
|
|
|
|
|
+ w.out.Write(bw[:])
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
- c2, _, err := er.ReadRune()
|
|
|
|
|
|
|
+ c2, err := er.ReadByte()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- w.lastbuf.WriteRune(c1)
|
|
|
|
|
|
|
+ w.lastbuf.WriteByte(c1)
|
|
|
break loop
|
|
break loop
|
|
|
}
|
|
}
|
|
|
if c2 != 0x5b {
|
|
if c2 != 0x5b {
|
|
|
- w.lastbuf.WriteRune(c1)
|
|
|
|
|
- w.lastbuf.WriteRune(c2)
|
|
|
|
|
|
|
+ w.lastbuf.WriteByte(c1)
|
|
|
|
|
+ w.lastbuf.WriteByte(c2)
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
var buf bytes.Buffer
|
|
|
- var m rune
|
|
|
|
|
|
|
+ var m byte
|
|
|
for {
|
|
for {
|
|
|
- c, _, err := er.ReadRune()
|
|
|
|
|
|
|
+ c, err := er.ReadByte()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- w.lastbuf.WriteRune(c1)
|
|
|
|
|
- w.lastbuf.WriteRune(c2)
|
|
|
|
|
|
|
+ w.lastbuf.WriteByte(c1)
|
|
|
|
|
+ w.lastbuf.WriteByte(c2)
|
|
|
w.lastbuf.Write(buf.Bytes())
|
|
w.lastbuf.Write(buf.Bytes())
|
|
|
break loop
|
|
break loop
|
|
|
}
|
|
}
|
|
@@ -466,7 +467,7 @@ loop:
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
|
- csbi.cursorPosition.x = short(n-1)
|
|
|
|
|
|
|
+ csbi.cursorPosition.x = short(n - 1)
|
|
|
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
|
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
|
|
case 'H':
|
|
case 'H':
|
|
|
token := strings.Split(buf.String(), ";")
|
|
token := strings.Split(buf.String(), ";")
|
|
@@ -481,8 +482,8 @@ loop:
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
- csbi.cursorPosition.x = short(n2-1)
|
|
|
|
|
- csbi.cursorPosition.y = short(n1-1)
|
|
|
|
|
|
|
+ csbi.cursorPosition.x = short(n2 - 1)
|
|
|
|
|
+ csbi.cursorPosition.y = short(n1 - 1)
|
|
|
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
|
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
|
|
case 'J':
|
|
case 'J':
|
|
|
n, err := strconv.Atoi(buf.String())
|
|
n, err := strconv.Atoi(buf.String())
|