From 82864e710ae284f106c21643a5ac4018e9e2d2fc Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Sep 2013 01:26:45 +0100 Subject: [PATCH] Added window handling commands to test plugins --- RubyTest.rb | 22 ++++++++++++++++++++++ python-test.py | 15 +++++++++++++++ test-c-plugin/test-c-plugin.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/RubyTest.rb b/RubyTest.rb index 6dcb2b6..21df426 100644 --- a/RubyTest.rb +++ b/RubyTest.rb @@ -3,6 +3,7 @@ module RubyTest def self.prof_init(version, status) Prof::cons_show("RubyTest: init, " + version + ", " + status) Prof::register_command("/ruby", 0, 1, "/ruby", "RubyTest", "RubyTest", cmd_ruby) + Prof::register_command("/lower", 0, 1, "/lower", "Lowercase input string", "Lowercase input string", cmd_lower) Prof::register_timed(timer_test, 10) end @@ -87,4 +88,25 @@ module RubyTest Prof::cons_alert } end + + def self.cmd_lower() + return Proc.new { | line | + win_tag = "Lower echo" + if (Prof::win_exists(win_tag) == false) + Prof::win_create(win_tag, handle_lower) + end + + Prof::win_focus(win_tag) + + if (line) + Prof::win_process_line(win_tag, line) + end + } + end + + def self.handle_lower() + return Proc.new { | win, line | + Prof::win_show(win, line.downcase) + } + end end diff --git a/python-test.py b/python-test.py index 05afd2f..4ad884b 100644 --- a/python-test.py +++ b/python-test.py @@ -1,8 +1,11 @@ import prof +win_tag = "Upper echo"; + def prof_init(version, status): prof.cons_show("python-test: init, " + version + ", " + status) prof.register_command("/python", 0, 1, "/python", "python-test", "python-test", cmd_python) + prof.register_command("/upper", 0, 1, "/upper", "Uppercase input string", "Uppercase input string", cmd_upper); prof.register_timed(timer_test, 10) def prof_on_start(): @@ -69,3 +72,15 @@ def timer_test(): prof.cons_show(" current recipient = " + recipient) prof.cons_alert() +def cmd_upper(line): + global win_tag; + if prof.win_exists(win_tag) == False: + prof.win_create(win_tag, handle_upper); + + prof.win_focus(win_tag); + + if line: + prof.win_process_line(win_tag, line); + +def handle_upper(win, line): + prof.win_show(win, line.upper()); diff --git a/test-c-plugin/test-c-plugin.c b/test-c-plugin/test-c-plugin.c index 69553a8..9c75c99 100644 --- a/test-c-plugin/test-c-plugin.c +++ b/test-c-plugin/test-c-plugin.c @@ -5,6 +5,8 @@ #include +static PROF_WIN_TAG echo_win = "Reverse Echo"; + void cmd_c(char **args) { @@ -36,6 +38,34 @@ timer_test(void) prof_cons_alert(); } +void +handle_reverse(PROF_WIN_TAG win, char *line) +{ + int len = strlen(line); + char buf[len]; + int i = len; + int pos = 0; + for (i = len-1; i >= 0; i--) { + buf[pos] = line[i]; + pos++; + } + buf[pos] = '\0'; + prof_win_show(win, buf); +} + +void +cmd_reverse(char **args) +{ + if (!prof_win_exists(echo_win)) { + prof_win_create(echo_win, handle_reverse); + } + + prof_win_focus(echo_win); + if (args[0] != NULL) { + prof_win_process_line(echo_win, args[0]); + } +} + void prof_init(const char * const version, const char * const status) { @@ -44,6 +74,7 @@ prof_init(const char * const version, const char * const status) sprintf(buf, "%s%s, %s", start, version, status); prof_cons_show(buf); prof_register_command("/c", 0, 1, "/c", "c test", "c test", cmd_c); + prof_register_command("/reverse", 0, 1, "/reverse", "Reverse input string", "Reverse input string", cmd_reverse); prof_register_timed(timer_test, 10); }