From c786466d6537ba4b10e46ee7a2ea5d5e0b236e40 Mon Sep 17 00:00:00 2001 From: w6vvn Date: Wed, 3 Sep 2025 21:16:32 -0700 Subject: [PATCH] totally redo the line interface, go and pagination commands --- gem300.rkt | 55 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/gem300.rkt b/gem300.rkt index d79ba7d..49084e8 100644 --- a/gem300.rkt +++ b/gem300.rkt @@ -3,22 +3,51 @@ (require (prefix-in net: "net.rkt") (prefix-in gmi: "gmi.rkt")) -(define commands - (list - (cons "default" (lambda (line) (void))))) +;; global state variable which will be an input port containing the +;; rendered out gemtext document as it shall be shown to the user +(define document-buffer null) -(define (dispatch-command line) - (let ([split (string-split line " ")]) +(define (go-cmd url) + (if (non-empty-string? url) + (let-values ([(status meta c-in) (net:get url)]) + (let-values ([(document) (gmi:parse (port->lines c-in))] + [(db-in db-out) (make-pipe #f)]) - (let ([cmd (assoc (cond [(null? split) "default"] - [else (first split)]) - commands)]) - (if cmd - ((cdr cmd) (string-join (cdr split))) - (displayln "no such command"))))) + (set! document-buffer db-in) + (parameterize ([current-output-port db-out]) + (gmi:render document)) + (let ([remaining (pipe-content-length db-in)]) + (printf "document retrieved. ~a bytes\n" remaining)) + + (next-cmd))) + + (displayln "go where?"))) + +(define (next-cmd) + (define (iter depth) + (when (> depth 0) + (let () + (displayln (read-line document-buffer)) + (iter (sub1 depth))))) + + (iter 10) + (newline) + (let ([remaining (pipe-content-length document-buffer)]) + (printf "~a bytes remaining\n" remaining))) (define (repl) - (display "G300> ") - (dispatch-command (read-line)) + (display "G-300 > ") + + (let ([matches (regexp-match #px"(\\w+)\\s*(.*)" (read-line))]) + (cond + ;; nothing was given. default command + [(not matches) + (next-cmd)] + + ;; go command + [(string=? (cadr matches) "go") + (go-cmd (caddr matches))])) + + (repl))