Skip to content

Commit

Permalink
prompt-buffer(suggestion-and-mark-count): Refactor.
Browse files Browse the repository at this point in the history
A saner version of commit efcdca4.
  • Loading branch information
aadcg committed Oct 31, 2023
1 parent 5875b6d commit c00f7f3
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions source/prompt-buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -329,34 +329,22 @@ See also `show-prompt-buffer'."
(show-prompt-buffer next-prompt-buffer))
(setf (ffi-height prompt-buffer) 0))))

(defun suggestion-and-mark-count (prompt-buffer suggestions marks
&key enable-marks-p pad-p)
(defun suggestion-and-mark-count (prompt-buffer suggestions marks &key enable-marks-p pad-p)
(alex:maxf (max-suggestions prompt-buffer)
(length suggestions))
(labels ((decimals (n)
(cond
((< n 0)
(decimals (- n)))
((< n 10)
1)
(t (1+ (decimals (truncate n 10)))))))
(cond
((not suggestions)
"")
((hide-suggestion-count-p prompt-buffer)
"")
(t
(let ((padding (if pad-p
(prin1-to-string (decimals (max-suggestions prompt-buffer)))
"0")))
(format nil (str:concat "[~a~" padding ",,,' @a]")
(cond
((or marks enable-marks-p)
(format nil
(str:concat "~" padding ",,,' @a/")
(length marks)))
(t ""))
(length suggestions)))))))
(flet ((digits-count (n) (1+ (floor (log (abs n) 10)))))
(if (or (not suggestions)
(hide-suggestion-count-p prompt-buffer))
""
(let ((padding (if pad-p
(prin1-to-string (digits-count (max-suggestions prompt-buffer)))
"0")))
(format nil
(str:concat "[~a~" padding ",,,' @a]")
(if (or marks enable-marks-p)
(format nil (str:concat "~" padding ",,,' @a/") (length marks))
"")
(length suggestions))))))

(defun prompt-render-prompt (prompt-buffer)
(let* ((suggestions (prompter:all-suggestions prompt-buffer))
Expand Down

0 comments on commit c00f7f3

Please sign in to comment.