Merge pull request #32 from bcicen/skip-erase-on-nil-height

skip line erasing on render when window size is not yet available
This commit is contained in:
Masashi SHIBATA 2018-02-13 22:01:18 +09:00 committed by GitHub
commit 5212a86596
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -154,7 +154,7 @@ func (r *Render) renderCompletion(buf *Buffer, completions *CompletionManager) {
// +1 means a width of scrollbar. // +1 means a width of scrollbar.
r.out.CursorBackward(width + 1) r.out.CursorBackward(width + 1)
} }
if d == 0 && len(prefix) + len(buf.Text()) != 0 { // the cursor is on right end. if d == 0 && len(prefix)+len(buf.Text()) != 0 { // the cursor is on right end.
// DON'T CURSOR DOWN HERE. Because the line doesn't erase properly. // DON'T CURSOR DOWN HERE. Because the line doesn't erase properly.
r.out.CursorForward(width + 1) r.out.CursorForward(width + 1)
} else if d+width > int(r.col) { } else if d+width > int(r.col) {
@ -168,18 +168,20 @@ func (r *Render) renderCompletion(buf *Buffer, completions *CompletionManager) {
// Render renders to the console. // Render renders to the console.
func (r *Render) Render(buffer *Buffer, completion *CompletionManager) { func (r *Render) Render(buffer *Buffer, completion *CompletionManager) {
line := buffer.Text()
prefix := r.getCurrentPrefix() prefix := r.getCurrentPrefix()
// Erasing if r.col > 0 {
r.out.CursorBackward(int(r.col) + len(buffer.Text()) + len(prefix)) // Erasing
r.out.EraseDown() r.out.CursorBackward(int(r.col) + len(line) + len(prefix))
r.out.EraseDown()
// prepare area // prepare area
line := buffer.Text() h := ((len(prefix) + len(line)) / int(r.col)) + 1 + int(completion.max)
h := ((len(prefix) + len(line)) / int(r.col)) + 1 + int(completion.max) if h > int(r.row) || completionMargin > int(r.col) {
if h > int(r.row) || completionMargin > int(r.col) { r.renderWindowTooSmall()
r.renderWindowTooSmall() return
return }
} }
// Rendering // Rendering