29 lines
1.0 KiB
Racket
29 lines
1.0 KiB
Racket
;;; SPDX-License-Identifier: LGPL-3.0-or-later
|
|
;;; SPDX-FileCopyrightText: Copyright © 2010-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
|
|
|
#lang syndicate
|
|
|
|
(require/activate "udp-dataspace.rkt")
|
|
(require/activate syndicate/drivers/external-event)
|
|
(require (only-in racket/port read-bytes-line-evt))
|
|
(require racket/random file/sha1)
|
|
|
|
(message-struct speak (who what))
|
|
(assertion-struct present (who))
|
|
|
|
(spawn (define me (bytes->hex-string (crypto-random-bytes 8)))
|
|
(define stdin-evt (read-bytes-line-evt (current-input-port) 'any))
|
|
|
|
(assert (mcds-outbound (present me)))
|
|
|
|
(on (message (inbound (external-event stdin-evt (list $line))))
|
|
(if (eof-object? line)
|
|
(stop-current-facet)
|
|
(send! (mcds-outbound (speak me line)))))
|
|
|
|
(during (mcds-inbound (present $user))
|
|
(on-start (printf "~a arrived\n" user))
|
|
(on-stop (printf "~a left\n" user))
|
|
(on (message (mcds-inbound (speak user $text)))
|
|
(printf "~a says '~a'\n" user text))))
|