aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaiki Ueno2015-08-19 11:38:32 +0900
committerDaiki Ueno2015-08-19 11:39:03 +0900
commit93fb1783a98ca31046f551ba1d33d67aa01e58b7 (patch)
tree0e1ac0dbe6c5c5033e942bb26e162c466b7a7514
parentaab8326b28f460a47f0a073612a8c8f9e9d8ec2f (diff)
downloademacs-93fb1783a98ca31046f551ba1d33d67aa01e58b7.tar.gz
emacs-93fb1783a98ca31046f551ba1d33d67aa01e58b7.zip
pinentry.el: Improve multiline prompt
* lisp/net/pinentry.el (pinentry--prompt): Simplify the interface. (pinentry--process-filter): Use `pinentry--prompt' for CONFIRM command.
-rw-r--r--lisp/net/pinentry.el128
1 files changed, 58 insertions, 70 deletions
diff --git a/lisp/net/pinentry.el b/lisp/net/pinentry.el
index 13a15c964ab..d7161bbf44d 100644
--- a/lisp/net/pinentry.el
+++ b/lisp/net/pinentry.el
@@ -108,9 +108,18 @@ If local sockets are not supported, this is nil.")
108 (setq truncate-lines t 108 (setq truncate-lines t
109 buffer-read-only t)) 109 buffer-read-only t))
110 110
111(defun pinentry--prompt (prompt short-prompt query-function &rest query-args) 111(defun pinentry--prompt (labels query-function &rest query-args)
112 (if (and (string-match "\n" prompt) 112 (let ((desc (cdr (assq 'desc labels)))
113 pinentry-popup-prompt-window) 113 (error (cdr (assq 'error labels)))
114 (prompt (cdr (assq 'prompt labels))))
115 (when (string-match "[ \n]*\\'" prompt)
116 (setq prompt (concat
117 (substring
118 prompt 0 (match-beginning 0)) " ")))
119 (when error
120 (setq desc (concat "Error: " (propertize error 'face 'error)
121 "\n" desc)))
122 (if (and desc pinentry-popup-prompt-window)
114 (save-window-excursion 123 (save-window-excursion
115 (delete-other-windows) 124 (delete-other-windows)
116 (unless (and pinentry--prompt-buffer 125 (unless (and pinentry--prompt-buffer
@@ -122,7 +131,7 @@ If local sockets are not supported, this is nil.")
122 (let ((inhibit-read-only t) 131 (let ((inhibit-read-only t)
123 buffer-read-only) 132 buffer-read-only)
124 (erase-buffer) 133 (erase-buffer)
125 (insert prompt)) 134 (insert desc))
126 (pinentry-prompt-mode) 135 (pinentry-prompt-mode)
127 (goto-char (point-min))) 136 (goto-char (point-min)))
128 (if (> (window-height) 137 (if (> (window-height)
@@ -135,13 +144,9 @@ If local sockets are not supported, this is nil.")
135 (if (> (window-height) pinentry-prompt-window-height) 144 (if (> (window-height) pinentry-prompt-window-height)
136 (shrink-window (- (window-height) 145 (shrink-window (- (window-height)
137 pinentry-prompt-window-height)))) 146 pinentry-prompt-window-height))))
138 (prog1 (apply query-function short-prompt query-args) 147 (prog1 (apply query-function prompt query-args)
139 (quit-window))) 148 (quit-window)))
140 (apply query-function 149 (apply query-function (concat desc "\n" prompt) query-args))))
141 ;; Append a suffix to the prompt, which can be derived from
142 ;; SHORT-PROMPT.
143 (concat prompt (substring short-prompt -2))
144 query-args)))
145 150
146;;;###autoload 151;;;###autoload
147(defun pinentry-start () 152(defun pinentry-start ()
@@ -312,29 +317,15 @@ Assuan protocol."
312 (ignore-errors 317 (ignore-errors
313 (process-send-string process "OK\n"))) 318 (process-send-string process "OK\n")))
314 ("GETPIN" 319 ("GETPIN"
315 (let ((prompt 320 (let ((confirm (not (null (assq 'repeat pinentry--labels))))
316 (or (cdr (assq 'desc pinentry--labels)) 321 passphrase escaped-passphrase encoded-passphrase)
317 (cdr (assq 'prompt pinentry--labels)) 322 (unwind-protect
318 "")) 323 (condition-case err
319 (confirm (not (null (assq 'repeat pinentry--labels)))) 324 (progn
320 entry) 325 (setq passphrase
321 (if (setq entry (assq 'error pinentry--labels)) 326 (pinentry--prompt
322 (setq prompt (concat "Error: " 327 pinentry--labels
323 (propertize 328 #'read-passwd confirm))
324 (copy-sequence (cdr entry))
325 'face 'error)
326 "\n"
327 prompt)))
328 (if (setq entry (assq 'title pinentry--labels))
329 (setq prompt (format "[%s] %s"
330 (cdr entry) prompt)))
331 (let (passphrase escaped-passphrase encoded-passphrase)
332 (unwind-protect
333 (condition-case nil
334 (progn
335 (setq passphrase
336 (pinentry--prompt prompt "Password: "
337 #'read-passwd confirm))
338 (setq escaped-passphrase 329 (setq escaped-passphrase
339 (pinentry--escape-string 330 (pinentry--escape-string
340 passphrase)) 331 passphrase))
@@ -345,7 +336,8 @@ Assuan protocol."
345 (pinentry--send-data 336 (pinentry--send-data
346 process encoded-passphrase) 337 process encoded-passphrase)
347 (process-send-string process "OK\n"))) 338 (process-send-string process "OK\n")))
348 (error 339 (error
340 (message "GETPIN error %S" err)
349 (ignore-errors 341 (ignore-errors
350 (pinentry--send-error 342 (pinentry--send-error
351 process 343 process
@@ -356,59 +348,55 @@ Assuan protocol."
356 (clear-string escaped-passphrase)) 348 (clear-string escaped-passphrase))
357 (if encoded-passphrase 349 (if encoded-passphrase
358 (clear-string encoded-passphrase)))) 350 (clear-string encoded-passphrase))))
359 (setq pinentry--labels nil))) 351 (setq pinentry--labels nil))
360 ("CONFIRM" 352 ("CONFIRM"
361 (let ((prompt 353 (let ((prompt
362 (or (cdr (assq 'desc pinentry--labels)) 354 (or (cdr (assq 'prompt pinentry--labels))
363 "")) 355 "Confirm? "))
364 (buttons 356 (buttons
365 (pinentry--labels-to-shortcuts 357 (delq nil
366 (list (cdr (assq 'ok pinentry--labels)) 358 (pinentry--labels-to-shortcuts
367 (cdr (assq 'notok pinentry--labels)) 359 (list (cdr (assq 'ok pinentry--labels))
368 (cdr (assq 'cancel pinentry--labels))))) 360 (cdr (assq 'notok pinentry--labels))
361 (cdr (assq 'cancel pinentry--labels))))))
369 entry) 362 entry)
370 (if (setq entry (assq 'error pinentry--labels)) 363 (if buttons
371 (setq prompt (concat "Error: "
372 (propertize
373 (copy-sequence (cdr entry))
374 'face 'error)
375 "\n"
376 prompt)))
377 (if (setq entry (assq 'title pinentry--labels))
378 (setq prompt (format "[%s] %s"
379 (cdr entry) prompt)))
380 (if (remq nil buttons)
381 (progn 364 (progn
382 (setq prompt 365 (setq prompt
383 (concat prompt " (" 366 (concat prompt " ("
384 (mapconcat #'cdr (remq nil buttons) 367 (mapconcat #'cdr buttons
385 ", ") 368 ", ")
386 ") ")) 369 ") "))
370 (if (setq entry (assq 'prompt pinentry--labels))
371 (setcdr entry prompt)
372 (setq pinentry--labels (cons (cons 'prompt prompt)
373 pinentry--labels)))
387 (condition-case nil 374 (condition-case nil
388 (let ((result (read-char prompt))) 375 (let ((result (pinentry--prompt pinentry--labels
376 #'read-char)))
389 (if (eq result (caar buttons)) 377 (if (eq result (caar buttons))
390 (ignore-errors 378 (ignore-errors
391 (process-send-string process "OK\n")) 379 (process-send-string process "OK\n"))
392 (if (eq result (car (nth 1 buttons))) 380 (if (eq result (car (nth 1 buttons)))
393 (ignore-errors 381 (ignore-errors
394 (pinentry--send-error 382 (pinentry--send-error
395 process 383 process
396 pinentry--error-not-confirmed)) 384 pinentry--error-not-confirmed))
397 (ignore-errors 385 (ignore-errors
398 (pinentry--send-error 386 (pinentry--send-error
399 process 387 process
400 pinentry--error-cancelled))))) 388 pinentry--error-cancelled)))))
401 (error 389 (error
402 (ignore-errors 390 (ignore-errors
403 (pinentry--send-error 391 (pinentry--send-error
404 process 392 process
405 pinentry--error-cancelled))))) 393 pinentry--error-cancelled)))))
406 (if (string-match "[ \n]*\\'" prompt) 394 (if (setq entry (assq 'prompt pinentry--labels))
407 (setq prompt (concat 395 (setcdr entry prompt)
408 (substring 396 (setq pinentry--labels (cons (cons 'prompt prompt)
409 prompt 0 (match-beginning 0)) " "))) 397 pinentry--labels)))
410 (if (condition-case nil 398 (if (condition-case nil
411 (pinentry--prompt prompt "Confirm? " #'y-or-n-p) 399 (pinentry--prompt pinentry--labels #'y-or-n-p)
412 (quit)) 400 (quit))
413 (ignore-errors 401 (ignore-errors
414 (process-send-string process "OK\n")) 402 (process-send-string process "OK\n"))