fix a few color-printing bugs & add .gitignore
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
__pycache__
|
||||||
|
*.pyz
|
||||||
|
|
||||||
+8
-6
@@ -7,6 +7,8 @@ from utils import parse_args, safe_input, load_script
|
|||||||
# terminal color codes
|
# terminal color codes
|
||||||
# the readline module requires \001 and \002 because it counts characters
|
# the readline module requires \001 and \002 because it counts characters
|
||||||
# when displaying, but those color codes are zero-width
|
# 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'
|
RST = '\001\x1b[0m\002'
|
||||||
GRN = '\001\x1b[0;32m\002'
|
GRN = '\001\x1b[0;32m\002'
|
||||||
BLU = '\001\x1b[0;34m\002'
|
BLU = '\001\x1b[0;34m\002'
|
||||||
@@ -19,10 +21,10 @@ def main():
|
|||||||
RCON_ADDRESS = args.host
|
RCON_ADDRESS = args.host
|
||||||
args.port = args.port or 25575
|
args.port = args.port or 25575
|
||||||
else:
|
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_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_PASSWORD = args.password or safe_input(f"{GRN} RCON server password>{RST} ")
|
||||||
|
|
||||||
# open TCP connection to server
|
# open TCP connection to server
|
||||||
with socket() as sock:
|
with socket() as sock:
|
||||||
@@ -41,7 +43,7 @@ def main():
|
|||||||
print(f"{GRY} Authentication failed. {RST}")
|
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 not run interactively, quit b/c we don't want to prompt the user for more passwords
|
||||||
if args.password: exit(1)
|
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.execute_command:
|
||||||
if args.echo: rcon.ECHO_COMMANDS = True
|
if args.echo: rcon.ECHO_COMMANDS = True
|
||||||
@@ -59,8 +61,8 @@ def main():
|
|||||||
else: # command REPL
|
else: # command REPL
|
||||||
print(f"{GRY} Successfully logged in. Press Ctrl-C for a fresh prompt or Ctrl-D to exit. {RST}")
|
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
|
while True: # safe_input will terminate the program when the user pressed Ctrl-D
|
||||||
command = safe_input(f"{BLU} RCON@{RCON_ADDRESS} > {RST}")
|
command = safe_input(f"{BLU} RCON@{RCON_ADDRESS} >{RST} ")
|
||||||
print(f"{GRY}", send_command(sock, command))
|
print(f"{GRY}", send_command(sock, command), f"{RST}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user