# HG changeset patch # User Richard Westhaver # Date 1726981369 14400 # Node ID 4d8451fe54238d88fde8a98626ce7c073aeefa3a # Parent cc89b337384bdd725b841b2edf3e444d4752ba24 moved web to lib/web, added dat/css diff -r cc89b337384b -r 4d8451fe5423 lisp/bin/skel.lisp --- a/lisp/bin/skel.lisp Sat Sep 21 22:58:22 2024 -0400 +++ b/lisp/bin/skel.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -206,10 +206,20 @@ (required-argument 'name))) (defcmd skc-vc - (if *args* - (std/string:string-case ((car *args*) :default (skel-simple-error "invalid command")) - ("status" (skc-status nil nil))) - (skc-status nil *opts*))) + (let* ((sk (find-skelfile #P"." :load t)) + (vc (sk-vc-meta-kind (sk-vc sk)))) + (sb-ext:enable-debugger) + (with-open-stream (proc (process-output + (if-let ((cmd (pop *args*))) + (ecase vc + (:hg (run-hg-command cmd *args* :stream)) + (:git (run-git-command cmd *args* :stream))) + (sb-ext:run-program (case vc (:hg *hg-program*) (:git *git-program*)) + nil + :output :stream)))) + (loop for x = (read-line proc nil) + while x + do (println x))))) (defcmd skc-shell (sb-ext:enable-debugger) diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/dat/css.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/lib/dat/css.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -0,0 +1,17 @@ +;;; css.lisp --- Cascading Style Sheets + +;; https://www.w3.org/Style/CSS/ + +;;; Commentary: + +;; for a list of all properties refer to: https://www.w3.org/Style/CSS/all-properties.en.html + +;; for other web data: https://github.com/mdn/data/tree/main + +;;; Code: +(in-package :dat/css) + +;; SHEET ::= (BLOCK*) +;; BLOCK ::= (:BLOCK SELECTOR PROPERTY*) +;; SELECTOR ::= (string*) +;; PROPERTY ::= (:PROPERTY string string) diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/dat/pkg.lisp --- a/lisp/lib/dat/pkg.lisp Sat Sep 21 22:58:22 2024 -0400 +++ b/lisp/lib/dat/pkg.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -115,6 +115,19 @@ #:+decode-table+ #:+uri-decode-table+)) +(defpackage :dat/css + (:use :cl :std :dat/proto) + (:export + :parse-css + :*minify-css* + :*css-indent-offset* + :parse-css-selector + :parse-css-fragment + :generate-css + :compile-css-selector + :compile-css + :compile-css-block)) + (defpackage :dat/html (:use :cl :std :dat/proto) (:import-from :sb-ext :defglobal) diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/net/condition.lisp --- a/lisp/lib/net/condition.lisp Sat Sep 21 22:58:22 2024 -0400 +++ b/lisp/lib/net/condition.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -10,9 +10,10 @@ (define-condition protocol-condition (net-condition) ()) (define-condition net-error (net-condition std-error) ()) - +(define-condition net-warning (net-condition std-warning) ()) (define-condition codec-error (codec-condition net-error) ()) +(define-condition codec-warning (codec-condition net-warning) ()) +(define-condition protocol-warning (protocol-condition net-warning) ()) (define-condition protocol-error (protocol-condition net-error) ()) - ;; sb-bsd-sockets:socket-error ;; sb-thread:thread-error diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/net/pkg.lisp --- a/lisp/lib/net/pkg.lisp Sat Sep 21 22:58:22 2024 -0400 +++ b/lisp/lib/net/pkg.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -16,7 +16,10 @@ :server :peer :proxy - :tunnel)) + :tunnel + :net-warning + :codec-warning + :protocol-warning)) (defpackage :net/util (:use :cl :obj :dat/proto :std :log :net/core :sb-bsd-sockets) diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/net/proto/http.lisp --- a/lisp/lib/net/proto/http.lisp Sat Sep 21 22:58:22 2024 -0400 +++ b/lisp/lib/net/proto/http.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -60,7 +60,6 @@ (lambda (condition stream) (format stream "~A: ~A" (type-of condition) (slot-value condition 'description))))) - ;; ;; Callback-related errors diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/skel/core/print.lisp --- a/lisp/lib/skel/core/print.lisp Sat Sep 21 22:58:22 2024 -0400 +++ b/lisp/lib/skel/core/print.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -24,15 +24,21 @@ (sb-ext:defglobal *sk-print-dispatch-table* (sb-pretty::make-pprint-dispatch-table #() nil nil)) -(defmethod sk-print ((self skel) &key (stream t) (id t) &allow-other-keys) +(defmethod sk-print ((self skel) &key (stream t) (id t) exclude &allow-other-keys) (if id (format stream "~S ~A~%" (keywordicate (class-name (class-of self))) (format-sxhash (obj/id:id self))) (format stream "~S~%" (keywordicate (class-name (class-of self))))) - (mapcar + (mapcar (lambda (slot) (let ((name (sb-mop:slot-definition-name slot))) (when (slot-boundp self name) (when-let ((val (slot-value self name))) - (format stream ":~A ~A~%" name val))))) - (sb-mop:class-direct-slots (class-of self))) + (typecase val + (sequence (unless (sequence:emptyp val) (format stream ":~A ~A~%" name val))) + (hash-table (unless (zerop (hash-table-count val)) + (format stream ":~A~%" name) + (pprint-tabular stream (hash-table-alist val) nil nil 2) + (terpri stream))) + (t (format stream ":~A ~A~%" name val))))))) + (remove-if (lambda (x) (member x exclude)) (sb-mop:class-direct-slots (class-of self)))) self) diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/web/dash.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/lib/web/dash.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -0,0 +1,31 @@ +;;; web/dash.lisp --- local user dashboard + +;;; Code: +(uiop:define-package :web/dash + (:use :cl :std #+nil :lass #+nil :spinneret :cli/clap) + ;; (:import-from :clack :clackup) + (:export + :main + :serve-static-assets + :*web-dash-port*)) + +(in-package :web/dash) + +(defparameter *web-dash-port* 8800) +(defparameter *web-dash-static-directory* #P"/tmp/web/dash/static/") + +(defvar *server*) + +(defun main (&key (output *standard-output*) (port *web-dash-port*)) + (let ((*standard-output* output)) + (print "starting dash server on ~A" port) + (handler-case (sb-thread:join-thread (find-if (lambda (th) + (search "hunchentoot" (sb-thread:thread-name th))) + (sb-thread:list-all-threads))) + ;; Catch a user's C-c + (#+sbcl sb-sys:interactive-interrupt + () (progn + (format *error-output* "Aborting.~&") + ;; (clack:stop *server*) + (uiop:quit))) + (error (c) (format t "Woops, an unknown error occured:~&~a~&" c))))) diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/web/index.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/lib/web/index.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -0,0 +1,89 @@ +;;; web/index.lisp --- local user index + +;;; Code: +(uiop:define-package :web/index + (:use :cl :std :hunchentoot :lass :spinneret) + (:export + :main + :*web-index-port*)) + +(in-package :web/index) + +(defparameter *last-update* (get-universal-time)) + +(defun current-time () (setq *last-update* (get-universal-time))) + +(defparameter *web-index-port* 8888) + +(defparameter *server* + (make-instance 'easy-acceptor + :port 8888 + :name "index")) + +(define-easy-handler (b :uri "/b") (user) + (setf (content-type*) "text/plain") + (format nil "showing buffers for ~@[ ~A~]." user)) + +(define-easy-handler (i :uri "/i") (user) + (setf (content-type*) "text/plain") + (format nil "showing inbox for ~@[ ~A~]." user)) + +(define-easy-handler (a :uri "/a") (user) + (setf (content-type*) "text/plain") + (format nil "showing agenda for ~@[ ~A~]." user)) + +(define-easy-handler (org :uri "/org") (user) + (setf (content-type*) "text/plain") + (format nil "showing org-files for ~@[ ~A~]." user)) + +(deftag link (link body) + `(:a :href ,@link ,@body)) + +(defmacro with-index-page (&optional (title "local index") &body body) + `(with-html + (:doctype) + (:html + (:head + (:title ,title) + (:body + (:div :class "nav" + "( " + (link "https://compiler.company" "~") + (link "https://compiler.company/blog" "blog") + (link "https://compiler.company/docs" "docs") + (link "https://compiler.company/code" "code") + " )") + ,@body + (:footer ("Last update: ~A" (current-time)))))))) + + (defun tabulate (&rest rows) + (with-html + (flet ((tabulate () + (loop for row in rows do + (:tr (loop for cell in row do + (:td cell)))))) + (if (find :table (get-html-path)) + (tabulate) + (:table (:tbody (tabulate))))))) + +(defun inner-section () + "Binds *HTML-PATH* to replicate the depth the output is used in." + (with-html-string + (let ((*html-path* (append *html-path* '(:section :section)))) + (:h* "Heading three levels deep")))) + +(defun outer-section (html) + "Uses HTML from elsewhere and embed it into a section" + (with-html-string + (:section + (:h* "Heading two levels deep") + (:section + (:raw html))))) + +(defun main (&key (output *standard-output*) (port *web-index-port*)) + (let ((*standard-output* output)) + (print "starting index server on ~A" port) + (start *server*))) + +(defun shutdown (&optional (target *server*)) + (stop target)) diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/web/pkg.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/lib/web/pkg.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -0,0 +1,7 @@ +;;; pkg.lisp --- Web Library + +;; + +;;; Code: +(defpackage :web/sys + (:use :cl :std)) diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/web/tests.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/lib/web/tests.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -0,0 +1,10 @@ +;;; tests.lisp --- Web Tests + +;; + +;;; Code: +(defpackage :web/tests + (:use :cl :std :rt :web/wasm/binary :web/wasm/text :web/sys)) +(in-package :web/tests) +(defsuite :web) +(in-suite :web) diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/web/wasm/binary.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/lib/web/wasm/binary.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -0,0 +1,6 @@ +;;; binary.lisp --- Wasm Binary Format + +;; https://webassembly.github.io/spec/core/binary/index.html + +;;; Code: +(in-package :web/wasm/binary) diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/web/wasm/pkg.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/lib/web/wasm/pkg.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -0,0 +1,13 @@ +;;; pkg.lisp --- Wasm Packages + +;; https://webassembly.github.io/spec/ + +;;; Code: +(defpackage :web/wasm/text + (:use :cl :std :dat/proto :dat/sxp)) + +(defpackage :web/wasm/binary + (:use :cl :std :dat/proto)) + +;; (defpackage :web/wasm/vm +;; (:use :cl :std :web/sys :web/wasm/binary)) diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/web/wasm/text.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/lib/web/wasm/text.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -0,0 +1,6 @@ +;;; text.lisp --- WASM Text (S-Expr) + +;; https://webassembly.github.io/spec/core/text/index.html + +;;; Code: +(in-package :web/wasm/text) diff -r cc89b337384b -r 4d8451fe5423 lisp/lib/web/web.asd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/lib/web/web.asd Sun Sep 22 01:02:49 2024 -0400 @@ -0,0 +1,30 @@ +(defsystem :web + :depends-on (:std :net :obj :dat :parse :doc :organ :syn :cry :nlp) + :components ((:file "pkg") + (:module "wasm" + :components + ((:file "pkg") + (:file "text") + (:file "binary")))) + :in-order-to ((test-op (test-op "web/tests")))) + +(defsystem :web/tests + :depends-on (:rt :net :web) + :components ((:file "tests")) + :perform (test-op (o c) (symbol-call :rt :do-tests :web))) + +(defsystem :web/index + :depends-on (:uiop :cl-ppcre :std :rdb :hunchentoot :parenscript :lass :spinneret :organ) + :components ((:file "index")) + :in-order-to ((test-op (test-op "web/tests"))) + :build-operation "program-op" + :build-pathname "web-index" + :entry-point "web/index::main") + +(defsystem :web/dash + :depends-on (:uiop :cl-ppcre :std :rdb :parenscript :lass :spinneret :organ) + :components ((:file "dash")) + :in-order-to ((test-op (test-op "web/tests"))) + :build-operation "program-op" + :build-pathname "web-dash" + :entry-point "web/dash::main") diff -r cc89b337384b -r 4d8451fe5423 lisp/std/pkg.lisp --- a/lisp/std/pkg.lisp Sat Sep 21 22:58:22 2024 -0400 +++ b/lisp/std/pkg.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -269,6 +269,7 @@ (:import-from :std/list :flatten) (:use-reexport :sb-thread) (:export + :std-thread-error :print-top-level :thread-support-p :find-thread-by-id :thread-id-list :timed-join-thread :kill-thread diff -r cc89b337384b -r 4d8451fe5423 lisp/std/thread.lisp --- a/lisp/std/thread.lisp Sat Sep 21 22:58:22 2024 -0400 +++ b/lisp/std/thread.lisp Sun Sep 22 01:02:49 2024 -0400 @@ -12,6 +12,9 @@ ;; (sb-thread:thread-os-tid sb-thread:*current-thread*) ;; sb-thread:interrupt-thread +;;; Conditions +(define-condition std-thread-error (thread-error) ()) + ;;; Utils (defun thread-support-p () (member :thread-support *features*)) diff -r cc89b337384b -r 4d8451fe5423 lisp/user.asd --- a/lisp/user.asd Sat Sep 21 22:58:22 2024 -0400 +++ b/lisp/user.asd Sun Sep 22 01:02:49 2024 -0400 @@ -5,7 +5,8 @@ :packy :parse :pod :rdb :krypt :gui :aud :net :krypt :rt :vc :dat - :q :box :log :gui) + :q :box :log :gui + :web) :components ((:file "user")) :build-operation monolithic-compile-bundle-op :build-pathname "user") diff -r cc89b337384b -r 4d8451fe5423 lisp/web/dash.lisp --- a/lisp/web/dash.lisp Sat Sep 21 22:58:22 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -;;; web/dash.lisp --- local user dashboard - -;;; Code: -(uiop:define-package :web/dash - (:use :cl :std #+nil :lass #+nil :spinneret :cli/clap) - ;; (:import-from :clack :clackup) - (:export - :main - :serve-static-assets - :*web-dash-port*)) - -(in-package :web/dash) - -(defparameter *web-dash-port* 8800) -(defparameter *web-dash-static-directory* #P"/tmp/web/dash/static/") - -(defvar *server*) - -(defun main (&key (output *standard-output*) (port *web-dash-port*)) - (let ((*standard-output* output)) - (print "starting dash server on ~A" port) - (handler-case (sb-thread:join-thread (find-if (lambda (th) - (search "hunchentoot" (sb-thread:thread-name th))) - (sb-thread:list-all-threads))) - ;; Catch a user's C-c - (#+sbcl sb-sys:interactive-interrupt - () (progn - (format *error-output* "Aborting.~&") - ;; (clack:stop *server*) - (uiop:quit))) - (error (c) (format t "Woops, an unknown error occured:~&~a~&" c))))) diff -r cc89b337384b -r 4d8451fe5423 lisp/web/index.lisp --- a/lisp/web/index.lisp Sat Sep 21 22:58:22 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -;;; web/index.lisp --- local user index - -;;; Code: -(uiop:define-package :web/index - (:use :cl :std :hunchentoot :lass :spinneret) - (:export - :main - :*web-index-port*)) - -(in-package :web/index) - -(defparameter *last-update* (get-universal-time)) - -(defun current-time () (setq *last-update* (get-universal-time))) - -(defparameter *web-index-port* 8888) - -(defparameter *server* - (make-instance 'easy-acceptor - :port 8888 - :name "index")) - -(define-easy-handler (b :uri "/b") (user) - (setf (content-type*) "text/plain") - (format nil "showing buffers for ~@[ ~A~]." user)) - -(define-easy-handler (i :uri "/i") (user) - (setf (content-type*) "text/plain") - (format nil "showing inbox for ~@[ ~A~]." user)) - -(define-easy-handler (a :uri "/a") (user) - (setf (content-type*) "text/plain") - (format nil "showing agenda for ~@[ ~A~]." user)) - -(define-easy-handler (org :uri "/org") (user) - (setf (content-type*) "text/plain") - (format nil "showing org-files for ~@[ ~A~]." user)) - -(deftag link (link body) - `(:a :href ,@link ,@body)) - -(defmacro with-index-page (&optional (title "local index") &body body) - `(with-html - (:doctype) - (:html - (:head - (:title ,title) - (:body - (:div :class "nav" - "( " - (link "https://compiler.company" "~") - (link "https://compiler.company/blog" "blog") - (link "https://compiler.company/docs" "docs") - (link "https://compiler.company/code" "code") - " )") - ,@body - (:footer ("Last update: ~A" (current-time)))))))) - - (defun tabulate (&rest rows) - (with-html - (flet ((tabulate () - (loop for row in rows do - (:tr (loop for cell in row do - (:td cell)))))) - (if (find :table (get-html-path)) - (tabulate) - (:table (:tbody (tabulate))))))) - -(defun inner-section () - "Binds *HTML-PATH* to replicate the depth the output is used in." - (with-html-string - (let ((*html-path* (append *html-path* '(:section :section)))) - (:h* "Heading three levels deep")))) - -(defun outer-section (html) - "Uses HTML from elsewhere and embed it into a section" - (with-html-string - (:section - (:h* "Heading two levels deep") - (:section - (:raw html))))) - -(defun main (&key (output *standard-output*) (port *web-index-port*)) - (let ((*standard-output* output)) - (print "starting index server on ~A" port) - (start *server*))) - -(defun shutdown (&optional (target *server*)) - (stop target)) diff -r cc89b337384b -r 4d8451fe5423 lisp/web/web.asd --- a/lisp/web/web.asd Sat Sep 21 22:58:22 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -(defsystem :web/index - :depends-on (:uiop :cl-ppcre :std :rdb :hunchentoot :parenscript :lass :spinneret :organ) - :components ((:file "index")) - :in-order-to ((test-op (test-op "app/tests"))) - :build-operation "program-op" - :build-pathname "web-index" - :entry-point "web/index::main") - -(defsystem :web/dash - :depends-on (:uiop :cl-ppcre :std :rdb :parenscript :lass :spinneret :organ) - :components ((:file "dash")) - :in-order-to ((test-op (test-op "app/tests"))) - :build-operation "program-op" - :build-pathname "web-dash" - :entry-point "web/dash::main") - -(defsystem :web - :depends-on (:web/dash :web/index))