diff options
| author | Wango Fett <wangofett@tilde.town> | 2017-10-26 17:05:49 +0000 |
|---|---|---|
| committer | Wango Fett <wangofett@tilde.town> | 2017-10-26 17:05:49 +0000 |
| commit | 3a8afeb369d4ef66c9b991e64febe66a35338177 (patch) | |
| tree | 460a2b88f6d5de2258ad17a319a4672afcde434d /asciifarm/client/__init__.py | |
Pip installable!
Diffstat (limited to 'asciifarm/client/__init__.py')
| -rw-r--r-- | asciifarm/client/__init__.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/asciifarm/client/__init__.py b/asciifarm/client/__init__.py new file mode 100644 index 0000000..5047151 --- /dev/null +++ b/asciifarm/client/__init__.py @@ -0,0 +1,40 @@ + +import curses +import json +import os +import getpass +import sys +from .connection import Connection +from .client import Client +from .display import Display + +defaultAdresses = { + "abstract": "asciifarm", + "unix": "asciifarm.socket", + "inet": "localhost:9021", + } + +def main(name, socketType, address, keybindings, characters, colours=False): + + connection = Connection(socketType) + try: + connection.connect(address) + except ConnectionRefusedError: + print("ERROR: Could not connect to server.\nAre you sure that the server is running and that you're connecting to the right address?", file=sys.stderr) + return + + caught_ctrl_c = False + + def start(stdscr): + display = Display(stdscr, characters, colours) + client = Client(stdscr, display, name, connection, keybindings) + nonlocal caught_ctrl_c + try: + client.start() + except KeyboardInterrupt: + caught_ctrl_c = True + + curses.wrapper(start) + + if caught_ctrl_c: + print('^C caught, goodbye!') |
