/* * term_ALDL_scroll: should be used for scrolling if the term has AL and DL * by setting the term_scroll function to it */ static int term_ALDL_scroll(int line1, int line2, int n) { int i; if (n > 0) { term_move_cursor(0, line1); for (i = 0; i < n; i++) tputs_x(DL); term_move_cursor(0, line2 - n + 1); for (i = 0; i < n; i++) tputs_x(AL); } else if (n < 0) { n = -n; term_move_cursor(0, line2-n+1); for (i = 0; i < n; i++) tputs_x(DL); term_move_cursor(0, line1); for (i = 0; i < n; i++) tputs_x(AL); } return (0); }
/* * term_CS_scroll: should be used if the terminal has the CS capability by * setting term_scroll equal to it */ static int term_CS_scroll(int line1, int line2, int n) { int i; u_char *thing; if (n > 0) thing = UP(SF ? SF : NL); else if (n < 0) { if (SR) thing = UP(SR); else return 1; } else return 0; tputs_x(tgoto(CS, line2, line1)); /* shouldn't do this each time */ if (n < 0) { term_move_cursor(0, line1); n = -n; } else term_move_cursor(0, line2); for (i = 0; i < n; i++) tputs_x(CP(thing)); tputs_x(tgoto(CS, get_li() - 1, 0)); /* shouldn't do this each time */ return (0); }
/* * term_IMEI_insert: should be used for character inserts if the term has IM * and EI by setting term_insert to it */ static int term_IMEI_insert(u_int c) { tputs_x(IM); putchar_x(c); tputs_x(EI); return (0); }
/* * term_reset: sets terminal attributed back to what they were before the * program started */ void term_reset(void) { tcsetattr(tty_des, TCSADRAIN, &oldb); if (CS) tputs_x(tgoto(CS, get_li() - 1, 0)); if (!use_termcap_enterexit() && TE) tputs_x(TE); term_move_cursor(0, get_li() - 1); term_reset_flag = 1; term_flush(); }
/* * term_IC_insert: should be used for character inserts if the term has IC by * setting term_insert to it. */ static int term_IC_insert(u_int c) { tputs_x(IC); putchar_x(c); return (0); }
void term_beep(void) { tputs_x(BL); Screen *screen = get_current_screen(); fflush(screen ? screen_get_fpout(screen) : stdout); }
/* * term_cont: sets the terminal back to IRCII stuff when it is restarted * after a SIGSTOP. Somewhere, this must be used in a signal() call */ void term_cont(int signo) { tcsetattr(tty_des, TCSADRAIN, &newb); if (!use_termcap_enterexit() && TI) tputs_x(TI); on_signal_occurred(signo); }
/* * term_param_ALDL_scroll: Uses the parameterized version of AL and DL */ static int term_param_ALDL_scroll(int line1, int line2, int n) { if (n > 0) { term_move_cursor(0, line1); tputs_x(tgoto(DL, n, n)); term_move_cursor(0, line2 - n + 1); tputs_x(tgoto(AL, n, n)); } else if (n < 0) { n = -n; term_move_cursor(0, line2-n+1); tputs_x(tgoto(DL, n, n)); term_move_cursor(0, line1); tputs_x(tgoto(AL, n, n)); } return (0); }
void term_standout_off(void) { tputs_x(SE); }
void term_standout_on(void) { tputs_x(SO); }
void term_underline_off(void) { tputs_x(UE); }
void term_bold_off(void) { tputs_x(ME); }
void term_cr(void) { tputs_x(CR); }
/* term_CE_clear_to_eol(): the clear to eol function, right? */ static int term_CE_clear_to_eol(void) { tputs_x(CE); return (0); }
/* * term_init: does all terminal initialization... reads termcap info, sets * the terminal to CBREAK, no ECHO mode. Chooses the best of the terminal * attributes to use .. for the version of this function that is called for * wserv, we set the termial to RAW, no ECHO, so that all the signals are * ignored.. fixes quite a few problems... -phone, jan 1993.. */ void term_init(void) { #ifndef STTY_ONLY char bp[TGETENT_BUFSIZ], *term, *ptr; if ((term = getenv("TERM")) == NULL) { fprintf(stderr, "irc: No TERM variable set!\n"); fprintf(stderr,"irc: You may still run irc by using the -d switch\n"); exit(1); } if (tgetent(bp, term) < 1) { fprintf(stderr, "irc: No termcap entry for %s.\n", term); fprintf(stderr,"irc: You may still run irc by using the -d switch\n"); exit(1); } if ((co = tgetnum("co")) == -1) co = 80; if ((li = tgetnum("li")) == -1) li = 24; ptr = termcap; /* * Thanks to Max Bell ([email protected]) for info about TVI * terminals and the sg terminal capability */ SG = tgetnum("sg"); CM = tgetstr("cm", &ptr); CL = tgetstr("cl", &ptr); if ((CM == NULL) || (CL == NULL)) { fprintf(stderr, "This terminal does not have the necessary " "capabilities to run IRCII\n" "in full screen mode. You may still run " "irc by using the -d switch\n"); exit(1); } if ((CR = tgetstr("cr", &ptr)) == NULL) CR = "\r"; if ((NL = tgetstr("nl", &ptr)) == NULL) NL = "\n"; if ((CE = tgetstr("ce", &ptr)) != NULL) term_clear_to_eol_func = term_CE_clear_to_eol; else term_clear_to_eol_func = term_null_function; TE = tgetstr("te", &ptr); if (!use_termcap_enterexit() && TE && (TI = tgetstr("ti", &ptr)) != NULL ) tputs_x(TI); else TE = TI = NULL; /* if ((ND = tgetstr("nd", &ptr)) || (ND = tgetstr("kr", &ptr))) */ if ((ND = tgetstr("nd", &ptr)) != NULL) term_cursor_right_func = term_ND_cursor_right; else term_cursor_right_func = term_null_function; /* if ((LE = tgetstr("le", &ptr)) || (LE = tgetstr("kl", &ptr))) */ if ((LE = tgetstr("le", &ptr)) != NULL) term_cursor_left_func = term_LE_cursor_left; else if (tgetflag("bs")) term_cursor_left_func = term_BS_cursor_left; else term_cursor_left_func = term_null_function; SF = tgetstr("sf", &ptr); SR = tgetstr("sr", &ptr); if ((CS = tgetstr("cs", &ptr)) != NULL) term_scroll_func = term_CS_scroll; else if ((AL = tgetstr("AL", &ptr)) && (DL = tgetstr("DL", &ptr))) term_scroll_func = term_param_ALDL_scroll; else if ((AL = tgetstr("al", &ptr)) && (DL = tgetstr("dl", &ptr))) term_scroll_func = term_ALDL_scroll; else term_scroll_func = (int (*)(int, int, int)) term_null_function; if ((IC = tgetstr("ic", &ptr)) != NULL) term_insert_func = term_IC_insert; else { if ((IM = tgetstr("im", &ptr)) && (EI = tgetstr("ei", &ptr))) term_insert_func = term_IMEI_insert; else term_insert_func = (int (*)(u_int)) term_null_function; } if ((DC = tgetstr("dc", &ptr)) != NULL) term_delete_func = term_DC_delete; else term_delete_func = term_null_function; SO = tgetstr("so", &ptr); SE = tgetstr("se", &ptr); if ((SO == NULL) || (SE == NULL)) { SO = CP(empty_string()); SE = CP(empty_string()); } US = tgetstr("us", &ptr); UE = tgetstr("ue", &ptr); if ((US == NULL) || (UE == NULL)) { US = CP(empty_string()); UE = CP(empty_string()); } MD = tgetstr("md", &ptr); ME = tgetstr("me", &ptr); if ((MD == NULL) || (ME == NULL)) { MD = CP(empty_string()); ME = CP(empty_string()); } if ((BL = tgetstr("bl", &ptr)) == NULL) BL = "\007"; #endif /* STTY_ONLY */ if (getenv("IRC_DEBUG")|| (tty_des = open("/dev/tty", O_RDWR, 0)) == -1) tty_des = 0; tcgetattr(tty_des, &oldb); newb = oldb; newb.c_lflag &= ~(ICANON | ECHO); /* set equivalent of * CBREAK and no ECHO */ newb.c_cc[VMIN] = 1; /* read() satified after 1 char */ newb.c_cc[VTIME] = 0; /* No timer */ #ifndef _POSIX_VDISABLE # define _POSIX_VDISABLE 0 #endif newb.c_cc[VQUIT] = _POSIX_VDISABLE; #ifdef VDISCARD newb.c_cc[VDISCARD] = _POSIX_VDISABLE; #endif #ifdef VDSUSP newb.c_cc[VDSUSP] = _POSIX_VDISABLE; #endif #ifdef VSUSP newb.c_cc[VSUSP] = _POSIX_VDISABLE; #endif #ifndef STTY_ONLY if (!use_flow_control()) newb.c_iflag &= ~IXON; /* No XON/XOFF */ #endif /* STTY_ONLY */ tcsetattr(tty_des, TCSADRAIN, &newb); }
void term_clear_screen(void) { tputs_x(CL); }
void term_move_cursor(int c, int r) { tputs_x(tgoto(CM, c, r)); }
/* * term_DC_delete: should be used for character deletes if the term has DC by * setting term_delete to it */ static int term_DC_delete(void) { tputs_x(DC); return (0); }
void term_newline(void) { tputs_x(NL); }
/* term_ND_cursor_right: got it yet? */ static int term_ND_cursor_right(void) { tputs_x(ND); return (0); }
void term_bold_on(void) { tputs_x(MD); }
/* term_LE_cursor_left: shouldn't you move on to something else? */ static int term_LE_cursor_left(void) { tputs_x(LE); return (0); }
void more(FILE *fp) { struct winsize w; unsigned short sys_width; unsigned short sys_height; char cmdbuf[1]; int cmd; int n; int lines; char *buf; if (ioctl(STDERR_FILENO, TIOCGWINSZ, &w) == 0) { if (w.ws_row > 0) { sys_height = w.ws_row; } if (w.ws_col > 0) { sys_width = w.ws_col; } } if ((buf = readfile(fp->_file, MAX)) == NULL) { perror("malloc"); return; } lines = countlines(buf); putlines(buf, 0, sys_height - 1); n = sys_height - 1; while (n < lines) { read(tty, cmdbuf, 1); cmd = cmdchr(*cmdbuf); if (cmd == CMD_QUIT) { break; } else if (cmd == CMD_PNEXT) { putlines(buf, n, sys_height - 1); n += sys_height - 1; } else if (cmd == CMD_LNEXT) { putline(buf, n++); } else if (cmd == CMD_PPREV) { tputs_x(CL); if (n - (sys_height - 1) * 2 < 0) { n = 0; } else { n -= (sys_height - 1) * 2; } putlines(buf, n, sys_height - 1); n += sys_height - 1; } else if (cmd == CMD_LPREV) { if (n - sys_height < 0) { continue; } tputs_x(SC); // save pos tputs_x(HO); // set home pos tputs_x(SR); // scroll revrse putline(buf, n-- - sys_height); tputs_x(RC); // restore pos tputs_x(CE); // clr line } } free(buf); }
void term_underline_on(void) { tputs_x(US); }