char *progname = NULL;
char *version = "0.1";
-int display (char **lines, int xmax, int ymax)
+char *input = NULL;
+char *command = NULL;
+
+void display (char **lines, int xmax, int ymax)
{
int stop = 0;
+#ifdef _PDCURSES
statusmsg ("Press 'q' or escape to quit");
-
+#else
+ statusmsg ("Press 'q' or double-escape to quit");
+#endif
+
int skip = 0;
while (!stop) {
clsbody ();
}
int key = waitforkey ();
switch (key) {
- case 'q':
case KEY_ESC:
- exit (0);
+#ifndef _PDCURSES
+ key = waitforkey ();
+ switch (key) {
+ case KEY_ESC:
+ DoExit ();
+ /* fallthrough */
+ case 'f':
+ case 'h':
+ stop = 1;
+ break;
+ }
+ break;
+#endif
+ case 'q':
+ DoExit ();
+ stop = 1;
break;
case 'i':
case KEY_UP:
case KEY_DOWN:
skip = (lines[skip + 1] != NULL) ? skip + 1 : skip;
break;
- case BUTTON_ALT+'f': //ALT_F:
- case BUTTON_ALT+'h': //ALT_H:
- stop = 2;
+#ifdef _PDCURSES
+ case BUTTON_ALT+'F': //ALT_F:
+ case BUTTON_ALT+'H': //ALT_H:
+ stop = 1;
break;
+#endif
+ default:
+ printf ("key pressed: %c (0x%04x)\n", (char)key, key);
}
}
rmstatus();
-
- return (stop == 1);
}
-int view (char *cmd)
+void process (void)
{
- char *buffer;
+ static char **lines = NULL;
int xmax, ymax;
WINDOW *wbody = bodywin ();
getmaxyx (wbody, ymax, xmax);
- buffer = exec_cmd (cmd);
+ char *buffer = (char *)-1;
+ if (command) {
+ buffer = exec_cmd (command);
+ } else if (input) {
+ buffer = load_file (input);
+ } else if (!lines) {
+ buffer = read_stdin ();
+ }
+
if (buffer == NULL) {
char msg[80];
- sprintf (msg, "Error executing %s", cmd);
+ sprintf (msg, "Error executing %s", command ? command : input ? input : "stdin");
statusmsg (msg);
- return 1;
}
- char **lines = split_lines (buffer, xmax);
- free (buffer);
-
- int rc = display (lines, xmax, ymax);
- free_lines (lines);
-
- return rc;
-}
-
-void exec_ipconfig (void)
-{
- static int index = 0;
+ if (!lines) {
+ lines = split_lines (buffer, xmax);
+ free (buffer);
+ }
- switch (index) {
- case 0: view ("ifconfig"); break;
- case 1: view ("ps aux"); break;
- case 2: view ("ls"); break;
+ display (lines, xmax, ymax);
+ if (command || buffer) {
+ free_lines (lines);
+ lines = NULL;
}
- index = (index + 1) % 3;
}
menu SubMenu0[] =
{
- { "Refresh", exec_ipconfig, "Various shell commands" },
+ { "Refresh", process, "Refresh action"},
{ "Exit", DoExit, "Terminate program" },
{ "", (FUNC)0, "" }
};
{ "", (FUNC)0, "" } /* always add this as the last item! */
};
-void init (void)
-{
- view ("ifconfig");
-}
-
/* help message */
int usage (int ret)
{
/* main function */
int main (int argc, char *argv[])
{
- char *input = NULL;
- char *command = NULL;
/* get basename */
char *pt = progname = argv[0];
}
char titre[256] = {0};
- sprintf (titre, "Application: %s", (argc > 1) ? argv[1] : "demonstration program");
-
- //setlocale (LC_ALL, "");
+ sprintf (titre, "Application: %s", command ? command : input ? input : "stdin");
- startmenu (MainMenu, titre, init);
+ startmenu (MainMenu, titre, process);
return 0;
}