1
0
Fork 0

Sorta working but readline is being annoying

This commit is contained in:
Vivianne 2024-02-02 23:00:52 -05:00
parent 1776832132
commit d308befda3
5 changed files with 52 additions and 29 deletions

View File

@ -6,7 +6,7 @@
(define (^room bcom creator-presence)
"The creator owns the canonical room which publishes to subscribers."
(define pubsub (spawn ^pubsub (list creator-presence)))
(define pubsub (spawn ^pubsub creator-presence))
(methods
[(add-user presence)
($ pubsub 'subscribe presence)

View File

@ -1,5 +1,6 @@
(define-module (bugafriend ui)
#:use-module (bugafriend utils registry)
#:use-module (bugafriend user)
#:use-module (bugafriend room)
#:use-module (goblins)
#:use-module (goblins vat)
@ -16,9 +17,15 @@
#: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 room-actor #f)
(define user-actor #f)
(define (is-command? str)
(and (> (string-length str) 0) (eq? (string-ref str 0) #\/)))
@ -30,6 +37,9 @@
(help console-command-help)
(thunk console-command-thunk))
(define (get-a-room)
($ user-actor 'room-data))
(define commands
(list
(make-console-command
@ -46,17 +56,17 @@
"/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-actor))
($ user-actor 'make-room)
(loop! #t)))
(make-console-command
"/me"
"<text> - Me command, you like roleplay or whatever"
(λ (args)
(when (room-actor)
(let* ((room-data (get-a-room))
(room (room-data-room room-data))
(presence (room-data-presence room-data)))
;; eww, maybe fix mangling the input by joining
(<- room-actor 'me (string-join args " "))
(<- room 'me presence (string-join args " "))
(loop! #t))))
(make-console-command
"/join"
@ -72,11 +82,9 @@
(unless ocapn-registry
(error "Relay not yet connected."))
(format #t "Connecting...\n")
(on (<- ocapn-registry 'enliven room-sref)
(λ (l)
(set! room-actor l)
(format #t "Joined chat.\n")
(λ (r)
($ user-actor 'join-room r)
(loop! #t))
#:catch
(λ (e)
@ -114,24 +122,32 @@
((eq? 0 (string-length line)) (loop! #t))
((is-command? line)
(%eval-command line))
(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))))))))
(else
(let ((room-data (get-a-room)))
(if room-data
(let ((room (room-data-room room-data))
(presence (room-data-presence room-data)))
(format #t "Presence: ~s\n" presence)
(on (<- room 'say presence line)
(λ (val) (loop! val))))
(begin
(format #t "Not connected to anyone yet. Use /join <sturdyref>!\n")
(loop! #t)))))))))
#:unwind? #t))
(define (say setup-sref)
(define (say setup-sref name)
(define vat (spawn-vat #:name "Speaker Vat"))
(set-readline-prompt! " 🐞 > ")
(with-vat vat
(format #t "Connecting to relay... ~s\n" setup-sref)
(with-vat
vat
(format #t "Connecting to relay...\n")
(on (prelay-sref->mycapn-registry setup-sref)
(λ (r)
(set! ocapn-registry r)
(format #t "Connected.\n")
(format #t "Connected. Creating user actor.\n")
(set! user-actor (spawn ^user name ocapn-registry #f))
(loop! #t))
#:catch
(λ (e)

View File

@ -6,7 +6,11 @@
#:use-module (goblins actor-lib methods)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
#:export (^user))
#:export (^user
make-room-data
room-data?
room-data-room
room-data-presence))
(define-record-type <room-data>
(make-room-data room presence)
@ -16,6 +20,7 @@
(define (^user bcom name registry joined-room-data)
(methods
[(room-data) joined-room-data]
[(make-room)
(let* ((my-presence (spawn ^room-presence name))
(room (spawn ^room my-presence))
@ -26,15 +31,17 @@
(bcom (^user bcom name registry room-data)))]
[(join-room room)
(format #t "Connecting...\n")
(let ((my-presence (spawn ^room-presence name)))
(when joined-room-data
(<-np (room-data-room joined-room-data) 'kick-user (room-data-presence joined-room-data))
(on (<- room 'add-user my-presence)
(λ (_)
(format #t "Joined room.\n")))
(<-np (room-data-room joined-room-data) 'kick-user (room-data-presence joined-room-data)))
(define room-data (make-room-data room my-presence))
(bcom (^user bcom name registry room-data))))]
(on (<- room 'add-user my-presence)
(λ (_)
(format #t "Joined room.\n")))
(define room-data (make-room-data room my-presence))
(bcom (^user bcom name registry room-data)))]
[(leave-room room)
(when (eq? room (room-data-room joined-room-data))

View File

@ -8,4 +8,4 @@
(fibers conditions)
(bugafriend ui))
(say (string->ocapn-id (list-ref (command-line) 1)))
(say (string->ocapn-id (list-ref (command-line) 1)) (list-ref (command-line) 2))

View File

@ -8,4 +8,4 @@
(fibers conditions)
(bugafriend ui))
(say (string->ocapn-id (list-ref (command-line) 1)))
(say (string->ocapn-id (list-ref (command-line) 1)) (list-ref (command-line) 2))