implement repl for new client structure

This commit is contained in:
2025-09-07 19:11:17 -07:00
parent 4ea51c0ed5
commit b0af59a316

View File

@@ -1,27 +1,51 @@
#lang racket #lang racket
(require (prefix-in client: "client.rkt")) (require (prefix-in net: "net.rkt")
(prefix-in client: "client.rkt"))
(define client (new client:client%)) (define client (new client:client%))
(define (repl) (define (repl)
(display "G-300 > ") (display "G-300 > ")
(let ([matches (regexp-match #px"(\\w+)\\s*(.*)" (read-line))]) (with-handlers
(cond ([(or/c exn:fail:user?
;; next command. also default ;; todo: catch these errors separately and reformat them
[(or (not matches) ;; in a user-y way
(string=? (cadr matches) "next") exn:fail:network?
(string=? (cadr matches) "n")) net:exn:fail:response?)
(λ (exn)
(displayln (exn-message exn)))])
(match (regexp-match #px"(\\w+)\\s*(.*)" (read-line))
[(or (list _ "go" url)
(list _ "g" url))
(send client go-cmd url)]
[(or (list _ "visit" id)
(list _ "v" id))
(send client visit-cmd (string->number id))]
[(or (list _ "next" _)
(list _ "n" _))
(send client next-cmd)] (send client next-cmd)]
;; go command [(or (list _ "url" id)
[(or (string=? (cadr matches) "go") (list _ "u" id))
(string=? (cadr matches) "g")) (send client url-cmd (string->number id))]
(send client go-cmd (caddr matches))]
;; visit link command [(or (list _ "url")
[(andmap char-numeric? (string->list (cadr matches))) (list _ "u"))
(send client visit-cmd (cadr matches))])) (send client url-cmd)]
[(list _ "up" _)
(send client up-cmd)]
[(or (list _ "back" _)
(list _ "b" _))
(send client back-cmd)]
[else
(displayln "no such command")]))
(repl)) (repl))