* Add test script

* Rename cont to windex
* Add optparse options
This commit is contained in:
Mewrry the Kitty 2026-02-02 15:20:52 -06:00
parent 880e85f12d
commit 1e8d916a36
3 changed files with 119 additions and 40 deletions

View file

@ -2,9 +2,30 @@
require 'socket'
require 'io/console'
require 'optparse'
HOST = 'localhost'
PORT = 6789
options = {
:port => 7570,
:host => 'localhost'
}
OptionParser.new do |opt|
opt.on('-pPORT', '--port PORT', Integer,
'Port to connect to (defaults to 7570)') do |o|
options[:port] = o
end
opt.on('-HHOST', '--host HOST', String,
'Host to connect to (defaults to `localhost`)') do |o|
options[:host] = o
end
opt.on('-h', '--help', 'Get help with this command') do
puts opt
exit
end
end.parse!(into: options)
HOST = options[:host]
PORT = options[:port]
#PORT = 6789
VERSION = 0.01
socket = TCPSocket.new(HOST, PORT)
@ -12,25 +33,31 @@ 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
begin
print "\x1b[?1049h\x1b[2J\x1b[3J" # Open and clear alternate buffer
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}"
#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
ensure
print "\x1b[?1049l" # Back to regular buffer
end