add Kiosk mode [currently ecl-only] - clic - Clic is an command line interactive client for gopher written in Common LISP
(HTM) git clone git://bitreich.org/clic/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/clic/
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
(DIR) LICENSE
---
(DIR) commit 63402005caf705a0707b910c66ed0f531d7b3d64
(DIR) parent 7d77950b670a06876d1c715ff5d1fc3efbddd5ae
(HTM) Author: solene <solene@t400.lan>
Date: Thu, 8 Feb 2018 10:08:25 +0100
add Kiosk mode [currently ecl-only]
Diffstat:
M clic.lisp | 76 +++++++++++++++++++------------
M make-binary.lisp | 2 +-
2 files changed, 49 insertions(+), 29 deletions(-)
---
(DIR) diff --git a/clic.lisp b/clic.lisp
@@ -41,6 +41,15 @@
(defstruct location host port type uri
:predicate)
+;;;; kiosk mode on/off
+(defparameter *kiosk-mode* nil)
+
+(defmacro kiosk-mode(&body code)
+ "prevent code if kiosk mode is enabled"
+ `(progn
+ (when (not *kiosk-mode*)
+ ,@code)))
+
;;;; BEGIN GLOBAL VARIABLES
;;; array of lines in buffer
@@ -261,7 +270,6 @@
(format stream "~a~a~a" uri #\Return #\Newline)
(force-output stream)
-
;; save into a file in /tmp
(let* ((filename (subseq uri (1+ (position #\/ uri :from-end t))))
(path (concatenate 'string "/tmp/" filename)))
@@ -318,8 +326,9 @@
(visit destination))
;; visit http link
((search "URL:" destination)
- (uiop:run-program (list "xdg-open"
- (subseq destination 4))))))))
+ (kiosk-mode
+ (uiop:run-program (list "xdg-open"
+ (subseq destination 4)))))))))
(defun filter-line(text)
"display only lines containg text"
@@ -334,7 +343,6 @@
do
(when (search text (car (split (subseq line 1) #\Tab)) :test #'char-equal)
(vector-push line *buffer*)))
-
(display-interactive-menu))
(defun load-file-menu(path)
@@ -449,6 +457,7 @@
;; exit
((or
(eql nil input)
+ (string= "NIL" input)
(string= "." input)
(string= "exit" input)
(string= "x" input)
@@ -468,15 +477,16 @@
(defun display-interactive-binary-file()
"call xdg-open on the binary file"
- (let* ((location (car *history*))
- (filename (subseq ;; get the text after last /
- (location-uri location)
- (1+ (position #\/
- (location-uri location)
- :from-end t))))
- (filepath (concatenate 'string "/tmp/" (or filename "index"))))
- (uiop:run-program (list "xdg-open" filepath))))
-
+ (kiosk-mode
+ (let* ((location (car *history*))
+ (filename (subseq ;; get the text after last /
+ (location-uri location)
+ (1+ (position #\/
+ (location-uri location)
+ :from-end t))))
+ (filepath (concatenate 'string "/tmp/" (or filename "index"))))
+ (uiop:run-program (list "xdg-open" filepath)))))
+
(defun display-text-stdout()
"display the buffer to stdout"
(foreach-buffer
@@ -496,6 +506,13 @@
:input :interactive
:output :interactive)))
+;; display a text file using the pager by piping
+;; the data to out, no temp file
+(defun display-with-pager-kiosk()
+ (loop for line across *buffer*
+ do
+ (format t "~a~%" line)))
+
(defun display-interactive-menu()
"display a menu"
;; we store the user input outside of the loop
@@ -605,9 +622,10 @@
;; if not type 0 1 7 then it's binary
(t
- (download-binary (location-host destination)
- (location-port destination)
- (location-uri destination))
+ (kiosk-mode
+ (download-binary (location-host destination)
+ (location-port destination)
+ (location-uri destination)))
'binary))))
@@ -624,20 +642,24 @@
(display-interactive-menu)
(progn
(if (eql type 'text)
- (display-with-pager)
- (display-interactive-binary-file))
- ;; redraw last menu
- ;; we need to get previous buffer and reset links numbering
- (pop *history*)
- (when *previous-buffer*
- (setf *buffer* (copy-array *previous-buffer*))
- (setf *links* (make-hash-table))
- (display-interactive-menu))))))
+ (if *kiosk-mode*
+ (display-with-pager-kiosk)
+ (display-with-pager))
+ (kiosk-mode (display-interactive-binary-file)))
+ ;; redraw last menu
+ ;; we need to get previous buffer and reset links numbering
+ (pop *history*)
+ (when (and
+ *previous-buffer*
+ (not *kiosk-mode*))
+ (setf *buffer* (copy-array *previous-buffer*))
+ (setf *links* (make-hash-table))
+ (display-interactive-menu))))))
(defun display-prompt()
(let ((last-page (car *history*)))
- (format t "gopher://~a:~a/~a~a (~as) / (P)rev (R)eload (H)istory : "
+ (format t "gopher://~a:~a/~a~a (~as) / (P)rev (R)edisplay (H)istory : "
(location-host last-page)
(location-port last-page)
(location-type last-page)
@@ -706,5 +728,3 @@
#+ecl
(defconstant +uri-rules+
'(("*DEFAULT*" 1 "" :stop)))
-
-
(DIR) diff --git a/make-binary.lisp b/make-binary.lisp
@@ -9,7 +9,7 @@
#+ecl
(progn
(compile-file "clic.lisp" :system-p t)
- (c:build-program "clic" :epilogue-code '(progn (main)) :lisp-files '("clic.o")))
+ (c:build-program "clic" :epilogue-code '(progn (handler-case (main) (condition () (quit)))) :lisp-files '("clic.o")))
#+sbcl
(progn
(require 'sb-bsd-sockets)