-
Notifications
You must be signed in to change notification settings - Fork 355
Clear to end of screen before redrawing prompt #476
base: master
Are you sure you want to change the base?
Changes from all commits
338c156
9decb76
363d3eb
cf89954
3090f93
38e598c
9e539c3
b96ec7a
d29d6fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,18 +47,24 @@ func (c *Cursor) Back(n int) error { | |
|
||
// NextLine moves cursor to beginning of the line n lines down. | ||
func (c *Cursor) NextLine(n int) error { | ||
if err := c.Down(1); err != nil { | ||
if err := c.HorizontalAbsolute(0); err != nil { | ||
return err | ||
} | ||
return c.HorizontalAbsolute(0) | ||
if n == 0 { | ||
return nil | ||
} | ||
return c.Down(n) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch that this didn't use to forward the |
||
} | ||
|
||
// PreviousLine moves cursor to beginning of the line n lines up. | ||
func (c *Cursor) PreviousLine(n int) error { | ||
if err := c.Up(1); err != nil { | ||
if err := c.HorizontalAbsolute(0); err != nil { | ||
return err | ||
} | ||
return c.HorizontalAbsolute(0) | ||
if n == 0 { | ||
return nil | ||
} | ||
return c.Up(n) | ||
} | ||
|
||
// HorizontalAbsolute moves cursor horizontally to x. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
package terminal | ||
|
||
type EraseLineMode int | ||
type EraseScreenMode int | ||
|
||
const ( | ||
ERASE_LINE_END EraseLineMode = iota | ||
ERASE_LINE_START | ||
ERASE_LINE_ALL | ||
) | ||
|
||
const ( | ||
ERASE_SCREEN_END EraseScreenMode = iota | ||
ERASE_SCREEN_START | ||
ERASE_SCREEN_ALL | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,22 @@ func EraseLine(out FileWriter, mode EraseLineMode) error { | |
_, _, err := procFillConsoleOutputCharacter.Call(uintptr(handle), uintptr(' '), uintptr(x), uintptr(*(*int32)(unsafe.Pointer(&cursor))), uintptr(unsafe.Pointer(&w))) | ||
return normalizeError(err) | ||
} | ||
|
||
func EraseScreen(out FileWriter, mode EraseScreenMode) error { | ||
handle := syscall.Handle(out.Fd()) | ||
|
||
var csbi consoleScreenBufferInfo | ||
if _, _, err := procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))); normalizeError(err) != nil { | ||
return err | ||
} | ||
|
||
var w uint32 | ||
cursor := csbi.cursorPosition | ||
|
||
lineCount := csbi.window.bottom - csbi.cursorPosition.Y | ||
termWidth := csbi.size.X | ||
screenSize := lineCount * termWidth | ||
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Windows version of this This seems to match the behavior of the POSIX |
||
|
||
_, _, err := procFillConsoleOutputCharacter.Call(uintptr(handle), uintptr(' '), uintptr(screenSize), uintptr(*(*int32)(unsafe.Pointer(&cursor))), uintptr(unsafe.Pointer(&w))) | ||
return normalizeError(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why first move horizontal and then try to move between lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be weird behavior when going
Down(0)
orUp(0)
, where the cursor moves down or up1
instead of remaining on the same line. I'm not sure if this is expected ANSI behavior for\x1b[0A
, but this change was made to guard against this case.It might be more appropriate to move this check for
n == 0
to theDown
andUp
functions instead? I wasn't sure if this current behavior was relied on by other functions and felt that this change was safer.