1
0
Fork 0

- prevented crash when suggestion windows are shown

when the width of the terminal was too thin  paginating the suggestions failed.
This commit is contained in:
cage 2021-08-07 13:22:33 +02:00
parent 638f970ddf
commit 2c6497a6f0
3 changed files with 47 additions and 21 deletions

View File

@ -77,10 +77,23 @@
(multiple-value-bind (candidates common-prefix underline-char-indices) (multiple-value-bind (candidates common-prefix underline-char-indices)
(funcall complete:*complete-function* hint) (funcall complete:*complete-function* hint)
(when candidates (when candidates
(let* ((batches (text-utils:box-fit-multiple-column candidates (let* ((max-string-size (max 1 (floor (/ (win-width-no-border object) 2.5))))
(- (win-width object) 2) (truncate-fn (lambda (batch)
(- (win-height object) (mapcar (lambda (a)
+box-height-diff+))) (safe-subseq a
0
max-string-size))
batch)))
(batches (handler-bind ((conditions:out-of-bounds
(lambda (e)
(declare (ignore e))
(invoke-restart 'truncate))))
(text-utils:box-fit-multiple-column candidates
(- (win-width object) 2)
(- (win-height object)
+box-height-diff+)
:truncate-restart-fn
truncate-fn)))
(padding-size (- (length candidates) (padding-size (- (length candidates)
(length underline-char-indices))) (length underline-char-indices)))
(padding (when (> padding-size 0) (padding (when (> padding-size 0)
@ -119,18 +132,18 @@
for row in column for row in column
for indices-row-underlined in column-indices for indices-row-underlined in column-indices
with row-count = 1 do with row-count = 1 do
(let ((text (if (and (= row-count (1+ selected-item-row-index)) (let* ((text (if (and (= row-count (1+ selected-item-row-index))
(= column-count selected-item-column-index)) (= column-count selected-item-column-index))
(make-tui-string row (make-tui-string row
:fgcolor foreground-selected-item :fgcolor foreground-selected-item
:bgcolor background-selected-item) :bgcolor background-selected-item)
(make-tui-string row)))) (make-tui-string row)))
(print-text object (tui-text (handler-case
(apply-attributes text (apply-attributes text
indices-row-underlined indices-row-underlined
matched-attributes) matched-attributes)
column-offset (error () text))))
row-count)) (print-text object tui-text column-offset row-count))
(incf row-count)) (incf row-count))
(incf column-offset column-size))) (incf column-offset column-size)))
(draw-pagination-info object))) (draw-pagination-info object)))

View File

@ -101,10 +101,14 @@
:line-char render-vertical-line-value :line-char render-vertical-line-value
:last-child-char render-leaf-value :last-child-char render-leaf-value
:print-data t)) :print-data t))
(batches (text-utils:box-fit-multiple-column-annotated tree-lines (batches (handler-bind ((conditions:out-of-bounds
(- (win-width window) 2) (lambda (e)
(- (win-height window) (declare (ignore e))
+box-height-diff+)))) (invoke-restart 'truncate))))
(text-utils:box-fit-multiple-column-annotated tree-lines
(- (win-width window) 2)
(- (win-height window)
+box-height-diff+)))))
(with-accessors ((tree-color-map tree-color-map)) window (with-accessors ((tree-color-map tree-color-map)) window
(let ((colorized-batches (loop for batch in batches collect (let ((colorized-batches (loop for batch in batches collect
(loop for column in batch collect (loop for column in batch collect

View File

@ -523,7 +523,15 @@ lines fitted in the box (nil in this case).
lines-length) lines-length)
rest-lines-index))))) rest-lines-index)))))
(defun box-fit-multiple-column (lines box-width box-height &key (spaces-between 1)) (defun box-fit-multiple-column (lines box-width box-height
&key
(spaces-between 1)
(truncate-restart-fn (lambda (batch)
(mapcar (lambda (a)
(subseq a
0
(- box-width spaces-between)))
batch))))
"Given 'lines' as list of strings this procedure will fits them in a "Given 'lines' as list of strings this procedure will fits them in a
box of width and height passed as parameters ('box-width' and 'box-height'). box of width and height passed as parameters ('box-width' and 'box-height').
@ -556,6 +564,7 @@ printed in the box column by column; in the example above the results are:
(multiple-value-bind (columns rest-index) (multiple-value-bind (columns rest-index)
(box-fit-as-much-lines-columns lines box-width (box-fit-as-much-lines-columns lines box-width
box-height box-height
:truncate-restart-fn truncate-restart-fn
:spaces-between spaces-between :spaces-between spaces-between
:pad-right-fn :pad-right-fn
(lambda (a max-width) (lambda (a max-width)