diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb42fa9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +*.pyz + diff --git a/src/main.py b/src/main.py index c0016cd..31755f3 100644 --- a/src/main.py +++ b/src/main.py @@ -7,6 +7,8 @@ from utils import parse_args, safe_input, load_script # terminal color codes # the readline module requires \001 and \002 because it counts characters # when displaying, but those color codes are zero-width +# also, the libedit library that readline sometimes interfaces with truncates trailing color codes +# always end input() prompt strings with a visible character (including a space) RST = '\001\x1b[0m\002' GRN = '\001\x1b[0;32m\002' BLU = '\001\x1b[0;34m\002' @@ -19,10 +21,10 @@ def main(): RCON_ADDRESS = args.host args.port = args.port or 25575 else: - RCON_ADDRESS = safe_input(f"{GRN} RCON hostname (IP address)> {RST}") + RCON_ADDRESS = safe_input(f"{GRN} RCON hostname (IP address)>{RST} ") - RCON_PORT = args.port or int(safe_input(f"{GRN} RCON port (default 25575)> {RST}") or 25575) - RCON_PASSWORD = args.password or safe_input(f"{GRN} RCON server password> {RST}") + RCON_PORT = args.port or int(safe_input(f"{GRN} RCON port (default 25575)>{RST} ") or 25575) + RCON_PASSWORD = args.password or safe_input(f"{GRN} RCON server password>{RST} ") # open TCP connection to server with socket() as sock: @@ -41,7 +43,7 @@ def main(): print(f"{GRY} Authentication failed. {RST}") # if not run interactively, quit b/c we don't want to prompt the user for more passwords if args.password: exit(1) - login_success = login(sock, safe_input(f"{GRN} Please re-enter the RCON password> {RST}")) + login_success = login(sock, safe_input(f"{GRN} Please re-enter the RCON password>{RST} ")) if args.execute_command: if args.echo: rcon.ECHO_COMMANDS = True @@ -59,8 +61,8 @@ def main(): else: # command REPL print(f"{GRY} Successfully logged in. Press Ctrl-C for a fresh prompt or Ctrl-D to exit. {RST}") while True: # safe_input will terminate the program when the user pressed Ctrl-D - command = safe_input(f"{BLU} RCON@{RCON_ADDRESS} > {RST}") - print(f"{GRY}", send_command(sock, command)) + command = safe_input(f"{BLU} RCON@{RCON_ADDRESS} >{RST} ") + print(f"{GRY}", send_command(sock, command), f"{RST}") if __name__ == '__main__':