=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/top/screen.c,v retrieving revision 1.16 retrieving revision 1.17 diff -c -r1.16 -r1.17 *** src/usr.bin/top/screen.c 2007/04/04 19:12:15 1.16 --- src/usr.bin/top/screen.c 2007/05/29 00:56:56 1.17 *************** *** 1,4 **** ! /* $OpenBSD: screen.c,v 1.16 2007/04/04 19:12:15 otto Exp $ */ /* * Top users/processes display for Unix --- 1,4 ---- ! /* $OpenBSD: screen.c,v 1.17 2007/05/29 00:56:56 otto Exp $ */ /* * Top users/processes display for Unix *************** *** 40,49 **** #include #include #include #include #include - #include #include #include --- 40,49 ---- #include #include + #include #include #include #include #include #include *************** *** 51,71 **** #include "screen.h" #include "boolean.h" ! int overstrike, screen_length, screen_width; ! char ch_erase, ch_kill, smart_terminal, PC; ! char string_buffer[1024], home[15], lower_left[15]; ! char *clear_line, *clear_scr, *clear_to_end; ! char *cursor_motion, *start_standout, *end_standout; ! char *terminal_init, *terminal_end; static struct termios old_settings, new_settings; - static char is_a_terminal = No; - void init_termcap(int interactive) { ! char *bufptr, *PCptr, *term_name; int status; /* set defaults in case we aren't smart */ --- 51,66 ---- #include "screen.h" #include "boolean.h" ! int screen_length, screen_width; ! char ch_erase, ch_kill, smart_terminal; static struct termios old_settings, new_settings; + static char is_a_terminal = No; void init_termcap(int interactive) { ! char *term_name; int status; /* set defaults in case we aren't smart */ *************** *** 107,112 **** --- 102,108 ---- smart_terminal = No; return; } + /* set up common terminal capabilities */ if ((screen_length = tgetnum("li")) <= Header_lines) { screen_length = smart_terminal = 0; *************** *** 119,154 **** else screen_width -= 1; ! /* terminals that overstrike need special attention */ ! overstrike = tgetflag("os"); - /* initialize the pointer into the termcap string buffer */ - bufptr = string_buffer; - - /* get "ce", clear to end */ - if (!overstrike) { - clear_line = tgetstr("ce", &bufptr); - } - /* get necessary capabilities */ - if ((clear_scr = tgetstr("cl", &bufptr)) == NULL || - (cursor_motion = tgetstr("cm", &bufptr)) == NULL) { - smart_terminal = No; - return; - } - /* get some more sophisticated stuff -- these are optional */ - clear_to_end = tgetstr("cd", &bufptr); - terminal_init = tgetstr("ti", &bufptr); - terminal_end = tgetstr("te", &bufptr); - start_standout = tgetstr("so", &bufptr); - end_standout = tgetstr("se", &bufptr); - - /* pad character */ - PC = (PCptr = tgetstr("pc", &bufptr)) ? *PCptr : 0; - - /* set convenience strings */ - (void) strlcpy(home, tgoto(cursor_motion, 0, 0), sizeof(home)); - /* (lower_left is set in get_screensize) */ - /* get the actual screen size with an ioctl, if needed */ /* * This may change screen_width and screen_length, and it always sets --- 115,126 ---- else screen_width -= 1; ! /* get necessary capabilities */ ! if (tgetstr("cl", NULL) == NULL || tgetstr("cm", NULL) == NULL) { ! smart_terminal = No; ! return; ! } /* get the actual screen size with an ioctl, if needed */ /* * This may change screen_width and screen_length, and it always sets *************** *** 168,209 **** if (tcgetattr(STDOUT_FILENO, &old_settings) != -1) { /* copy the settings so we can modify them */ new_settings = old_settings; - /* turn off ICANON, character echo and tab expansion */ new_settings.c_lflag &= ~(ICANON | ECHO); new_settings.c_oflag &= ~(OXTABS); new_settings.c_cc[VMIN] = 1; new_settings.c_cc[VTIME] = 0; - (void) tcsetattr(STDOUT_FILENO, TCSADRAIN, &new_settings); /* remember the erase and kill characters */ ch_erase = old_settings.c_cc[VERASE]; ch_kill = old_settings.c_cc[VKILL]; - /* remember that it really is a terminal */ is_a_terminal = Yes; ! /* send the termcap initialization string */ putcap(terminal_init); } if (!is_a_terminal) { /* not a terminal at all---consider it dumb */ smart_terminal = No; } } void end_screen(void) { ! /* move to the lower left, clear the line and send "te" */ ! if (smart_terminal) { ! putcap(lower_left); ! putcap(clear_line); ! fflush(stdout); ! putcap(terminal_end); ! } ! ! /* if we have settings to reset, then do so */ if (is_a_terminal) (void) tcsetattr(STDOUT_FILENO, TCSADRAIN, &old_settings); } --- 140,176 ---- if (tcgetattr(STDOUT_FILENO, &old_settings) != -1) { /* copy the settings so we can modify them */ new_settings = old_settings; /* turn off ICANON, character echo and tab expansion */ new_settings.c_lflag &= ~(ICANON | ECHO); new_settings.c_oflag &= ~(OXTABS); new_settings.c_cc[VMIN] = 1; new_settings.c_cc[VTIME] = 0; + (void) tcsetattr(STDOUT_FILENO, TCSADRAIN, &new_settings); /* remember the erase and kill characters */ ch_erase = old_settings.c_cc[VERASE]; ch_kill = old_settings.c_cc[VKILL]; is_a_terminal = Yes; ! #if 0 /* send the termcap initialization string */ putcap(terminal_init); + #endif } if (!is_a_terminal) { /* not a terminal at all---consider it dumb */ smart_terminal = No; } + + if (smart_terminal) + initscr(); } void end_screen(void) { ! if (smart_terminal) ! endwin(); if (is_a_terminal) (void) tcsetattr(STDOUT_FILENO, TCSADRAIN, &old_settings); } *************** *** 211,216 **** --- 178,184 ---- void reinit_screen(void) { + #if 0 /* install our settings if it is a terminal */ if (is_a_terminal) (void) tcsetattr(STDOUT_FILENO, TCSADRAIN, &new_settings); *************** *** 218,223 **** --- 186,192 ---- /* send init string */ if (smart_terminal) putcap(terminal_init); + #endif } void *************** *** 231,284 **** if (ws.ws_col != 0) screen_width = ws.ws_col - 1; } - (void) strlcpy(lower_left, tgoto(cursor_motion, 0, screen_length - 1), - sizeof(lower_left)); } void ! standout(char *msg) { if (smart_terminal) { ! putcap(start_standout); ! if (fputs(msg, stdout) == EOF) ! exit(1); ! putcap(end_standout); ! } else { ! if (fputs(msg, stdout) == EOF) ! exit(1); } - } - - void - clear(void) - { - if (smart_terminal) - putcap(clear_scr); - } - - int - clear_eol(int len) - { - if (smart_terminal && !overstrike && len > 0) { - if (clear_line) { - putcap(clear_line); - return (0); - } else { - while (len-- > 0) { - if (putchar(' ') == EOF) - exit(1); - } - return (1); - } - } - return (-1); - } - - void - go_home(void) - { - if (smart_terminal) - putcap(home); } /* This has to be defined as a subroutine for tputs (instead of a macro) */ --- 200,214 ---- if (ws.ws_col != 0) screen_width = ws.ws_col - 1; } } void ! go_home(void) { if (smart_terminal) { ! move(0, 0); ! refresh(); } } /* This has to be defined as a subroutine for tputs (instead of a macro) */