"""
Lab 3 - Chat Room (Client)
NAME:
STUDENT ID:
DESCRIPTION:
"""

from gui import MainWindow


def loop(port, cert, ip):
    """
    GUI loop.
    port: port to connect to.
    cert: public certificate (task 3)
    ip: IP to bind to (task 3)
    """
    # The following code explains how to use the GUI.
    w = MainWindow()
    # update() returns false when the user quits or presses escape.
    while w.update():
        # if the user entered a line getline() returns a string.
        line = w.getline()
        if line:
            w.writeln(line)


# Command line parser.
if __name__ == '__main__':
    import sys
    import argparse
    p = argparse.ArgumentParser()
    p.add_argument('--port', help='port to connect to',
                   default=12345, type=int)
    p.add_argument('--cert', help='server public cert', default='', type=str)
    p.add_argument('--ip', help='IP to bind to', default='127.0.0.1', type=str)
    args = p.parse_args(sys.argv[1:])
    loop(args.port, args.cert, args.ip)
