Skip to content

Commit

Permalink
Use Lparallel-powered prompter library.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambrevar committed May 31, 2023
1 parent f073f7d commit 9f7dd06
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion source/command.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ With MODE-SYMBOLS and GLOBAL-P, include global commands."
(with-current-buffer (current-buffer)
(let ((*interactive-p* t))
(handler-case (apply #'funcall command args)
(prompt-buffer-canceled ()
(prompter:canceled ()
(log:debug "Prompt buffer interrupted")
nil)))))

Expand Down
2 changes: 1 addition & 1 deletion source/concurrency.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ raised condition."
(alex:with-gensyms (c sub-c)
`(if (or *run-from-repl-p* *debug-on-error*)
(handler-case (progn ,@body)
(prompt-buffer-canceled ()
(prompter:canceled ()
(log:debug "Prompt buffer interrupted")))
(ignore-errors
(handler-bind
Expand Down
5 changes: 3 additions & 2 deletions source/conditions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ It should abort the ongoing command, but not the whole process."))
((context :initarg :context :reader context)))

(export-always 'prompt-buffer-canceled)
(define-condition prompt-buffer-canceled (error)
())
(define-condition prompt-buffer-canceled (prompter:canceled) ; TODO: Remove with 4.0.0.
()
(:documentation "Obsolete. Use `prompter:canceled' instead."))
(export-always 'prompt-buffer-non-interactive)
(define-condition prompt-buffer-non-interactive (error)
((name :initarg :name :accessor name))
Expand Down
2 changes: 1 addition & 1 deletion source/configuration.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ Examples:
,@(when explicit-no-p
(list :no no)))
:hide-suggestion-count-p t)
(prompt-buffer-canceled () nil))))
(prompter:canceled () nil))))
(if answer
,yes-form
,no-form)))
Expand Down
2 changes: 1 addition & 1 deletion source/describe.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ Otherwise prompt for matches."
(prompt1
:prompt (format nil "Set ~a to" variable)
:sources 'prompter:raw-source))))
(prompt-buffer-canceled nil))))
(prompter:canceled nil))))
"Change value")
(:p (:raw (value->html (symbol-value variable))))
(:nsection
Expand Down
2 changes: 1 addition & 1 deletion source/inspector.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ values in help buffers, REPL and elsewhere."))
(prompt1
:prompt (format nil "Set ~a to" slot-name)
:sources 'prompter:raw-source))))
(prompt-buffer-canceled nil))))
(prompter:canceled nil))))
"change "))
(:dd (:raw (value->html (slot-value value slot-name) t)))))
(:raw (escaped-literal-print value))))))
Expand Down
2 changes: 1 addition & 1 deletion source/mode/prompt-buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ current unmarked suggestion."
(prompter:actions-on-return first-prompt-buffer))
(progn
(echo-warning "No actions to choose from.")
(error 'prompt-buffer-canceled))))
(error 'prompt-buffer-canceled)))) ; TODO: Obsolete, switch to `promter:canceled' with 4.0.0.

(defun prompt-buffer-actions-on-current-suggestion (&optional (window (current-window)))
(sera:and-let* ((first-prompt-buffer (first (nyxt::active-prompt-buffers window))))
Expand Down
2 changes: 1 addition & 1 deletion source/mode/small-web.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ Implies that `small-web-mode' is enabled."
(prompt1 :prompt meta
:sources 'prompter:raw-source
:invisible-input-p (eq status :sensitive-input))
(nyxt::prompt-buffer-canceled () "")))))
(prompter:canceled () "")))))
(buffer-load (str:concat url "?" text) :buffer buffer)))
(:success
(if (str:starts-with-p "text/gemini" meta)
Expand Down
22 changes: 7 additions & 15 deletions source/prompt-buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,8 @@ See `update-prompt-input' to update the changes visually."
"Block and return PROMPT-BUFFER results."
(when (prompt-buffer-p prompt-buffer)
(show-prompt-buffer prompt-buffer)
(calispel:fair-alt
((calispel:? (prompter:result-channel prompt-buffer) results)
(hide-prompt-buffer prompt-buffer)
results)
((calispel:? (prompter:interrupt-channel prompt-buffer))
(hide-prompt-buffer prompt-buffer)
(error 'prompt-buffer-canceled)))))
(unwind-protect (lpara:force (prompter:result-channel prompt-buffer))
(hide-prompt-buffer prompt-buffer))))

(sera:eval-always
(defvar %prompt-args (delete-duplicates
Expand Down Expand Up @@ -647,23 +642,20 @@ See the documentation of `prompt-buffer' to know more about the options."
(restart-case
(error 'prompt-buffer-non-interactive :name prompter:prompt)
(prompt-anyway () nil)
(cancel () (error 'prompt-buffer-canceled))))
(cancel () (error 'prompter:canceled))))
(alex:when-let ((prompt-text (getf args :prompt)))
(when (str:ends-with-p ":" prompt-text)
(log:warn "Prompt text ~s should not end with a ':'." prompt-text)
(setf (getf args :prompt) (string-right-trim (uiop:strcat ":" serapeum:whitespace) prompt-text))))
(let ((prompt-object-channel (make-channel 1)))
(let ((prompt-promise (lpara:promise)))
(ffi-within-renderer-thread
*browser*
(lambda ()
(let ((prompt-buffer (apply #'make-instance 'prompt-buffer
(append args
(list
:window (current-window)
:result-channel (make-channel)
:interrupt-channel (make-channel))))))
(calispel:! prompt-object-channel prompt-buffer))))
(let ((new-prompt (calispel:? prompt-object-channel)))
(list :window (current-window))))))
(lpara:fulfill prompt-promise prompt-buffer))))
(let ((new-prompt (lpara:force prompt-promise)))
(wait-on-prompt-buffer new-prompt)))))

(export-always 'prompt1)
Expand Down
4 changes: 2 additions & 2 deletions source/renderer/gtk.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ the `active-buffer'."
:extra-modes 'nyxt/mode/file-manager:file-manager-mode
:sources (make-instance 'nyxt/mode/file-manager:file-source
:enable-marks-p multiple))
(prompt-buffer-canceled ()
(prompter:canceled ()
nil)))))
(if files
(webkit:webkit-file-chooser-request-select-files
Expand Down Expand Up @@ -1416,7 +1416,7 @@ the `active-buffer'."
:prompt (webkit:webkit-script-dialog-get-message dialog)
:input (webkit:webkit-script-dialog-prompt-get-default-text dialog)
:sources 'prompter:raw-source)
(prompt-buffer-canceled () nil)))))
(prompter:canceled () nil)))))
(if text
(webkit:webkit-script-dialog-prompt-set-text dialog text)
(progn
Expand Down

0 comments on commit 9f7dd06

Please sign in to comment.