Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun read-one-line (screen prompt &key (initial-input "") require-match password)
- "Read a line of input through stumpwm and return it. returns nil if the user aborted."
- (let ((*input-last-command* nil)
- (input (make-input-line :string (make-input-string initial-input)
- :position (length initial-input)
- :history -1
- :password password)))
- (labels ((match-input ()
- (let* ((in (string-trim " " (input-line-string input)))
- (compls (input-find-completions in *input-completions*)))
- (and (consp compls)
- (string= in (car compls)))))
- (key-loop ()
- (loop for key = (read-key-or-selection) do
- (cond ((stringp key)
- ;; handle selection
- (input-insert-string input key)
- (draw-input-bucket screen prompt input))
- ;; skip modifiers
- ((is-modifier (car key)))
- ((process-input screen prompt input (car key) (cdr key))
- (if (or (not require-match)
- (match-input))
- (return (input-line-string input))
- (draw-input-bucket screen prompt input "[No match]" t)))))))
- (setup-input-window screen prompt input)
- (catch :abort
- (unwind-protect
- (with-focus (screen-input-window screen)
- (key-loop))
- (shutdown-input-window screen))))))
Advertisement
Add Comment
Please, Sign In to add comment