Add luacurses to contrib
[project/luci.git] / contrib / luacurses / src / test / filter.lua
1
2 require("curses");
3
4 function read_cmd()
5     curses.attron(curses.A_BOLD);
6     curses.addstr("Command: ");
7     curses.attron(underline);
8     local s = "";
9     while (true) do
10         local c = string.char(curses.getch());
11         if (c == '\n') then break; end
12         s = s .. c;
13     end
14     curses.attroff(underline);
15     curses.attroff(curses.A_BOLD);
16     curses.addch("\n");
17
18     return s;
19 end
20
21
22 curses.filter();
23 curses.initscr();
24 curses.cbreak();
25 curses.keypad(curses.stdscr(), TRUE);
26
27 if (curses.has_colors()) then
28     curses.start_color();
29     curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK);
30     underline = curses.COLOR_PAIR(1);
31 else
32     underline = curses.A_UNDERLINE;
33 end
34
35 while (true) do
36     local s = read_cmd();
37     if (s == "exit") then break; end
38     curses.reset_shell_mode();
39     io.write("\n");
40     io.flush(io.stdout);
41     os.execute(s);
42     curses.reset_prog_mode();
43     curses.touchwin(curses.stdscr());
44     curses.erase();
45     curses.refresh();
46 end
47
48 curses.endwin();
49