From: Christopher Allan Webber Date: Sun, 22 Jan 2017 04:13:03 +0000 (-0600) Subject: formatted output X-Git-Tag: fosdem-2017~102 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=e8015ebb1351ace6536cfe04aab1e29c26f22366;p=mudsync.git formatted output --- diff --git a/data/web-static/js/mudsync.js b/data/web-static/js/mudsync.js index b926c14..631fa89 100644 --- a/data/web-static/js/mudsync.js +++ b/data/web-static/js/mudsync.js @@ -20,7 +20,6 @@ function displayMessage(data, self_sent) { var new_entry = document.createElement("div"); - var new_text = document.createTextNode(data); var stream_metabox = document.getElementById("stream-metabox"); var should_scroll = false; if(stream_metabox.scrollTop === (stream_metabox.scrollHeight @@ -33,7 +32,7 @@ function displayMessage(data, self_sent) { } else { new_entry.setAttribute("class", "stream-entry"); } - new_entry.appendChild(new_text); + new_entry.innerHTML = data; document.getElementById("stream").appendChild(new_entry); if (should_scroll) { stream_metabox.scrollTop = stream_metabox.scrollHeight; diff --git a/mudsync/networking.scm b/mudsync/networking.scm index 1a8ece5..228a89f 100644 --- a/mudsync/networking.scm +++ b/mudsync/networking.scm @@ -26,6 +26,9 @@ #:use-module (ice-9 receive) #:use-module (oop goops) + ;; Formatting + #:use-module (sxml simple) + ;; used by web server only #:use-module (sxml simple) #:use-module (web request) @@ -190,16 +193,20 @@ (define* (nm-send-to-client-id nm message #:key client data) "Send DATA to TO-CLIENT id" + (define formatted-data + (call-with-output-string + (lambda (p) + (sxml->xml data p)))) (define client-obj (hash-ref (nm-clients nm) client)) (match client-obj (#f (throw 'no-such-client "Asked to send data to client but that client doesn't exist" #:client-id client - #:data data)) + #:data formatted-data)) (('socket . client-socket) - (display data client-socket)) + (display formatted-data client-socket)) (('websocket . ws-client-id) - (<- (.web-server nm) 'ws-send ws-client-id data)))) + (<- (.web-server nm) 'ws-send ws-client-id formatted-data)))) (define (nm-incoming-line-action nm message client-id line) "Handle LINE coming in, probably from an external message handler, diff --git a/mudsync/room.scm b/mudsync/room.scm index aaedd5c..6efac43 100644 --- a/mudsync/room.scm +++ b/mudsync/room.scm @@ -66,7 +66,10 @@ (empty-command "go" 'cmd-go-where) (loose-direct-command "go" 'cmd-go) (greedy-command "say" 'cmd-say) - (greedy-command "emote" 'cmd-emote))) + (greedy-command "\"" 'cmd-say) + (greedy-command "'" 'cmd-say) + (greedy-command "emote" 'cmd-emote) + (greedy-command "/me" 'cmd-emote))) ;; TODO: Subclass from container? (define-class () @@ -152,9 +155,8 @@ "Handle looking around the room" ;; Get the room text (define room-text - (format #f "**~a**\n~a\n" - (slot-ref room 'name) - (slot-ref room 'desc))) + `((strong "=> " ,(slot-ref room 'name) " <=") + (p ,(slot-ref room 'desc)))) ;; Get a list of other things the player would see in the room (define occupant-names-all @@ -182,7 +184,8 @@ (define final-text (if occupant-names-string - (string-append room-text occupant-names-string) + `(,@room-text + (p (i ,occupant-names-string))) room-text)) (<- player-id 'tell @@ -257,7 +260,7 @@ (define player-name (mbody-val (<-wait (message-from message) 'get-name))) (define message-to-send - (format #f "~a says: ~a\n" player-name phrase)) + `((b "<" ,player-name ">") " " ,phrase)) (room-tell-room room message-to-send)) (define* (room-cmd-emote room message #:key phrase) @@ -265,7 +268,7 @@ (define player-name (mbody-val (<-wait (message-from message) 'get-name))) (define message-to-send - (format #f "* ~a ~a\n" player-name phrase)) + `((b "* " ,player-name) " " ,phrase)) (room-tell-room room message-to-send)) (define* (room-announce-entrance room message #:key who-entered)