# HG changeset patch # User Steve Losh # Date 1586827784 14400 # Node ID f592e6093609ed87d89798f13d2ac187fad24491 # Parent 1d2776f7fa4a369c3adef135ca459d6d06cd0278# Parent da80130c3bbf8b9ffd5a587dbf1ebee61853e761 Merge. diff -r 1d2776f7fa4a -r f592e6093609 Makefile diff -r 1d2776f7fa4a -r f592e6093609 brows.asd --- a/brows.asd Mon Apr 13 21:23:33 2020 -0400 +++ b/brows.asd Mon Apr 13 21:29:44 2020 -0400 @@ -8,6 +8,7 @@ :depends-on ( + :adopt :boots :cl-ppcre :external-program diff -r 1d2776f7fa4a -r f592e6093609 src/build.lisp --- a/src/build.lisp Mon Apr 13 21:23:33 2020 -0400 +++ b/src/build.lisp Mon Apr 13 21:29:44 2020 -0400 @@ -1,4 +1,7 @@ -(ql:quickload :brows) +(ql:quickload :brows :silent t) + +(with-open-file (stream "bin/brows.1" :direction :output :if-exists :supersede) + (adopt:print-manual brows::*ui* :stream stream)) #+sbcl (progn diff -r 1d2776f7fa4a -r f592e6093609 src/main.lisp --- a/src/main.lisp Mon Apr 13 21:23:33 2020 -0400 +++ b/src/main.lisp Mon Apr 13 21:29:44 2020 -0400 @@ -108,17 +108,42 @@ ((#\j :down) (incf-pos 1)) (t nil))))) -(defmacro catch-and-spew-errors (&body body) - `(handler-case (progn ,@body) - (t (c) (format t "Error: ~A" c)))) +(defun run () + (catch 'done + (with-open-file (input "/dev/tty" :direction :input) + (with-open-file (output "/dev/tty" :direction :output :if-exists :append) + (boots/terminals/ansi:with-ansi-terminal (terminal :input-stream input :output-stream output) + (boots:with-screen (screen terminal :root (boots:make-canvas :draw #'draw)) + (init) + (main))))))) + + +;;;; CLI ---------------------------------------------------------------------- +(adopt:define-string *documentation* + "Brows is a utility for finding links in a chunk of text and presenting a ~ + nice text-based UI for opening them. It's written (and customizable) in ~ + Common Lisp.") + +(defparameter *ui* + (adopt:make-interface + :name "brows" + :usage "[OPTIONS]" + :summary "Find links and present a menu for opening them in a browser." + :help *documentation* + :examples '(("Present a menu for opening some links:" . + "curl http://stevelosh.com/ | brows")) + :contents (list (adopt:make-option 'help + :help "Display help and exit." + :long "help" + :short #\h + :reduce (constantly t))))) (defun toplevel () - (catch-and-spew-errors - (catch 'done - (with-open-file (input "/dev/tty" :direction :input) - (with-open-file (output "/dev/tty" :direction :output :if-exists :append) - (boots/terminals/ansi:with-ansi-terminal (terminal :input-stream input :output-stream output) - (boots:with-screen (screen terminal :root (boots:make-canvas :draw #'draw)) - (init) - (main)))))))) - + (handler-case + (multiple-value-bind (arguments options) (adopt:parse-options *ui*) + (when (gethash 'help options) + (adopt:print-help-and-exit *ui*)) + (when arguments + (error "Unrecognized command line arguments: ~S" arguments)) + (run)) + (error (c) (adopt:print-error-and-exit c))))