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
(require (prefix-in client: "client.rkt"))
(require (prefix-in net: "net.rkt")
(prefix-in client: "client.rkt"))
(define client (new client:client%))
(define (repl)
(display "G-300 > ")
(let ([matches (regexp-match #px"(\\w+)\\s*(.*)" (read-line))])
(cond
;; next command. also default
[(or (not matches)
(string=? (cadr matches) "next")
(string=? (cadr matches) "n"))
(with-handlers
([(or/c exn:fail:user?
;; todo: catch these errors separately and reformat them
;; in a user-y way
exn:fail:network?
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)]
;; go command
[(or (string=? (cadr matches) "go")
(string=? (cadr matches) "g"))
(send client go-cmd (caddr matches))]
[(or (list _ "url" id)
(list _ "u" id))
(send client url-cmd (string->number id))]
;; visit link command
[(andmap char-numeric? (string->list (cadr matches)))
(send client visit-cmd (cadr matches))]))
[(or (list _ "url")
(list _ "u"))
(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))