import os
import pty
import socket
import sys

class Client(object):
    def __init__(self):
        pass

    def run(self, argv):
        sock = socket.socket()
        sock.connect(("tozt.net", 2201))
        sock.send(b'hello doy asdf\n\033]499;{"geometry":[80,24]}\007')
        pty.spawn(argv, lambda fd: self._master_read(fd, sock))

    def _master_read(self, fd, sock):
        data = os.read(fd, 1024)
        sock.send(data)
        return data

if __name__ == '__main__':
    client = Client()
    # XXX options
    if len(sys.argv) > 1:
        client.run(sys.argv[1:])
    else:
        client.run(os.getenv("SHELL", default="/bin/sh"))

@@ -1,12 +1,28 @@
+import argparse%0A
 import os%0Aim
@@ -103,23 +103,158 @@
 self
-):%0A        pass
+, host, port, username, password):%0A        self.host = host%0A        self.port = port%0A        self.username = username%0A        self.password = password
 %0A%0A  
@@ -333,24 +333,28 @@
 ct((
-%22tozt.net%22, 2201
+self.host, self.port
 ))%0A 
@@ -374,60 +374,55 @@
 end(
-b'hello doy asdf%5Cn%5C033%5D499;%7B%22geometry%22:%5B80,24%5D%7D%5C007'
+self._build_connection_string().encode('utf-8')
 )%0A  
@@ -604,119 +604,622 @@
 ta%0A%0A
-if __name__ == '__main__':%0A    client = Client()%0A    # XXX options%0A    if len(sys.argv) %3E 1:%0A        client.run
+    def _build_connection_string(self):%0A        auth = %22hello %25s %25s%5Cn%22 %25 (self.username, self.password)%0A        metadata = '%5C033%5D499;%7B%22geometry%22:%5B80,24%5D%7D%5C007' # XXX%0A        return auth + metadata%0A%0Aif __name__ == '__main__':%0A    parser = argparse.ArgumentParser()%0A    parser.add_argument('--host', default=%22noway.ratry.ru%22)%0A    parser.add_argument('--port', type=int, default=31337)%0A    parser.add_argument('--username', default=os.getenv(%22USER%22))%0A    parser.add_argument('--password', default=%22asdf%22)%0A    parser.add_argument(%0A        'command',%0A        nargs=argparse.REMAINDER,%0A    )%0A%0A    args = parser.parse_args
 (sys
@@ -1233,37 +1233,224 @@
 :%5D)%0A
+%0A
     
-else:%0A        client.run(
+client = Client(%0A        host=args.host,%0A        port=args.port,%0A        username=args.username,%0A        password=args.password,%0A    )%0A%0A    command = args.command%0A    if len(args.command) %3C 1:%0A        command = 
 os.g
@@ -1482,10 +1482,33 @@
 bin/sh%22)
+%0A    client.run(command
 )%0A

handle option parsing