File tree 2 files changed +18
-6
lines changed 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 20
20
$stdout. write "> "
21
21
22
22
while line = $stdin. gets
23
- connection . write ( { input : line } )
23
+ connection . write ( Protocol :: WebSocket :: TextMessage . generate ( { input : line } ) )
24
24
connection . flush
25
25
26
26
$stdout. write "> "
27
27
end
28
28
end
29
29
30
30
while message = connection . read
31
- $stdout. puts message
31
+ # Rewind to start of line:
32
+ $stdout. write "\r "
33
+
34
+ # Clear line:
35
+ $stdout. write "\e [2K"
36
+
37
+ # Print message:
38
+ $stdout. puts message . to_h
39
+
40
+ $stdout. write "> "
32
41
end
33
42
end
34
43
end
Original file line number Diff line number Diff line change @@ -83,25 +83,28 @@ class User < Async::WebSocket::Connection
83
83
@name || ANONYMOUS
84
84
end
85
85
86
+ def send_message ( value )
87
+ self . write ( Protocol ::WebSocket ::TextMessage . generate ( value ) )
88
+ end
89
+
86
90
def handle ( message )
87
- key , *arguments = Command . split ( message [ :input ] )
91
+ key , *arguments = Command . split ( message . parse [ :input ] )
88
92
case key
89
93
when "name"
90
94
@name = arguments . first
91
95
when "look"
92
- self . write ( { room : @room . as_json } )
96
+ self . send_message ( { room : @room . as_json } )
93
97
else
94
98
if action = @room . actions [ key ]
95
99
action . call ( self , *arguments )
96
100
else
97
- message [ :user ]
98
101
@room . broadcast ( message )
99
102
end
100
103
end
101
104
end
102
105
103
106
def notify ( text )
104
- self . write ( { notify : text } )
107
+ self . send_message ( { notify : text } )
105
108
self . flush
106
109
end
107
110
You can’t perform that action at this time.
0 commit comments