From 2a35ceea897796d90ff6c2c8c7e99896f683a4ad Mon Sep 17 00:00:00 2001 From: Nao YONASHIRO Date: Wed, 14 Feb 2018 19:50:00 +0900 Subject: [PATCH] fix: fix runtime error when r.col == 0 --- render.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/render.go b/render.go index e378678..2bab0d8 100644 --- a/render.go +++ b/render.go @@ -162,24 +162,26 @@ func (r *Render) renderCompletion(buf *Buffer, completions *CompletionManager) { // Render renders to the console. func (r *Render) Render(buffer *Buffer, completion *CompletionManager) { + // In situations where a psuedo tty is allocated (e.g. within a docker container), + // window size via TIOCGWINSZ is not immediately available and will result in 0,0 dimensions. + if r.col == 0 { + return + } + + // Erasing + r.clear(r.previousCursor) + line := buffer.Text() prefix := r.getCurrentPrefix() cursor := len(prefix) + len(line) - // In situations where a psuedo tty is allocated (e.g. within a docker container), - // window size via TIOCGWINSZ is not immediately available and will result in 0,0 dimensions. - if r.col > 0 { - // Erasing - r.clear(r.previousCursor) + // prepare area + _, y := r.toPos(cursor) - // prepare area - _, y := r.toPos(cursor) - - h := y + 1 + int(completion.max) - if h > int(r.row) || completionMargin > int(r.col) { - r.renderWindowTooSmall() - return - } + h := y + 1 + int(completion.max) + if h > int(r.row) || completionMargin > int(r.col) { + r.renderWindowTooSmall() + return } // Rendering