From ae47e116db0dee50907b445ffd2997cc62bdae64 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 28 Feb 2016 23:28:12 +0000 Subject: [PATCH] Added current_win_is_console --- ascii.py | 10 +++++++--- tests/python-test.py | 14 ++++++++++++-- tests/test-c-plugin/test-c-plugin.c | 13 ++++++++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ascii.py b/ascii.py index 2e86aaa..2323186 100644 --- a/ascii.py +++ b/ascii.py @@ -2,12 +2,16 @@ import prof import subprocess def _cmd_ascii(text): + proc = subprocess.Popen(['figlet', '--', text], stdout=subprocess.PIPE) + ascii_out = proc.communicate()[0].decode('utf-8') recipient = prof.get_current_recipient() room = prof.get_current_muc() - if recipient or room: - proc = subprocess.Popen(['figlet', '--', text], stdout=subprocess.PIPE) - ascii_out = proc.communicate()[0].decode('utf-8') + if recipient: prof.send_line(u'\u000A' + ascii_out) + elif room: + prof.send_line(u'\u000A' + ascii_out) + elif prof.current_win_is_console(): + prof.cons_show(u'\u000A' + ascii_out) def prof_init(version, status): synopsis = [ "/ascii " ] diff --git a/tests/python-test.py b/tests/python-test.py index 8133899..4e8cb5c 100644 --- a/tests/python-test.py +++ b/tests/python-test.py @@ -34,7 +34,15 @@ def cmd_pythontest(arg1=None, arg2=None, arg3=None, arg4=None, arg5=None): create_win() prof.win_focus(plugin_win) prof.cons_show_themed(group, key, dflt, message) - prof.win_show(plugin_win, "called -> prof_cons_show_themed: " + arg2 + ", " + arg3 + ", " + arg4 + ", " + arg5) + prof.win_show(plugin_win, "called -> prof.cons_show_themed: " + arg2 + ", " + arg3 + ", " + arg4 + ", " + arg5) + elif arg1 == "constest": + res = prof.current_win_is_console() + create_win() + prof.win_focus(plugin_win) + if res: + prof.win_show(plugin_win, "called -> prof.current_win_is_console: true") + else: + prof.win_show(plugin_win, "called -> prof.current_win_is_console: false") elif arg1 == "winshow": if arg2 != None: create_win() @@ -141,6 +149,7 @@ def prof_init(version, status): "/python-test consalert", "/python-test consshow ", "/python-test consshow_t ", + "/python-test constest", "/python-test winshow ", "/python-test winshow_t ", "/python-test notify ", @@ -153,6 +162,7 @@ def prof_init(version, status): [ "consalert", "Highlight the console window in the status bar" ], [ "consshow ", "Show the message in the console window" ], [ "consshow_t ", "Show the themed message in the console window. " ], + [ "constest", "Show whether the command was run in the console." ], [ "winshow ", "Show the message in the plugin window" ], [ "winshow_t ", "Show the themed message in the plugin window. " ], [ "notify ", "Send a desktop notification with message" ], @@ -171,7 +181,7 @@ def prof_init(version, status): prof.register_command("/python-test", 1, 5, synopsis, description, args, examples, cmd_pythontest) prof.register_ac("/python-test", - [ "consalert", "consshow", "consshow_t", "winshow", "winshow_t", "notify", "sendline", "get", "log" ] + [ "consalert", "consshow", "consshow_t", "constest", "winshow", "winshow_t", "notify", "sendline", "get", "log" ] ) prof.register_ac("/python-test get", [ "recipient", "room" ] diff --git a/tests/test-c-plugin/test-c-plugin.c b/tests/test-c-plugin/test-c-plugin.c index ea4f0a9..feafd14 100644 --- a/tests/test-c-plugin/test-c-plugin.c +++ b/tests/test-c-plugin/test-c-plugin.c @@ -60,6 +60,15 @@ cmd_ctest(char **args) sprintf(buf, "%s%s, %s, %s, %s", str, args[1], args[2], args[3], args[4]); prof_win_show(plugin_win, buf); } + } else if (strcmp(args[0], "constest") == 0) { + int res = prof_current_win_is_console(); + create_win(); + prof_win_focus(plugin_win); + if (res) { + prof_win_show(plugin_win, "called -> prof_current_win_is_console: true"); + } else { + prof_win_show(plugin_win, "called -> prof_current_win_is_console: false"); + } } else if (strcmp(args[0], "winshow") == 0) { if (args[1]) { create_win(); @@ -212,6 +221,7 @@ prof_init(const char * const version, const char * const status) "/c-test consalert", "/c-test consshow ", "/c-test consshow_t ", + "/c-test constest", "/c-test winshow ", "/c-test winshow_t ", "/c-test notify ", @@ -225,6 +235,7 @@ prof_init(const char * const version, const char * const status) { "consalert", "Highlight the console window in the status bar" }, { "consshow ", "Show the message in the console window" }, { "consshow_t ", "Show the themed message in the console window. " }, + { "constest", "Show whether the command was run in the console." }, { "winshow ", "Show the message in the plugin window" }, { "winshow_t ", "Show the themed message in the plugin window. " }, { "notify ", "Send a desktop notification with message" }, @@ -245,7 +256,7 @@ prof_init(const char * const version, const char * const status) prof_register_command("/c-test", 1, 5, synopsis, description, args, examples, cmd_ctest); - char *cmd_ac[] = { "consalert", "consshow", "consshow_t", "winshow", "winshow_t", "notify", "sendline", "get", "log", NULL }; + char *cmd_ac[] = { "consalert", "consshow", "consshow_t", "constest", "winshow", "winshow_t", "notify", "sendline", "get", "log", NULL }; prof_register_ac("/c-test", cmd_ac); char *get_ac[] = { "recipient", "room", NULL };