Add a history and a way to view it, we can go backward in the history too - 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 92b47b4e58d94657cf0e238e2cff77f01f0af1e1
(DIR) parent 52134391cf7ed0c1deaec32e0e8a7010b6c2a102
(HTM) Author: Solene Rapenne <solene@perso.pw>
Date: Sat, 4 Nov 2017 16:13:38 +0000
Add a history and a way to view it, we can go backward in the history too
Diffstat:
M README.md | 3 ++-
M clic.lisp | 45 +++++++++++++++++++++----------
2 files changed, 33 insertions(+), 15 deletions(-)
---
(DIR) diff --git a/README.md b/README.md
@@ -43,7 +43,8 @@ links. You can exit shell mode with **x**.
## Shell mode
- "a number" : follow the link "number"
-- p : display the latest page with links you have seen
+- p : previous page
+- h : display history
- x : quit shell mode
## Non shell-mode ##
(DIR) diff --git a/clic.lisp b/clic.lisp
@@ -5,7 +5,7 @@
#+ecl
(require 'sockets))
-(defstruct location host port uri type)
+(defstruct location host port type uri)
(defun color(num1 num2)
"generate string used to put ANSI color"
@@ -15,6 +15,7 @@
(defparameter *colors* (make-hash-table))
(defparameter *allowed-selectors* (list "0" "1" "2" "3" "4" "5" "6" "i"
"h" "7" "8" "9" "+" "T" "g" "I"))
+(defparameter *history* '())
;; ANSI colors
(defun addcolor(name type hue) (setf (gethash name *colors*) (color type hue)))
@@ -127,14 +128,17 @@
(defun getpage(host port uri &optional (type "1"))
"connect and display"
- ;; we reset the links table
- ;; ONLY if we have a new folder
- (when (string= "1" type)
- (setf *links* (make-hash-table))
-
- ;; here we store the location for using "previous" command
- (setf (gethash 0 *links*)
- (make-location :host host :port port :uri uri :type type)))
+ (let ((here (make-location :host host :port port :uri uri :type type)))
+
+ ;; goes to the history !
+ (push here *history*)
+
+ ;; we reset the links table ONLY if we have a new folder
+ ;; and we store the location for "previous" command
+ (when (string= "1" type)
+ (setf *links* (make-hash-table))
+ (setf (gethash 0 *links*) here)))
+
;; we prepare informations about the connection
(let* ((address (sb-bsd-sockets:get-host-by-name host))
@@ -162,13 +166,24 @@
(format t "~a~%" line))))))
(format t "~aRequested gopher://~a:~a/~a~a~a~%" (getcolor 'cyan) host port type uri (getcolor 'white)))
+(defun visit(destination)
+ "visit a location"
+ (getpage (location-host destination)
+ (location-port destination)
+ (location-uri destination)
+ (location-type destination)))
+
(defun g(key)
"browse to the N-th link"
(let ((destination (gethash key *links*)))
- (getpage (location-host destination)
- (location-port destination)
- (location-uri destination)
- (location-type destination))))
+ (when destination
+ (visit destination))))
+
+(defun p()
+ "browse to the previous link"
+ (when (<= 2 (length *history*))
+ (pop *history*)
+ (visit (pop *history*))))
(defun help()
"show help"
@@ -194,7 +209,9 @@
((string= "HELP" user-input)
(help-shell))
((string= "P" user-input)
- (g 0))
+ (p))
+ ((string= "H" user-input)
+ (format t "~{~a~%~}" *history*))
(t
(when user-input
(g (parse-integer user-input)))))