3ecc82d75817

Make it actually do something useful
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 04 May 2018 21:45:28 -0400
parents 06972f89d220
children d0a70b561459
branches/tags (none)
files Makefile brows.asd src/main.lisp

Changes

--- a/Makefile	Thu May 03 23:42:55 2018 -0400
+++ b/Makefile	Fri May 04 21:45:28 2018 -0400
@@ -17,10 +17,10 @@
 	mkdir -p bin
 
 binary-sbcl: bin
-	sbcl --load "src/build.lisp"
+	/usr/local/bin/sbcl --noinform --load "src/build.lisp"
 
 binary-ccl: bin
-	ccl --load "src/build.lisp"
+	/usr/local/bin/ccl64 --load "src/build.lisp"
 
 binary: binary-sbcl
 
--- a/brows.asd	Thu May 03 23:42:55 2018 -0400
+++ b/brows.asd	Fri May 04 21:45:28 2018 -0400
@@ -9,6 +9,7 @@
                :boots
                :cl-ppcre
                :deploy
+               :external-program
                :iterate
                :losh
 
--- a/src/main.lisp	Thu May 03 23:42:55 2018 -0400
+++ b/src/main.lisp	Fri May 04 21:45:28 2018 -0400
@@ -1,7 +1,6 @@
 (in-package :brows)
 
 
-
 (defparameter *regex*
   (concatenate
     'string
@@ -9,12 +8,15 @@
     "[^ .,;\\t\\n\\r<\">\\):]?[^, <>\"\\t]*[^ .,;\\t\\n\\r<\">\\):]"))
 
 (defparameter *urls* nil)
+(defparameter *log* nil)
 (defparameter *pos* 0)
 
 
 (defun find-urls (string)
   (-<> string
-    (ppcre:all-matches-as-strings *regex* <> :sharedp t)
+    (ppcre:all-matches-as-strings
+      *regex* <>
+      :sharedp nil) ; ccl can't take non-simple-strings as external program args, because fuck me
     (remove-duplicates <> :test #'string-equal)
     (coerce <> 'vector)))
 
@@ -39,13 +41,27 @@
 (defun process-input (input)
   (find-urls input))
 
+(defun action-open (url)
+  (external-program:run "open" (list url)))
+
+(defun action-w3m (url)
+  (external-program:run "w3m" (list url) :output t :input t))
+
+(defun perform-action (action)
+  (charms/ll:endwin)
+  (funcall action (aref *urls* *pos*))
+  (boots:blit))
+
 (defun draw (canvas)
   (boots:clear canvas)
-  (iterate (for row :from 0 :below (boots:height canvas))
-           (for url :in-vector *urls*)
-           (when (= row *pos*)
-             (boots:draw canvas row 0 "-> "))
-           (boots:draw canvas row 3 url)))
+  (boots:draw canvas 0 0 (structural-string *log*))
+  (iterate
+    (with selected = (1+ *pos*))
+    (for row :from 1 :below (boots:height canvas))
+    (for url :in-vector *urls*)
+    (when (= row selected)
+      (boots:draw canvas row 0 "-> "))
+    (boots:draw canvas row 3 url)))
 
 (defun init ()
   (setf *urls* (-<> "-"
@@ -55,10 +71,14 @@
 (defun main ()
   (iterate
     (boots:blit)
-    (case (boots:read-event)
+    (for event = (boots:read-event))
+    (case event
+      (#\newline (perform-action #'action-open))
+      (#\w (perform-action #'action-w3m))
       ((#\Q #\q) (return-from main))
       ((#\k :up) (incf-pos -1))
-      ((#\j :down) (incf-pos 1)))))
+      ((#\j :down) (incf-pos 1))
+      (t (setf *log* event)))))
 
 (defmacro catch-and-spew-errors (&body body)
   `(handler-case (progn ,@body)