Following bugs are fixed:
1.Handle out of bound cursor movements: vi in busybox sets cursor
to (999,999) expecting it to be set to right, bottom correctly.
2.Correctly determine redirected non-terminal file.
Signed-off-by: Sachin Joshi <sachin_jayant_joshi@hotmail.com>
| ... | ... |
@@ -265,6 +265,10 @@ func StdStreams() (stdOut io.Writer, stdErr io.Writer, stdIn io.ReadCloser) {
|
| 265 | 265 |
func GetHandleInfo(in interface{}) (uintptr, bool) {
|
| 266 | 266 |
var inFd uintptr |
| 267 | 267 |
var isTerminalIn bool |
| 268 |
+ if file, ok := in.(*os.File); ok {
|
|
| 269 |
+ inFd = file.Fd() |
|
| 270 |
+ isTerminalIn = IsTerminal(inFd) |
|
| 271 |
+ } |
|
| 268 | 272 |
if tr, ok := in.(*terminalReader); ok {
|
| 269 | 273 |
if file, ok := tr.wrappedReader.(*os.File); ok {
|
| 270 | 274 |
inFd = file.Fd() |
| ... | ... |
@@ -678,14 +682,24 @@ func (term *WindowsTerminal) HandleOutputCommand(fd uintptr, command []byte) (n |
| 678 | 678 |
// [line;columnf |
| 679 | 679 |
// Moves the cursor to the specified position (coordinates). |
| 680 | 680 |
// If you do not specify a position, the cursor moves to the home position at the upper-left corner of the screen (line 0, column 0). |
| 681 |
+ screenBufferInfo, err := GetConsoleScreenBufferInfo(uintptr(handle)) |
|
| 682 |
+ if err != nil {
|
|
| 683 |
+ return len(command), err |
|
| 684 |
+ } |
|
| 681 | 685 |
line, err := parseInt16OrDefault(parsedCommand.getParam(0), 1) |
| 682 | 686 |
if err != nil {
|
| 683 | 687 |
return len(command), err |
| 684 | 688 |
} |
| 689 |
+ if line > int16(screenBufferInfo.Window.Bottom) {
|
|
| 690 |
+ line = int16(screenBufferInfo.Window.Bottom) |
|
| 691 |
+ } |
|
| 685 | 692 |
column, err := parseInt16OrDefault(parsedCommand.getParam(1), 1) |
| 686 | 693 |
if err != nil {
|
| 687 | 694 |
return len(command), err |
| 688 | 695 |
} |
| 696 |
+ if column > int16(screenBufferInfo.Window.Right) {
|
|
| 697 |
+ column = int16(screenBufferInfo.Window.Right) |
|
| 698 |
+ } |
|
| 689 | 699 |
// The numbers are not 0 based, but 1 based |
| 690 | 700 |
r, err = setConsoleCursorPosition(uintptr(handle), false, int16(column-1), int16(line-1)) |
| 691 | 701 |
if !r {
|