working prototype

This commit is contained in:
Mewrry the Kitty 2026-01-31 00:37:01 -06:00
commit 880e85f12d
2 changed files with 115 additions and 0 deletions

36
client.rb Normal file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env ruby
require 'socket'
require 'io/console'
HOST = 'localhost'
PORT = 6789
VERSION = 0.01
socket = TCPSocket.new(HOST, PORT)
puts "PORT: #{PORT}"
puts "HOST: #{HOST}"
#reader = Thread.new do
Thread.new do
loop do
msg = socket.gets
exit 0 unless msg
ver, msg = msg.split('|',2)
next unless ver.to_f <= VERSION
next unless msg != nil
# In message version 0.01 and lower,
# all messages are in an assumed format...
row,col,chars = msg.split('|',3)
print "\x1b[#{row};#{col}H#{chars}\x1b[A"
end
end
while (char = STDIN.noecho(&:getch))
exit unless char != "\x03" # ^C
exit unless char != "\x04" # ^D
next unless char.ord >= 0x20 # Non printing
next unless char.ord != 0x7F # DEL (Non print)
socket.puts "#{VERSION}|#{char}"
end