syscmd.py: Make newlines configurable

issue #9
This commit is contained in:
James Booth
2016-11-13 21:50:45 +00:00
parent 018f369ff4
commit aef8541135

View File

@@ -33,41 +33,90 @@ def create_win():
prof.win_create(system_win, _handle_win_input) prof.win_create(system_win, _handle_win_input)
def _handle_send(command=None):
if command == None:
prof.cons_bad_cmd_usage("/system")
return
room = prof.get_current_muc()
recipient = prof.get_current_recipient()
if room == None and recipient == None:
prof.cons_show("You must be in a chat or muc window to send a system command")
prof.cons_alert()
return
result = _get_result(command)
newline = prof.settings_boolean_get("system", "newline", True)
if len(result.splitlines()) > 1 and newline:
prof.send_line(u'\u000A' + result)
else:
prof.send_line(result)
def _handle_exec(command=None):
if command == None:
prof.cons_bad_cmd_usage("/system")
return;
create_win()
prof.win_focus(system_win)
_handle_win_input(system_win, command)
def _handle_newline(setting=None):
if not setting:
prof.cons_show("")
newline = prof.settings_boolean_get("system", "newline", True)
if newline:
prof.cons_show("syscmd.py newline: on")
else:
prof.cons_show("syscmd.py newline: off")
return
if setting == "on":
prof.settings_boolean_set("system", "newline", True)
prof.cons_show("syscmd.py newline enabled.")
return
if setting == "off":
prof.settings_boolean_set("system", "newline", False)
prof.cons_show("syscmd.py newline disabled.")
return
prof.cons_bad_cmd_usage("/paste")
def _cmd_system(arg1=None, arg2=None): def _cmd_system(arg1=None, arg2=None):
if not arg1: if not arg1:
create_win() create_win()
prof.win_focus(system_win) prof.win_focus(system_win)
elif arg1 == "send": return;
if arg2 == None:
prof.cons_bad_cmd_usage("/system") if arg1 == "newline":
else: _handle_newline(arg2)
room = prof.get_current_muc() return
recipient = prof.get_current_recipient()
if room == None and recipient == None: if arg1 == "send":
prof.cons_show("You must be in a chat or muc window to send a system command") _handle_send(arg2)
prof.cons_alert() return
else:
result = _get_result(arg2) if arg1 == "exec":
prof.send_line(u'\u000A' + result) _handle_exec(arg2)
elif arg1 == "exec": return
if arg2 == None:
prof.cons_bad_cmd_usage("/system") prof.cons_bad_cmd_usage("/system")
else:
create_win()
prof.win_focus(system_win)
_handle_win_input(system_win, arg2)
else:
prof.cons_bad_cmd_usage("/system")
def prof_init(version, status, account_name, fulljid): def prof_init(version, status, account_name, fulljid):
synopsis = [ synopsis = [
"/system", "/system",
"/system newline on|off",
"/system exec <comman>", "/system exec <comman>",
"/system send <command>" "/system send <command>"
] ]
description = "Run a system command, calling with no arguments will open or focus the system window." description = "Run a system command, calling with no arguments will open or focus the system window."
args = [ args = [
[ "newline on|off", "Send newline before multiline command output, defaults to on" ],
[ "exec <command>", "Execute a command" ], [ "exec <command>", "Execute a command" ],
[ "send <command>", "Send the result of the command to the current recipient or room" ] [ "send <command>", "Send the result of the command to the current recipient or room" ]
] ]
@@ -76,4 +125,5 @@ def prof_init(version, status, account_name, fulljid):
"/system send uname -a" "/system send uname -a"
] ]
prof.register_command("/system", 0, 2, synopsis, description, args, examples, _cmd_system) prof.register_command("/system", 0, 2, synopsis, description, args, examples, _cmd_system)
prof.completer_add("/system", [ "exec", "send" ]) prof.completer_add("/system", [ "exec", "send", "newline" ])
prof.completer_add("/system newline", [ "on", "off" ])