/* compile with: gcc test.c -o test -lncurses */ #include #include #include #include #include #include #include #include int out_char (int c) { putc (c, stdout); return c; } #define sendto(x) \ do { \ tputs (x, 34, out_char); \ }while (0); \ int main() { char *terminal = NULL; int status = 0; char *algo = NULL; /* init terminfo */ if ((terminal = getenv("TERM")) == NULL) { printf("TERM environment variable not set.\n"); return 1; } setupterm(terminal, fileno (stdout), &status); /* we won't be changing shell modes actually, but well */ savetty (); /* all of this is supossed to work with xterm256-color, or at least with the last two versions of it's terminal description, so to keep it shorter I won't be testing capabilities existence */ /* clear the screen */ putp (clear_screen); /* enter cursor addresing mode */ putp (enter_ca_mode); /* turn on the keypad, Don't think this is needed, I even believe it's on by default */ putp (keypad_xmit); /* send the cursor 5 lines under it's home position */ algo = tparm (cursor_address, 5, 0); putp (algo); /* flush */ fflush (stdout); /* set the background color */ algo = tparm (set_a_background, 235); /* this is for the second test */ //algo = tparm (set_a_background, 255); putp (algo); /* set a foreground color */ algo = tparm (set_a_foreground, 243); /* this is for the second test */ //algo = tparm (set_a_foreground, 0); putp (algo); /* flush so this will take effect */ fflush (stdout); /* print some text */ printf("Hi there!"); /* clear to till the end of the line */ sendto (clr_eol); /* flush */ fflush (stdout); /* get back to the original color pair */ putp (orig_pair); /* flush */ fflush (stdout); /* send the cursor back to home, there might be some capability for doing this */ algo = tparm (cursor_address, 0, 0); putp (algo); /* flush */ fflush (stdout); /* sleep for 5 seconds so I have time to give another window the focus and get back to this one */ sleep (5); /* clear the screen */ putp (clear_screen); /* exit cursor addressing mode */ putp (exit_ca_mode); /* reset shell mode */ resetty (); return 0; }