diff options
author | Abhiseck Paira <abhiseckpaira@disroot.org> | 2022-02-25 19:16:07 +0530 |
---|---|---|
committer | Abhiseck Paira <abhiseckpaira@disroot.org> | 2022-02-25 19:16:07 +0530 |
commit | 7a0d85b3f7c170ae930ea7ff5be948a6183ca513 (patch) | |
tree | ab34b7b58548fb419dce47a9f43132d365953699 | |
parent | 7ec5aea30e8ada9475e1199a084d468f0031002d (diff) |
auth: present auth code request in a nicer way
Instead of using the minibuffer prompt to present the explanation what
the user needs to do to get authorization code, use Emacs buffer and
Window. The minibuffer prompt should have 2-3 words.
This increases the readability of the explanation.
Of course delete explanation buffer and restore the window configuration
as it was after reading from minibuffer.
-rw-r--r-- | lisp/mastodon-auth.el | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 416e714..ebbe86c 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -85,13 +85,44 @@ if you are happy with unencryped storage use e.g. \"~/authinfo\"." "Login to your account (%s) and authorize \"mastodon.el\".\n" "Paste Authorization Code here: ") (mastodon-client-form-user-from-vars))) +(defun mastodon-auth--show-notice (notice buffer-name &optional ask) + "Display NOTICE to user. +NOTICE is displayed in vertical split occupying 50% of total +width. The buffer name of the buffer being displayed in the +window is BUFFER-NAME. + +When optional argument ASK is given which should be a string, use +ASK as the minibuffer prompt. Return whatever user types in +response to the prompt. + +When ASK is absent return nil." + (let ((buffer (get-buffer-create buffer-name)) + (inhibit-read-only t) + ask-value window) + (set-buffer buffer) + (erase-buffer) + (insert notice) + (fill-region (point-min) (point-max)) + (read-only-mode) + (setq window (select-window + (split-window (frame-root-window) nil 'left) + t)) + (switch-to-buffer buffer t) + (when ask + (setq ask-value (read-string ask)) + (kill-buffer buffer) + (delete-window window)) + ask-value)) (defun mastodon-auth--request-authorization-code () "Ask authorization code and return it." (let ((url (mastodon-auth--get-browser-login-url)) authorization-code) (kill-new url) - (setq authorization-code (read-string mastodon-auth--explanation)) + (setq authorization-code + (mastodon-auth--show-notice mastodon-auth--explanation + "*mastodon-notice*" + "Authorization Code: ")) authorization-code)) (defun mastodon-auth--generate-token () |