diff options
-rw-r--r-- | build-app.lisp | 52 | ||||
-rw-r--r-- | src/lib.lisp | 53 |
2 files changed, 68 insertions, 37 deletions
diff --git a/build-app.lisp b/build-app.lisp index 69338b1..3511a8c 100644 --- a/build-app.lisp +++ b/build-app.lisp @@ -61,9 +61,14 @@ you run the oneliner, all positional variables appear first. ;;; CLON SYNOPSIS DEFINITION -(defsynopsis (:postfix "[TAGS ...] | N [ARGS ...]") +(defsynopsis (:postfix "[ARGUMENTS ...]") + + (group (:header "SEARCH OPTIONS") - (text :contents "Return oneliners tagged with all of TAGS") + (text :contents "By default, ARGUMENTS are interpeted as search terms for oneliners. For example:") + (text :contents "$ ol grep awk # search for oneliners involving both grep and awk") + (text :contents " ") + (lispobj :long-name "limit" :argument-type :optional :argument-name "NUMBER" @@ -71,20 +76,29 @@ you run the oneliner, all positional variables appear first. :description "The maximum number of results to return." :typespec 'integer) (flag :long-name "all-flagged" - :description "Return flagged oneliners. Ignores TAGS. Respects --limit") + :description "Return flagged oneliners.") (flag :long-name "not-flagged" :description "Request that no flagged oneliners are returned.") (flag :long-name "newest" - :description "Return newest oneliners. Ignores TAGs. Respects --limit up to server specified maxiumum.")) + :description "Return newest oneliners.")) (text :contents " ") - (group (:header "ONELINER EXECUTION OPTIONS") - (text :contents "Runs the Nth search result with possible arguments ARGS.") - (flag :long-name "id" - :description "Refers a oneliner by its unique id instead of by result number.") + + + (group (:header "EXECUTION OPTIONS") + (text :contents "Several options override the default interpretation of ARGUMENTS.") + (text :contents "Execution options interpret the first argument as the identifier of a oneliner: ") + (text :contents "$ ol <EXECUTION OPTION> <NAME or ID> [MORE ARGUMENTS...]") + (text :contents " ") + + + (flag :long-name "run" + :description "Executes a oneliner by NAME or ID. See also help topic 'variables'.") (flag :long-name "clip" - :description "Put oneliner into clipboard instead of running it.") - (flag :long-name "clear-cache" - :description "Clears all cached search results from your system.") + :description "Like --run, but puts the oneliner into the clipboard.")) + (text :contents " ") + (group (:header "OTHER OPTIONS") + (flag :long-name "info" + :description "View all info the oneliner given by NAME or ID") (lispobj :long-name "timeout" :argument-type :optional :argument-name "SECONDS" @@ -93,15 +107,15 @@ you run the oneliner, all positional variables appear first. :description "How long to wait for standard output before giving up.")) (text :contents " ") (group (:header "HELP OPTIONS") - (flag :long-name "explain" - :description "View oneliner explaination text.") (flag :long-name "whois" - :description "View information about a contributor. ARGS is just a contributor handle.") - (enum :long-name "help" - :enum '(:account :wiki :invites :variables) - :argument-name "TOPIC" - :description "Print help for a topic. -Topics: wiki, account, invites, variables")) + :description "View information about a contributor. The first argument is a contributor handle.") + (flag :long-name "help" + :description "Print help for a topic. Topics: wiki, account, invites, variables")) + + (group (:header "Advanced Options" :hidden t) + (flag :long-name "clear-cache" + :description "Clears all cached search results from your system.")) + (group (:header "Variables" :hidden t) (text :contents +oneliners-variables-help-text+)) (group (:header "Wiki" :hidden t) diff --git a/src/lib.lisp b/src/lib.lisp index c77619c..1ddb103 100644 --- a/src/lib.lisp +++ b/src/lib.lisp @@ -520,28 +520,44 @@ the directories that appear in the value of that variable." (print results output)) (merge-into-cache results)) -(defun print-oneliner-result-for-user (number oneliner) - (dotimes (n 80) (princ #\_)) - (terpri) - (format t "~3a~a~a~a [~a] ~a" - number - (if (getf oneliner :isflagged) - "⚠" " ") - (if (getf oneliner :islocked) - "🔒" " ") - (if (equalp "manual" (getf oneliner :runstyle)) - "📋" " ") - (getf oneliner :id) - (getf oneliner :brief)) - (format t "~% by: ~12a tags: ~{~a~^ ~}" (getf oneliner :createdby) (getf oneliner :tags)) - (format t "~%~% ~a~%~%" (getf oneliner :oneliner))) +(defvar *term-width* 80) + +(defun set-term-width () + (setf *term-width* + (or (parse-integer (uiop:run-program '("tput" "cols") :output :string) :junk-allowed t) + 80))) + +(defun print-oneliner-result-for-user (oneliner) + (let* ((title-line-format-str + (concatenate 'string "~" (prin1-to-string *term-width*) "<[~a]~;~a~;~a~>~%")) + (tags-line-format-string + (concatenate 'string "~" (prin1-to-string *term-width*) "<~a~;by ~a~>~%"))) + (loop repeat *term-width* do (princ #\_)) + (terpri) + (format t title-line-format-str + (getf oneliner :id) + (or (getf oneliner :name) " ") + (format nil "~:[ ~;⚠~]~:[ ~;🔒~]~:[ ~;📋~]" + (getf oneliner :isflagged) + (getf oneliner :islocked) + (equalp "manual" (getf oneliner :runstyle)))) + (format t tags-line-format-string + (format nil "tags: ~{~a~^ ~}" + (getf oneliner :tags)) + (getf oneliner :createdby)) + (loop + with brief = (getf oneliner :brief) + for x from 0 to (length brief) by *term-width* + do (format t "~a~%" + (string-trim '(#\space) + (alexandria-2:subseq* brief x (+ x *term-width*))))) + (format t "~%~a~%~%" (getf oneliner :oneliner)))) (defun cache-and-print-search-response (response) (cache-search-results-to-last-search-file - (loop for number from 1 - for oneliner in (getf (jonathan:parse response) :oneliners) + (loop for oneliner in (getf (jonathan:parse response) :oneliners) collect oneliner - do (print-oneliner-result-for-user number oneliner)))) + do (print-oneliner-result-for-user oneliner)))) (defun newest-oneliners (&optional limit) (ensure-config) @@ -565,6 +581,7 @@ the directories that appear in the value of that variable." (defun search-for-oneliners (terms limit not-flagged-p) (assert (loop for term in terms never (find #\, term) )) + (set-term-width) (ensure-config) (let ((response (api:request-with |