52 lines
1.2 KiB
Racket
52 lines
1.2 KiB
Racket
#lang racket
|
|
|
|
(require (prefix-in net: "net.rkt")
|
|
(prefix-in client: "client.rkt"))
|
|
|
|
(define client (new client:client%))
|
|
|
|
(define (repl)
|
|
(display "G-300 > ")
|
|
|
|
(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)]
|
|
|
|
[(or (list _ "url" id)
|
|
(list _ "u" id))
|
|
(send client url-cmd (string->number id))]
|
|
|
|
[(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))
|