Function: cfrs-read

cfrs-read is an autoloaded and byte-compiled function defined in cfrs.el.

Signature

(cfrs-read PROMPT &optional INITIAL-INPUT)

Documentation

Read a string using a pos-frame with given PROMPT and INITIAL-INPUT.

Source Code

;; Defined in ~/.emacs.d/elpa/cfrs-20250729.1422/cfrs.el
;;;###autoload
(defun cfrs-read (prompt &optional initial-input)
  "Read a string using a pos-frame with given PROMPT and INITIAL-INPUT."
  (if (not (or (display-graphic-p)
               (not (fboundp #'display-buffer-in-side-window))))
      (read-string prompt initial-input)
    (let* ((buffer (get-buffer-create cfrs--buffer-name))
           (border-color (face-attribute 'cfrs-border-color :background nil t))
           (cursor (cfrs--determine-cursor-type))
           (width  (+ 2 ;; extra space for margin and cursor
                      (min cfrs-max-width
                           (max cfrs-min-width
                                (+ (length prompt)
                                   (if initial-input (length initial-input) 0))))))
           (frame (posframe-show
                   buffer
                   :min-height 1
                   :min-width width
                   :internal-border-width 2
                   :internal-border-color border-color
                   :string ""
                   :accept-focus t
                   :override-parameters `(,@cfrs-frame-parameters
                                          (cursor-type . ,cursor)))))
      (with-selected-frame frame
        (select-frame frame)
        (x-focus-frame frame)
        (add-hook 'delete-frame-functions #'cfrs--on-frame-kill nil :local)
        (with-current-buffer buffer
          (cfrs-input-mode)
          (-each (overlays-in (point-min) (point-max)) #'delete-overlay)
          (erase-buffer)
          (-doto (make-overlay 1 2)
            (overlay-put
             'before-string
             (propertize (concat " " prompt) 'face 'minibuffer-prompt))
            (overlay-put 'rear-nonsticky t)
            (overlay-put 'read-only t))
          (when initial-input
            (insert initial-input))
          (when (and (bound-and-true-p evil-mode)
                     (fboundp 'evil-insert-state))
            (evil-insert-state nil))
          (end-of-line)
          (recursive-edit)
          (cfrs--hide)
          (s-trim (buffer-string)))))))