Adding ui of chat, untested
This commit is contained in:
parent
476f0a3a7c
commit
6189ac719a
|
@ -15,15 +15,9 @@
|
|||
#:use-module (ice-9 suspendable-ports)
|
||||
#:export (say))
|
||||
|
||||
;; ;; https://www.gnu.org/software/guile/manual/guile.html#Non_002dBlocking-I_002fO
|
||||
;; (let* ((input (current-input-port))
|
||||
;; (flags (fcntl input F_GETFL)))
|
||||
;; (fcntl input F_SETFL (logior O_NONBLOCK flags)))
|
||||
;; (install-suspendable-ports!)
|
||||
|
||||
|
||||
(define ocapn-registry #f)
|
||||
(define listener-actor #f)
|
||||
(define room-actor #f)
|
||||
|
||||
(define (is-command? str)
|
||||
(and (> (string-length str) 0) (eq? (string-ref str 0) #\/)))
|
||||
|
@ -47,24 +41,40 @@
|
|||
(λ (args)
|
||||
(print-help)
|
||||
(loop! #t)))
|
||||
(make-console-command
|
||||
"/create"
|
||||
"- Create a new chat and join it."
|
||||
(λ (args)
|
||||
(define my-presence (spawn ^room-presence "user"))
|
||||
(set! room-actor (spawn ^room my-presence))
|
||||
(format #t "Room ID: ~a\n" ($ ocapn-registry 'register room))
|
||||
(loop! #t)))
|
||||
(make-console-command
|
||||
"/me"
|
||||
"<text> - Me command, you like roleplay or whatever"
|
||||
(λ (args)
|
||||
(when (room-actor)
|
||||
;; eww, maybe fix mangling the input by joining
|
||||
(<- room-actor 'me (string-join args " "))
|
||||
(loop! #t))))
|
||||
(make-console-command
|
||||
"/join"
|
||||
"<listener-id> - Switch chats to another listener"
|
||||
"<room-id> - Switch chats to another room"
|
||||
(λ (args)
|
||||
(unless (eq? 2 (length args))
|
||||
(error "Need one argument, the listener sturdyref!"))
|
||||
(error "Need one argument, the room sturdyref!"))
|
||||
|
||||
(let* ((listener-id (list-ref args 1))
|
||||
(listener-sref (string->ocapn-id listener-id)))
|
||||
(unless listener-sref
|
||||
(let* ((room-id (list-ref args 1))
|
||||
(room-sref (string->ocapn-id room-id)))
|
||||
(unless room-sref
|
||||
(error "Badly formatted sturdyref!"))
|
||||
(unless ocapn-registry
|
||||
(error "Relay not yet connected."))
|
||||
|
||||
(format #t "Connecting...\n")
|
||||
(on (<- ocapn-registry 'enliven listener-sref)
|
||||
(on (<- ocapn-registry 'enliven room-sref)
|
||||
(λ (l)
|
||||
(set! listener-actor l)
|
||||
(set! room-actor l)
|
||||
(format #t "Joined chat.\n")
|
||||
(loop! #t))
|
||||
#:catch
|
||||
|
@ -103,8 +113,8 @@
|
|||
((eq? 0 (string-length line)) (loop! #t))
|
||||
((is-command? line)
|
||||
(%eval-command line))
|
||||
(else (if listener-actor
|
||||
(on (<- listener-actor line) (λ (val) (loop! val)))
|
||||
(else (if room-actor
|
||||
(on (<- room-actor 'say line) (λ (val) (loop! val)))
|
||||
(begin
|
||||
(format #t "Not connected to anyone yet. Use /join <sturdyref>!\n")
|
||||
(loop! #t))))))))
|
||||
|
|
Loading…
Reference in New Issue