int rl_checkperf(size_t size, size_t *len) { static int flag; int co; co = tgetnum("co"); *len = (size_t)co; if ((((int)size / co) < (tgetnum("li") - 1)) && !flag) return (1); if (flag) *len = 0; flag = 1; return (0); }
/* * This routine gets all the terminal flags from the termcap database */ static void zap() { register char *namp; register bool **fp; register char ***sp; #ifdef DEBUG register char *cp; #endif namp = "ambsdadbeohchzinmimsncnsosulxbxnxtxsxx"; fp = sflags; do { *(*fp++) = tgetflag(namp); #ifdef DEBUG fprintf(outf, "%2.2s = %s\n", namp, *fp[-1] ? "TRUE" : "FALSE"); #endif namp += 2; } while (*namp); namp = "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullmandnlpcrcscsesfsosrtatetiucueupusvbvsveALDLUPDOLERI"; sp = sstrs; do { *(*sp++) = tgetstr(namp, &aoftspace); #ifdef DEBUG fprintf(outf, "%2.2s = %s", namp, *sp[-1] == NULL ? "NULL\n" : "\""); if (*sp[-1] != NULL) { for (cp = *sp[-1]; *cp; cp++) fprintf(outf, "%s", unctrl(*cp)); fprintf(outf, "\"\n"); } #endif namp += 2; } while (*namp); if (XS) SO = SE = NULL; else { if (tgetnum("sg") > 0) SO = NULL; if (tgetnum("ug") > 0) US = NULL; if (!SO && US) { SO = US; SE = UE; } } if (DO && !NL) NL = DO; }
void rl_goto(char *buff, size_t from, size_t to) { int co; int eco; int eli; char c; co = tgetnum("co"); if (ABS((eco = ((from % co) - (to % co))))) { if (eco > 0) c = 'D'; else c = 'C'; ft_sprintf(buff, "\033[%d%c", ABS(eco), c); write(1, buff, ft_strlen(buff)); } if (ABS((eli = ((from / co) - (to / co))))) { if (eli > 0) c = 'A'; else c = 'B'; ft_sprintf(buff, "\033[%d%c", ABS(eli), c); write(1, buff, ft_strlen(buff)); } }
void sigwinch_handler(t_data *data) { ioctl(0, TIOCGWINSZ, &(data->win)); data = stock_data(data, 1); tputs(tgetstr("cd", NULL), tgetnum("co"), ft_putchar2); show_menu(data); }
void move_cursor(int x, int y) { int width; int height; char *cap; char *str; width = tgetnum("co"); height = tgetnum("li"); if (x >= 0 && x <= width && y >= 0 && y <= height) { cap = tgetstr("cm", NULL); str = tgoto(cap, x, y); tputs(str, 1, &display); } }
CAMLprim value caml_terminfo_setup (value vchan) { value result; static char buffer[1024]; char *term; chan = Channel (vchan); term = getenv ("TERM"); if (term == NULL) return Bad_term; if (tgetent(buffer, term) != 1) return Bad_term; num_lines = tgetnum ("li"); up = tgetstr ("up", &area_p); down = tgetstr ("do", &area_p); standout = tgetstr ("us", &area_p); standend = tgetstr ("ue", &area_p); if (standout == NULL || standend == NULL){ standout = tgetstr ("so", &area_p); standend = tgetstr ("se", &area_p); } Assert (area_p <= area + 1024); if (num_lines == -1 || up == NULL || down == NULL || standout == NULL || standend == NULL){ return Bad_term; } result = caml_alloc_small (1, Good_term_tag); Field (result, 0) = Val_int (num_lines); return result; }
void term_edit_set(t_env *env) { env->term_len = tgetnum("co"); term_put("vi"); term_put("im"); term_canonical_mode(env, 0); }
LineEditor::LineEditor() : file(historyFile) { TaskMaster::logger.Debug("new"); std::string line; history.reserve(100); if (!file.is_open()) file.open(historyFile, std::fstream::out); else while (file.good()) { if (!std::getline(file, line).good()) break; history.push_back(line); } tgetent(NULL, getenv("TERM")); tputs(tgetstr((char *)"im", NULL), 1, putonterm); tcgetattr(0, &(old)); tcgetattr(0, &(termios_p)); termios_p.c_lflag &= ~(ECHO | ICANON); tcsetattr(0, TCSADRAIN, &(termios_p)); error = 0; // initscr(); // cbreak(); // keypad(stdscr, TRUE); // noecho(); sizeX = tgetnum((char *)"co"); std::cout << sizeX << std::endl; // getmaxyx(stdscr, sizeY, sizeX); TaskMaster::logger.Debug("x = %d, y = %d", sizeX, sizeY); numLine = 0; }
main() { char *cp = getenv("TERM"); char clbuf[20]; char pcbuf[20]; char *clbp = clbuf; char *pcbp = pcbuf; char *clear; char buf[1024]; char *pc; struct sgttyb tty; gtty(1, &tty); ospeed = tty.sg_ospeed; if (cp == (char *) 0) exit(1); if (tgetent(buf, cp) != 1) exit(1); pc = tgetstr("pc", &pcbp); if (pc) PC = *pc; clear = tgetstr("cl", &clbp); if (clear) tputs(clear, tgetnum("li"), putchar); exit (clear == (char *) 0); }
void ft_arrow_left(t_lst **lst) { t_lst *tmp; int i; int move; i = 0; move = 0; tmp = *lst; if ((*lst)->nbr_w < tgetnum("li")) { if ((*lst)->next != *lst) move_tmp(tmp); } else { i = 0; while (tmp->select == 0) { tmp = tmp->next; i++; } tmp->select = 0; tmp = i_min_li(i, lst, tmp, move); tmp->select = 1; } }
int hl_groups_setup(hl_groups_ptr hl_groups) { int i; const struct default_hl_group_info *ginfo; if (!hl_groups) return -1; #ifdef NCURSES_VERSION ginfo = default_groups_for_background_dark; #else ginfo = default_groups_for_curses; #endif hl_groups->in_color = has_colors(); if (hl_groups->in_color) hl_groups->more_colors = (tgetnum("Co") >= 16); /* Set up the default groups. */ for (i = 0; ginfo[i].kind != HLG_LAST; ++i) { int val; const struct default_hl_group_info *spec = &ginfo[i]; val = setup_group(hl_groups, spec->kind, spec->mono_attrs, spec->color_attrs, spec->fore_color, spec->back_color); if (val == -1) { logger_write_pos(logger, __FILE__, __LINE__, "setup group."); return -1; } } return 0; }
int control_size(t_elem *l) { char *termtype; int lin; termtype = getenv("TERM"); if (!termtype) ft_env_error(); tgetent(NULL, termtype); tputs(tgetstr("cl", NULL), 1, int_char); lin = tgetnum("li"); l->len = ft_list_len(l); if (l->len > lin - 1) { tputs(tgetstr("cl", NULL), 1, int_char); ft_putendl_red("Please Resize window"); return (0); } else { tputs(tgetstr("cl", NULL), 1, int_char); display_list(l); } return (1); }
void tcutil_winsize (int *ncols, int *nrows) { int rv; struct winsize wsz; /* Try the ioctl first */ rv = ioctl(0, TIOCGWINSZ, &wsz); if(rv == 0) { *ncols = wsz.ws_col; *nrows = wsz.ws_row; } else { /* Try termcap */ *ncols = tgetnum("co"); *nrows = tgetnum("li"); } }
int main (int argc, char **argv) { char *term; char *buf; term = argv[1]; printf ("TERM: %s\n", term); buf = (char *) tgetent (0, term); if ((int) buf <= 0) { printf ("No entry.\n"); return 0; } printf ("Entry: %s\n", buf); tprint ("cm"); tprint ("AL"); printf ("co: %d\n", tgetnum ("co")); printf ("am: %d\n", tgetflag ("am")); return 0; }
mod_export void tsetcap(int cap, int flags) { if (tccan(cap) && !isset(SINGLELINEZLE) && !(termflags & (TERM_NOUP|TERM_BAD|TERM_UNKNOWN))) { switch (flags & TSC_OUTPUT_MASK) { case TSC_RAW: tputs(tcstr[cap], 1, putraw); break; case 0: default: tputs(tcstr[cap], 1, putshout); break; case TSC_PROMPT: if (!bv->dontcount) { addbufspc(1); *bv->bp++ = Inpar; } tputs(tcstr[cap], 1, putstr); if (!bv->dontcount) { int glitch = 0; if (cap == TCSTANDOUTBEG || cap == TCSTANDOUTEND) glitch = tgetnum("sg"); else if (cap == TCUNDERLINEBEG || cap == TCUNDERLINEEND) glitch = tgetnum("ug"); if(glitch < 0) glitch = 0; addbufspc(glitch + 1); while(glitch--) *bv->bp++ = Nularg; *bv->bp++ = Outpar; } break; } if (flags & TSC_DIRTY) { flags &= ~TSC_DIRTY; if (txtisset(TXTBOLDFACE) && cap != TCBOLDFACEBEG) tsetcap(TCBOLDFACEBEG, flags); if (txtisset(TXTSTANDOUT)) tsetcap(TCSTANDOUTBEG, flags); if (txtisset(TXTUNDERLINE)) tsetcap(TCUNDERLINEBEG, flags); } } }
static void railroad(char **args) { NCURSES_CONST char *name = getenv("TERM"); char buffer[1024]; char area[1024], *ap = area; if (name == 0) name = "dumb"; if (tgetent(buffer, name) >= 0) { wipeit = tgetstr("ce", &ap); height = tgetnum("li"); length = tgetnum("co"); moveit = tgetstr("cm", &ap); if (wipeit == 0 || moveit == 0 || height <= 0 || length <= 0) { wipeit = 0; moveit = 0; height = 0; length = 0; } startS = tgetstr("so", &ap); finisS = tgetstr("se", &ap); startU = tgetstr("us", &ap); finisU = tgetstr("ue", &ap); backup = tgetstr("le", &ap); startC = tgetstr("ve", &ap); finisC = tgetstr("vi", &ap); ShowCursor(0); CATCHALL(onsig); while (*args) { ShowSign(*args++); } ShowCursor(1); } }
static void s_for_select(void) { int i; if (sgt_readline()->prompt.len + sgt_readline()->len_buffer > \ (unsigned long)tgetnum("co")) { i = tgetnum("co"); while (i > 0 && sgt_readline()->cursor_pos < sgt_readline()->len_buffer) { ++sgt_readline()->cursor_pos; ++sgt_readline()->select.len; --i; } } readline_refresh_line(); }
static void get_termcap_number(char const* id, int* dest, int low, int high) { int const val = tgetnum(id); if (low <= val && val <= high) { *dest = val; } }
void init_caps(t_caps *caps) { char t[4096]; char *area; area = t; verif_term(); if ((caps->clstr = tgetstr("cl", &area)) == NULL) aff_error("tgetstr failed to load clstr"); if ((caps->cmstr = tgetstr("cm", &area)) == NULL) aff_error("tgetstr failed to load cmdstr"); caps->li = tgetnum("li"); caps->co = tgetnum("co"); if (caps->co < WIDTH + 1 || caps->li < HEIGHT + 1) aff_error("terminal too small"); tputs(caps->clstr, 1, my_outc); }
void readline_key_ctrl_down(void) { int i; if (sgt_readline()->select.is_select) return (s_for_select()); if (sgt_readline()->prompt.len + sgt_readline()->len_buffer > (unsigned long)tgetnum("co")) { i = tgetnum("co"); while (i > 0 && sgt_readline()->cursor_pos < sgt_readline()->len_buffer) { readline_key_right(); --i; } } }
int main(int argc, char **argv) { int ch, exitval, n; char *cptr, *term, buf[1024], tbuf[1024]; const char *p; term = NULL; while ((ch = getopt(argc, argv, "T:")) != -1) switch(ch) { case 'T': term = optarg; break; case '?': default: usage(); } argc -= optind; argv += optind; if (argc < 1) usage(); if (!term && !(term = getenv("TERM"))) errx(2, "no terminal type specified and no TERM environmental variable."); if (tgetent(tbuf, term) != 1) err(3, "tgetent failure"); for (exitval = 0; (p = *argv) != NULL; ++argv) { switch (*p) { case 'c': if (!strcmp(p, "clear")) p = "cl"; break; case 'i': if (!strcmp(p, "init")) p = "is"; break; case 'l': if (!strcmp(p, "longname")) { prlongname(tbuf); continue; } break; case 'r': if (!strcmp(p, "reset")) p = "rs"; break; } cptr = buf; if (tgetstr(p, &cptr)) argv = process(p, buf, argv); else if ((n = tgetnum(p)) != -1) (void)printf("%d\n", n); else exitval = !tgetflag(p); } exit(exitval); }
static int bin_echotc(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) { char *s, buf[2048], *t, *u; int num, argct; s = *argv++; if (termflags & TERM_BAD) return 1; if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term())) return 1; /* if the specified termcap has a numeric value, display it */ if ((num = tgetnum(s)) != -1) { printf("%d\n", num); return 0; } /* if the specified termcap is boolean, and set, say so */ switch (ztgetflag(s)) { case -1: break; case 0: puts("no"); return 0; default: puts("yes"); return 0; } /* get a string-type capability */ u = buf; t = tgetstr(s, &u); if (t == (char *)-1 || !t || !*t) { /* capability doesn't exist, or (if boolean) is off */ zwarnnam(name, "no such capability: %s", s); return 1; } /* count the number of arguments required */ for (argct = 0, u = t; *u; u++) if (*u == '%') { if (u++, (*u == 'd' || *u == '2' || *u == '3' || *u == '.' || *u == '+')) argct++; } /* check that the number of arguments provided is correct */ if (arrlen(argv) != argct) { zwarnnam(name, (arrlen(argv) < argct) ? "not enough arguments" : "too many arguments"); return 1; } /* output string, through the proper termcap functions */ if (!argct) tputs(t, 1, putraw); else { /* This assumes arguments of <lines> <columns> for cap 'cm' */ num = (argv[1]) ? atoi(argv[1]) : atoi(*argv); tputs(tgoto(t, num, atoi(*argv)), 1, putraw); } return 0; }
void setlinescols(void) { char *p; int i; #ifdef __EMX__ { int s[2]; _scrsize(s); COLS = s[0]; LINES = s[1]; if (getenv("WINDOWID")) { FILE *fd = popen("scrsize", "rt"); if (fd) { fscanf(fd, "%i %i", &COLS, &LINES); pclose(fd); } } } #elif defined(HAVE_TERMIOS_H) && defined(TIOCGWINSZ) struct winsize wins; i = ioctl(tty, TIOCGWINSZ, &wins); if (i >= 0 && wins.ws_row != 0 && wins.ws_col != 0) { LINES = wins.ws_row; COLS = wins.ws_col; } #endif /* defined(HAVE-TERMIOS_H) && defined(TIOCGWINSZ) */ if (LINES <= 0 && (p = getenv("LINES")) != NULL && (i = atoi(p)) >= 0) LINES = i; if (COLS <= 0 && (p = getenv("COLUMNS")) != NULL && (i = atoi(p)) >= 0) COLS = i; if (LINES <= 0) LINES = tgetnum("li"); /* number of line */ if (COLS <= 0) COLS = tgetnum("co"); /* number of column */ if (COLS > MAX_COLUMN) COLS = MAX_COLUMN; if (LINES > MAX_LINE) LINES = MAX_LINE; #if defined(__CYGWIN__) LASTLINE = LINES - (isWinConsole == TERM_CYGWIN_RESERVE_IME ? 2 : 1); #endif /* defined(__CYGWIN__) */ }
void ms_term_mode_raw(t_term *term) { struct termios attr; char *env_term; if ((env_term = getenv("TERM"))) tgetent(NULL, env_term); else tgetent(NULL, "xterm"); tcgetattr(STDIN_FILENO, &attr); attr.c_lflag &= ~(ECHO | ICANON); attr.c_cc[VMIN] = 1; attr.c_cc[VTIME] = 0; tcsetattr(STDIN_FILENO, TCSADRAIN, &attr); term->nb_columns = tgetnum("co"); term->nb_lines = tgetnum("li"); ms_capabilities_load(term); }
void rl_last_co(size_t offset) { int co; co = tgetnum("co"); if (!offset || (offset % co)) return ; tm_cap("do"); }
/* * Reads the window size and clear the window. This is called on setup, * and also catches SIGWINCHs, and adjusts Maxlines. Basically, this is * the central place for window size stuff. */ void window_size(int signo) { struct winsize ws; if((ioctl(1, TIOCGWINSZ, &ws) != -1) && (ws.ws_col>73) && (ws.ws_row>7)){ Cols = ws.ws_col; Lines = ws.ws_row; }else{ Cols = tgetnum("co"); Lines = tgetnum("li"); } if (!Batch) clear_screen(); /* * calculate header size, length of cmdline field ... */ Numfields = make_header(); }
/*--------------------------------------------------------------------------*/ int scilinesdefault(void) { #ifndef _MSC_VER char tc_buf[1024]; /* holds termcap buffer */ if (tgetent(tc_buf, getenv("TERM")) == 1) { setConsoleLines(tgetnum("li")); /* retrieve from the term info the number of lines */ setConsoleWidth(tgetnum("co")); /* And the number of columns */ } else { /* Haven't been able to detect the terminal */ setConsoleLines(DEFAULT_NUMBERS_LINES); setConsoleWidth(DEFAULT_NUMBERS_COLUMNS); } #else if ( (getScilabMode() != SCILAB_STD) && (getScilabMode() != SCILAB_API) ) { /* -NW or -NWNI mode */ int X = getXConsoleScreenSize(); int Y = getYConsoleScreenSize(); if (X < DEFAULT_NUMBERS_COLUMNS) { X = DEFAULT_NUMBERS_COLUMNS; } if (Y < DEFAULT_NUMBERS_LINES) { Y = DEFAULT_NUMBERS_LINES; } setConsoleWidth(X); setConsoleLines(Y); } else { setConsoleLines(DEFAULT_NUMBERS_LINES); setConsoleWidth(DEFAULT_NUMBERS_COLUMNS); } #endif return 0; }
static HashNode gettermcap(UNUSED(HashTable ht), char *name) { int len, num; char *tcstr, buf[2048], *u; Param pm = NULL; /* This depends on the termcap stuff in init.c */ if (termflags & TERM_BAD) return NULL; if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term())) return NULL; unmetafy(name, &len); pm = (Param) hcalloc(sizeof(struct param)); pm->nam = dupstring(name); pm->flags = PM_READONLY; u = buf; /* logic in the following cascade copied from echotc, above */ if ((num = tgetnum(name)) != -1) { pm->gsu.i = &nullsetinteger_gsu; pm->u.val = num; pm->flags |= PM_INTEGER; return (HashNode) pm; } pm->gsu.s = &nullsetscalar_gsu; switch (ztgetflag(name)) { case -1: break; case 0: pm->u.str = dupstring("no"); pm->flags |= PM_SCALAR; return (HashNode) pm; default: pm->u.str = dupstring("yes"); pm->flags |= PM_SCALAR; return (HashNode) pm; } if ((tcstr = (char*)tgetstr(name, &u)) != NULL && tcstr != (char *)-1) { pm->u.str = dupstring(tcstr); pm->flags |= PM_SCALAR; } else { /* zwarn("no such capability: %s", name, 0); */ pm->u.str = dupstring(""); pm->flags |= PM_UNSET; } return (HashNode) pm; }
/* For compatibility with FSF readline. */ void rl_reset_terminal(const char *terminal_name) { #ifdef CONFIG_USE_TERMCAP char buf[1024]; char *bp; #endif #ifdef TIOCGWINSZ struct winsize W; #endif if (terminal_name) { el_term = terminal_name; } else if ((el_term = getenv("TERM")) == NULL) { el_term = "dumb"; } /* Initialize to faulty values to trigger fallback if nothing else works. */ tty_cols = tty_rows = -1; #ifdef CONFIG_USE_TERMCAP bp = buf; if (-1 != tgetent(buf, el_term)) { if ((backspace = tgetstr("le", &bp)) != NULL) backspace = strdup(backspace); tty_cols = tgetnum("co"); tty_rows = tgetnum("li"); } /* Make sure to check width & rows and fallback to TIOCGWINSZ if available. */ #endif if (tty_cols <= 0 || tty_rows <= 0) { #ifdef TIOCGWINSZ if (ioctl(el_outfd, TIOCGWINSZ, &W) >= 0 && W.ws_col > 0 && W.ws_row > 0) { tty_cols = (int)W.ws_col; tty_rows = (int)W.ws_row; return; } #endif tty_cols = SCREEN_COLS; tty_rows = SCREEN_ROWS; } }
static void signal_handler(int sign, siginfo_t *siginfo, void *context) { t_win *term; (void)siginfo; (void)context; if (sign == SIGWINCH) { ft_putendl_fd("", STDIN_FILENO); term = g_memory(S_WIN, 0); if (term->all_act != NULL) { if (tgetent(NULL, term->term_name) == -1) int_error(ETERM); term->win_column = tgetnum("co"); term->win_line = tgetnum("li"); g_error = ESIGWINCH; } } }