Don't display the port in the url when it's the default - clic - Clic is an command line interactive client for gopher written in Common LISP HTML git clone git://bitreich.org/clic/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/clic/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit ce63b08d9802f2fe55117343a9211bd22bb7cdfc DIR parent aef4daefc84599c967d86e9bef2fb5a778f8b3f8 HTML Author: Solene Rapenne <solene@perso.pw> Date: Sun, 5 Nov 2017 14:03:02 +0000 Don't display the port in the url when it's the default Diffstat: M clic.lisp | 38 ++++++++++++++++++------------- 1 file changed, 22 insertions(+), 16 deletions(-) --- DIR diff --git a/clic.lisp b/clic.lisp @@ -6,11 +6,6 @@ (require 'sockets)) (defstruct location host port type uri) - -(defun color(num1 num2) - "generate string used to put ANSI color" - (format nil "~a[~a;~am" #\Escape num1 num2)) - (defparameter *links* (make-hash-table)) (defparameter *colors* (make-hash-table)) (defparameter *allowed-selectors* (list "0" "1" "2" "3" "4" "5" "6" "i" @@ -18,21 +13,25 @@ (defparameter *history* '()) ;; ANSI colors -(defun addcolor(name type hue) (setf (gethash name *colors*) (color type hue))) -(defun getcolor(name) (gethash name *colors*)) -(addcolor 'red 1 31) -(addcolor 'white 0 70) -(addcolor 'folder 4 34) -(addcolor 'green 1 32) -(addcolor 'file 0 33) -(addcolor 'cyan 0 46) +(defun add-color(name type hue) + "Storing a ANSI color string into *colors*" + (setf (gethash name *colors*) + (format nil "~a[~a;~am" #\Escape type hue))) + +(defun get-color(name) (gethash name *colors*)) +(add-color 'red 1 31) +(add-color 'white 0 70) +(add-color 'folder 4 34) +(add-color 'green 1 32) +(add-color 'file 0 33) +(add-color 'cyan 0 46) (defun print-with-color(text &optional (color 'white) (line-number nil)) "Used to display a line with a color" - (format t "~3A| ~a~a~a~%" (if line-number line-number "") (getcolor color) text (getcolor 'white))) + (format t "~3A| ~a~a~a~%" (if line-number line-number "") (get-color color) text (get-color 'white))) (defmacro check(identifier &body code) - "Syntax to make a when easier for formatted-output func" + "Syntax to make when easier for formatted-output func" `(progn (when (string= ,identifier line-type) ,@code))) (defun split(text separator) @@ -162,7 +161,14 @@ (formatted-output line line-number)) ((string= "0" type) (format t "~a~%" line)))))) - (format t "~aRequested gopher://~a:~a/~a~a~a~%" (getcolor 'cyan) host port type uri (getcolor 'white)))) + + (format t "~aRequested gopher://~a~a/~a~a~a~%" + (get-color 'cyan) + host + (if (= 70 port ) "" (concatenate 'string ":" (write-to-string port))) + type + uri + (get-color 'white)))) (defun visit(destination) "visit a location"