Guest User

Alessandro Piras

a guest
Apr 3rd, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.64 KB | None | 0 0
  1. (defun read-one-line (screen prompt &key (initial-input "") require-match password)
  2.   "Read a line of input through stumpwm and return it. returns nil if the user aborted."
  3.   (let ((*input-last-command* nil)
  4.         (input (make-input-line :string (make-input-string initial-input)
  5.                                 :position (length initial-input)
  6.                                 :history -1
  7.                                 :password password)))
  8.     (labels ((match-input ()
  9.                (let* ((in (string-trim " " (input-line-string input)))
  10.                       (compls (input-find-completions in *input-completions*)))
  11.                  (and (consp compls)
  12.                       (string= in (car compls)))))
  13.              (key-loop ()
  14.                (loop for key = (read-key-or-selection) do
  15.                      (cond ((stringp key)
  16.                             ;; handle selection
  17.                             (input-insert-string input key)
  18.                             (draw-input-bucket screen prompt input))
  19.                            ;; skip modifiers
  20.                            ((is-modifier (car key)))
  21.                            ((process-input screen prompt input (car key) (cdr key))
  22.                             (if (or (not require-match)
  23.                                     (match-input))
  24.                                 (return (input-line-string input))
  25.                                 (draw-input-bucket screen prompt input "[No match]" t)))))))
  26.       (setup-input-window screen prompt input)
  27.       (catch :abort
  28.         (unwind-protect
  29.              (with-focus (screen-input-window screen)
  30.                (key-loop))
  31.           (shutdown-input-window screen))))))
Advertisement
Add Comment
Please, Sign In to add comment