summaryrefslogtreecommitdiffhomepage
path: root/contrib/luacurses/test
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-08-31 11:16:52 +0000
committerSteven Barth <steven@midlink.org>2008-08-31 11:16:52 +0000
commitdf52b711a78dbe8808628ae873acc1f3edefb1cf (patch)
tree00b4c145e7ab0501a6de277478b659d51e50fc92 /contrib/luacurses/test
parent36c76090638e80d1cb9ad2dd060aae65976f24c8 (diff)
Reorganise luacurses
Diffstat (limited to 'contrib/luacurses/test')
-rw-r--r--contrib/luacurses/test/filter.lua49
-rw-r--r--contrib/luacurses/test/getnstr.lua12
-rw-r--r--contrib/luacurses/test/getyx.lua13
-rw-r--r--contrib/luacurses/test/hello.lua20
-rw-r--r--contrib/luacurses/test/mouse.lua54
-rw-r--r--contrib/luacurses/test/pair.lua18
-rw-r--r--contrib/luacurses/test/rain.lua89
7 files changed, 255 insertions, 0 deletions
diff --git a/contrib/luacurses/test/filter.lua b/contrib/luacurses/test/filter.lua
new file mode 100644
index 000000000..f8f6ef582
--- /dev/null
+++ b/contrib/luacurses/test/filter.lua
@@ -0,0 +1,49 @@
+
+require("curses");
+
+function read_cmd()
+ curses.attron(curses.A_BOLD);
+ curses.addstr("Command: ");
+ curses.attron(underline);
+ local s = "";
+ while (true) do
+ local c = string.char(curses.getch());
+ if (c == '\n') then break; end
+ s = s .. c;
+ end
+ curses.attroff(underline);
+ curses.attroff(curses.A_BOLD);
+ curses.addch("\n");
+
+ return s;
+end
+
+
+curses.filter();
+curses.initscr();
+curses.cbreak();
+curses.keypad(curses.stdscr(), TRUE);
+
+if (curses.has_colors()) then
+ curses.start_color();
+ curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK);
+ underline = curses.COLOR_PAIR(1);
+else
+ underline = curses.A_UNDERLINE;
+end
+
+while (true) do
+ local s = read_cmd();
+ if (s == "exit") then break; end
+ curses.reset_shell_mode();
+ io.write("\n");
+ io.flush(io.stdout);
+ os.execute(s);
+ curses.reset_prog_mode();
+ curses.touchwin(curses.stdscr());
+ curses.erase();
+ curses.refresh();
+end
+
+curses.endwin();
+
diff --git a/contrib/luacurses/test/getnstr.lua b/contrib/luacurses/test/getnstr.lua
new file mode 100644
index 000000000..172365ea9
--- /dev/null
+++ b/contrib/luacurses/test/getnstr.lua
@@ -0,0 +1,12 @@
+
+require("curses");
+
+curses.initscr();
+
+curses.keypad(curses.stdscr(), true);
+s = curses.mvgetnstr(10, 10, 10);
+curses.addstr(s);
+curses.getch();
+
+curses.endwin();
+
diff --git a/contrib/luacurses/test/getyx.lua b/contrib/luacurses/test/getyx.lua
new file mode 100644
index 000000000..4600236bb
--- /dev/null
+++ b/contrib/luacurses/test/getyx.lua
@@ -0,0 +1,13 @@
+
+require("curses");
+
+curses.initscr();
+while (true) do
+ local s = curses.getnstr(1000);
+ curses.addstr(s);
+ curses.addstr(":" .. table.concat({curses.getyx(curses.stdscr())}, ' ') .. "\n");
+ if (s == "exit") then break; end
+end
+
+curses.endwin();
+
diff --git a/contrib/luacurses/test/hello.lua b/contrib/luacurses/test/hello.lua
new file mode 100644
index 000000000..6a1d28a21
--- /dev/null
+++ b/contrib/luacurses/test/hello.lua
@@ -0,0 +1,20 @@
+
+require("curses");
+
+function show_message(message)
+ local width = string.len(message) + 6;
+ win = curses.newwin(5, width, (curses.LINES() - 5) / 2, (curses.COLS() - width) / 2);
+ win:box('|', '-');
+ win:mvaddstr(2, 3, message);
+ win:getch();
+ win:delwin();
+end
+
+curses.initscr();
+curses.cbreak();
+curses.mvaddstr((curses.LINES() - 5) / 2, (curses.COLS() - 10) / 2, "Hit any key");
+curses.getch();
+show_message("Hello, World!")
+
+curses.endwin();
+
diff --git a/contrib/luacurses/test/mouse.lua b/contrib/luacurses/test/mouse.lua
new file mode 100644
index 000000000..0129cd8c4
--- /dev/null
+++ b/contrib/luacurses/test/mouse.lua
@@ -0,0 +1,54 @@
+
+require("curses");
+
+function show_message(m)
+ local width = string.len(m) + 6;
+ local win = curses.newwin(5, width, (lines - 5) / 2, (cols - width) / 2);
+ win:keypad(true);
+ win:attron(curses.COLOR_PAIR(curses.COLOR_RED));
+ win:box('|', '-', '+');
+ win:mvaddstr(2, 3, m);
+ win:refresh();
+ win:getch();
+ win:delwin();
+end
+
+curses.initscr();
+curses.start_color();
+curses.init_pair(curses.COLOR_BLUE, curses.COLOR_BLUE, curses.COLOR_WHITE);
+curses.init_pair(curses.COLOR_RED, curses.COLOR_RED, curses.COLOR_WHITE);
+curses.cbreak();
+curses.noecho();
+curses.keypad(curses.stdscr(), true);
+
+lines = curses.LINES();
+cols = curses.COLS();
+
+mmasks =
+{
+ curses.BUTTON1_CLICKED,
+ curses.BUTTON2_CLICKED,
+ curses.BUTTON3_CLICKED,
+ curses.BUTTON4_CLICKED
+};
+
+table.foreachi(mmasks, function(_i, _m) curses.addmousemask(_m) end);
+curses.attron(curses.COLOR_PAIR(curses.COLOR_BLUE));
+curses.attron(curses.A_BOLD);
+curses.mvaddstr((lines - 5) / 2, (cols - 10) / 2, "click");
+
+curses.refresh();
+while(true) do
+ local c = curses.getch();
+ if (c == curses.KEY_MOUSE) then
+ local r, id, x, y, z, bstate = curses.getmouse();
+ if (r) then
+ show_message("id = " .. id .. ", x = " .. x .. ", y = " .. y .. ", z = " .. z .. ", bstate = " ..
+ string.format("0x%x", bstate));
+ end
+ break;
+ end
+end
+
+curses.endwin();
+
diff --git a/contrib/luacurses/test/pair.lua b/contrib/luacurses/test/pair.lua
new file mode 100644
index 000000000..f26980061
--- /dev/null
+++ b/contrib/luacurses/test/pair.lua
@@ -0,0 +1,18 @@
+
+require("curses");
+
+curses.initscr();
+
+curses.start_color();
+curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_YELLOW);
+curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_RED);
+
+for i = 1, 2 do
+ local r, f, b = curses.pair_content(i);
+ curses.attrset(curses.COLOR_PAIR(i));
+ curses.addstr(f .. ", " .. b .. "\n");
+end
+
+curses.getch();
+curses.endwin();
+
diff --git a/contrib/luacurses/test/rain.lua b/contrib/luacurses/test/rain.lua
new file mode 100644
index 000000000..35e469102
--- /dev/null
+++ b/contrib/luacurses/test/rain.lua
@@ -0,0 +1,89 @@
+
+require("curses");
+
+curses.initscr();
+curses.nl();
+curses.noecho();
+
+
+if (curses.has_colors()) then
+ curses.start_color();
+ curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK);
+ curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK);
+end
+
+curses.curs_set(0);
+curses.timeout(0);
+
+math.randomseed(os.time());
+
+lines = curses.LINES();
+cols = curses.COLS();
+
+xpos = {};
+ypos = {};
+r = lines - 4;
+c = cols - 4;
+for i = 0, 4 do
+ xpos[i] = c * math.random() + 2;
+ ypos[i] = r * math.random() + 2;
+end
+
+function dec(i, max)
+ if (curses.has_colors()) then
+ local z = 3 * math.random();
+ local c = curses.COLOR_PAIR(z);
+ curses.attrset(c);
+ if (math.floor(z) > 0) then
+ curses.attron(curses.A_BOLD);
+ end
+ end
+
+ if (i > 0) then return i - 1;
+ else return max;
+ end
+end
+
+i = 0;
+while(true) do
+ x = c * math.random() + 2;
+ y = r * math.random() + 2;
+
+ curses.mvaddstr(y, x, ".");
+
+ curses.mvaddstr(ypos[i], xpos[i], "o");
+
+ i = dec(i, 4);
+ curses.mvaddstr(ypos[i], xpos[i], "O");
+
+ i = dec(i, 4);
+ curses.mvaddstr(ypos[i] - 1, xpos[i], "-");
+ curses.mvaddstr(ypos[i], xpos[i] - 1, "|.|");
+ curses.mvaddstr(ypos[i] + 1, xpos[i], "-");
+
+ i = dec(i, 4);
+ curses.mvaddstr(ypos[i] - 2, xpos[i], "-");
+ curses.mvaddstr(ypos[i] - 1, xpos[i] - 1, "/ \\");
+ curses.mvaddstr(ypos[i], xpos[i] - 2, "| O |");
+ curses.mvaddstr(ypos[i] + 1, xpos[i] - 1, "\\ /");
+ curses.mvaddstr(ypos[i] + 2, xpos[i], "-");
+
+ i = dec(i, 4);
+ curses.mvaddstr(ypos[i] - 2, xpos[i], " ");
+ curses.mvaddstr(ypos[i] - 1, xpos[i] - 1, " ");
+ curses.mvaddstr(ypos[i], xpos[i] - 2, " ");
+ curses.mvaddstr(ypos[i] + 1, xpos[i] - 1, " ");
+ curses.mvaddstr(ypos[i] + 2, xpos[i], " ");
+
+
+ xpos[i] = x;
+ ypos[i] = y;
+
+ local ch = curses.getch();
+ if (ch == string.byte('q', 1)) or (ch == string.byte('Q', 1)) then break; end
+ curses.refresh();
+ curses.napms(50);
+end
+
+curses.endwin();
+