@@ -92,9 +92,13 @@ func (e *Engine) Refresh() {
9292
9393 // Display hints and completions, go back
9494 // to the start of the line, then to cursor.
95- e .displayHelpers ()
96- e .cursorHintToLineStart ()
97- e .lineStartToCursorPos ()
95+ helpersMoved := e .displayHelpers ()
96+ if helpersMoved {
97+ e .cursorHintToLineStart ()
98+ e .lineStartToCursorPos ()
99+ } else {
100+ e .lineEndToCursorPos ()
101+ }
98102 fmt .Print (term .ShowCursor )
99103}
100104
@@ -294,22 +298,55 @@ func (e *Engine) displayMultilinePrompts() {
294298// displayHelpers renders the hint and completion sections.
295299// It assumes that the cursor is on the last line of input,
296300// and goes back to this same line after displaying this.
297- func (e * Engine ) displayHelpers () {
298- fmt .Print (term .NewlineReturn )
299-
301+ func (e * Engine ) displayHelpers () bool {
300302 // Recompute completions and hints if autocompletion is on.
301303 e .completer .Autocomplete ()
302304
305+ hintRows := ui .CoordinatesHint (e .hint )
306+ compMatches := e .completer .Matches ()
307+ compSkip := e .completer .DisplaySkipped ()
308+
309+ if e .hintRows == 0 && e .compRows == 0 && hintRows == 0 && (compMatches == 0 || compSkip ) {
310+ return false
311+ }
312+
313+ fmt .Print (term .NewlineReturn )
314+
315+ prevHintRows := e .hintRows
316+ prevCompRows := e .compRows
317+
303318 // Display hint and completions.
304319 ui .DisplayHint (e .hint )
305320 e .hintRows = ui .CoordinatesHint (e .hint )
306- completion .Display (e .completer , e .AvailableHelperLines ())
307- e .compRows = completion .Coordinates (e .completer )
321+ if compMatches > 0 && ! compSkip {
322+ completion .Display (e .completer , e .AvailableHelperLines ())
323+ e .compRows = completion .Coordinates (e .completer )
324+ } else {
325+ e .completer .ResetUsedRows ()
326+ e .compRows = 0
327+ }
328+
329+ if e .hintRows + e .compRows < prevHintRows + prevCompRows {
330+ fmt .Print (term .ClearScreenBelow )
331+ }
308332
309333 // Go back to the first line below the input line.
310334 term .MoveCursorBackwards (term .GetWidth ())
311335 term .MoveCursorUp (e .compRows )
312- term .MoveCursorUp (ui .CoordinatesHint (e .hint ))
336+ term .MoveCursorUp (e .hintRows )
337+
338+ return true
339+ }
340+
341+ // lineEndToCursorPos moves the cursor from the end of the input line
342+ // to the current cursor position.
343+ func (e * Engine ) lineEndToCursorPos () {
344+ if e .lineRows > e .cursorRow {
345+ term .MoveCursorUp (e .lineRows - e .cursorRow )
346+ }
347+
348+ term .MoveCursorBackwards (term .GetWidth ())
349+ term .MoveCursorForwards (e .cursorCol )
313350}
314351
315352// AvailableHelperLines returns the number of lines available below the hint section.
0 commit comments