static void setup_scr(void) { char *cbuf = gbuf, *term; if (!opt_interactive) return; if ((term = getenv("TERM"))) if (tgetent(tbuf, term) == 1) if (tgetstr("cl", &cbuf)) clear_ok = 1; set_tty(); clear(); }
void set_title (char *s) { #if defined(USE_NCURSES) || defined (USE_NCURSES_W) if (tgetflag ("hs")) { // terminal has status line support char buf[255] = {0}; char *p = buf; // tgetstr modifies its second argument, let buf keep pointing to the beginning char *ok; // tgetstr's return value is apparently undocumented, except that it's NULL on errors ok = tgetstr ("tsl", &p); // "to status line" if (ok == NULL) return; strcpy (p - 1, s); // tgetstr leaves us *after* the null, so skip back a bit p += strlen (s) - 1; // same here ok = tgetstr ("fsl", &p); // "from status line" if (ok == NULL) return; putp (buf); } #else // assume pdcurses PDC_set_title(s); #endif }
static int get_capability(const char* label, const char* name, const char** pptr, char** p_buf_ptr) { const char* ptr; ptr = tgetstr(name, p_buf_ptr); printf("%-22s (%s) = ", label, name); print_text(ptr); printf("\n"); *pptr = ptr; return ptr != NULL; }
void do_clear(t_var *v, char **line) { int i; short col; col = getsing_col(-1); tputs(tgetstr("cl", NULL), 0, ret_putchar); tputs(tgetstr("sc", NULL), 0, ret_putchar); i = prompt(); i += ft_strlen(*line); ft_putstr(*line); while (i > v->cursor) { i--; if (i % col == 0 && i >= col) { tputs(tgetstr("up", NULL), 0, ret_putchar); tputs(tgoto(tgetstr("ch", NULL), 0, col), 0, ret_putchar); } else tputs(tgetstr("le", NULL), 0, ret_putchar); } }
char *insert_char(char *line, char buffer[3], int i, int len) { char *new_line; if (line && i != (int)ft_strlen(line)) new_line = into(line, buffer, i); else { new_line = ft_strjoin(line, buffer); ft_strdel(&line); } tputs(tgetstr("im", NULL), 0, outputc); tputs(tgetstr("ic", NULL), 0, outputc); write(1, &buffer[0], 1); if (!((len + i + 1) % (g_sz.ws_col))) { tputs(tgetstr("ic", NULL), 0, outputc); write(1, " ", 1); tputs(tgetstr("le", NULL), 0, outputc); } tputs(tgetstr("ei", NULL), 0, outputc); return (new_line); }
void apply_delete(void) { int win_size; t_hist **historic; historic = init_historic(0); if ((*historic)->copy->index != -1) { (*historic)->copy->line = update_line((*historic)->copy->line, (*historic)->copy->index); if ((win_size = check_beginning((*historic)->copy->index))) { tputs(tgetstr("up", NULL), 1, aff_c); tputs(tgoto(tgetstr("ch", NULL), 0, win_size), 1, aff_c); } else tputs(tgetstr("le", NULL), 1, aff_c); tputs(tgetstr("dc", NULL), 1, aff_c); (*historic)->copy->index -= 1; (*historic)->copy->size = ft_strlen((*historic)->copy->line); display_line(); } }
void keyboard_line_up(t_line **l_line, size_t *position, int len_prompt) { if ((*l_line)->prev) { if (!((*l_line)->prev->prev)) prompt_up(l_line, position, len_prompt); else if (*position <= ft_strlen((*l_line)->prev->line)) { tputs(tgetstr("up", NULL), 1, ft_outc); *l_line = (*l_line)->prev; } else { tputs(tgetstr("up", NULL), 1, ft_outc); *l_line = (*l_line)->prev; while (*position > ft_strlen((*l_line)->line)) { tputs(tgetstr("le", NULL), 1, ft_outc); (*position)--; } } } }
void special_key_init(void) { static char sbuf[1024]; char *sp = sbuf; char *res = NULL; /* Arrow up */ res = tgetstr("ku", &sp); add_cmdtable(res, A_B_LINE); /* Arrow down */ res = tgetstr("kd", &sp); add_cmdtable(res, A_F_LINE); /* Page up */ res = tgetstr("kP", &sp); add_cmdtable(res, A_B_SCREEN); /* Page down */ res = tgetstr("kN", &sp); add_cmdtable(res, A_F_SCREEN); }
char *xtgetstr(char *cap, char **area) { char *capstr; if ((capstr = tgetstr(cap, area)) == NULL) { my_putstr("Problem getting "); my_putstr(cap); my_putchar('\n'); my_putstr("Run './42sh t' for non-termcaps mode\n"); exit(1); } return (capstr); }
int tclear(void) { char *res; if ((res = tgetstr("cd", NULL)) == NULL) { ft_putstr_fd("Attempt to clear the term failed", 2); return (-1); } tho(); tputs(res, 2, ft_outc); tvi(); return (0); }
int ft_loop(int *buff, t_list **list, int ac) { while (1) { g_list = list; ft_chk_sig(); tputs(tgoto(tgetstr("cm", NULL), 0, (*list)->y), FD, ft_putint); buff[0] = 0; read(0, buff, 3); ft_chk_up(buff, list); ft_chk_down(buff, list); if (buff[0] == 32) { ft_chk_slct(list); ft_down(list); } ft_del(buff, list); ft_echap(buff, ac); if (buff[0] == 10) return (0); tputs(tgetstr("me", NULL), FD, ft_putint); } }
int set_next_prompt(char *prompt, int cursor, char *to_edit) { int i; i = -1; cursor = 0; (void)prompt; while (++i < 2) if ((tputs(tgetstr("cr", NULL), 1, t_puts)) == -1) ft_exit("Tputs error"); ft_refresh(to_edit, cursor); cursor = -1; return (cursor); }
void get_terminfo(t_env *e) { if ((tgetent((char *)NULL, getenv("TERM"))) != 1) error_call_system("tgetent"); if ((tcgetattr(0, &(e->term_default))) == (-1)) error_call_system("tcgetattr"); if ((tcgetattr(0, &(e->term_update))) == (-1)) error_call_system("tcgetattr"); update_struct(&(e->term_update), 1); if ((tcsetattr(0, TCSADRAIN, &(e->term_update))) == (-1)) error_call_system("tcsetattr"); tputs(tgetstr("vi", NULL), 1, myputc); ft_putstr_fd("\033[?1049h\033[H", 2); }
void insert_char(char c, t_print *print) { int i; i = 0; tputs(tgetstr("im", NULL), 1, out); tputs(tgetstr("ic", NULL), 1, out); write(1, &c, 1); if (print->pos != (i = ft_strlen(print->line))) { while (i >= print->pos) { print->line[i + 1] = print->line[i]; i--; } print->line[print->pos] = c; } print->line[print->pos] = c; print->pos += 1; tputs(tgetstr("ip", NULL), 1, out); tputs(tgetstr("ei", NULL), 1, out); check_length_and_realloc(print); }
int move_cursor_end(t_line *rdl) { if (rdl->line == NULL) return (FALSE); if (rdl->line[rdl->pos]) { if ((get_nb_char_line(rdl)) == get_winsize_x()) go_down(rdl, 0); else my_putstr(tgetstr("nd", NULL)); ++rdl->pos; } return (TRUE); }
int main(int argc, char *argv[]) { char *op = output; char *rp = result; const char *t = getenv("TERM"); char *prop, *pe; int n; if (argc != 2) { fprintf(stderr, "%s [props]\n", argv[0]); exit(1); } if (t == NULL) t = "dumb"; if ((n = tgetent(buf, t)) != 1) { fprintf(stderr, "%s is not a known terminal type\n", t); putw(0, stdout); exit(1); } prop = argv[1]; pe = prop + strlen(prop) - 2; while(prop < pe) { id[0] = *prop++; id[1] = *prop++; if (*prop == '$') { char *r = tgetstr(id, &op); if (r) { size_t l = strlen(r); memcpy(rp, r, l); rp += l; } *rp++= 0; prop++; continue; } if (*prop == '#') { n = tgetnum(id); prop++; } else n = tgetflag(id); /* Intentionally native type and endian */ memcpy(rp, &n, sizeof(n)); rp += sizeof(n); } putw(rp - result, stdout); fwrite(result, rp - result, 1, stdout); return 0; }
/* Move cursor to the column _col and the line _li */ void capGoto(int col, int li) { char *stringCap; stringCap = tgetstr("cm", NULL); if (stringCap != NULL) { stringCap = tgoto(stringCap, col, li); } if (stringCap != NULL) { tputs(stringCap, 1, putchar); } }
void keyboard_line_down(t_line **l_line, size_t *position, int len_prompt) { if ((*l_line)->next) { if (!(*l_line)->prev) { *position = len_prompt + *position + 1; } if (*position >= ft_strlen((*l_line)->next->line)) { tputs(tgetstr("do", NULL), 1, ft_outc); *l_line = (*l_line)->next; *position = 0; while (*position < ft_strlen((*l_line)->line)) { tputs(tgetstr("nd", NULL), 1, ft_outc); (*position)++; } } else else_down(l_line, position); } }
int move_abs(int x, int y) { char *cap; cap = tgetstr("cm", NULL); if (cap != NULL) cap = tgoto(cap, x, y); if (cap != NULL) { my_putstr_fd(cap); return (1); } return (0); }
/* Output startup string. */ void set_init(void) { char *bp, buf[1024]; int settle; bp = buf; if (tgetstr("pc", &bp) != 0) /* Get/set pad character. */ PC = buf[0]; #ifdef TAB3 if (oldmode.c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) { oldmode.c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET); tcsetattr(STDERR_FILENO, TCSADRAIN, &oldmode); } #endif settle = set_tabs(); if (isreset) { bp = buf; if (tgetstr("rs", &bp) != 0 || tgetstr("is", &bp) != 0) { tputs(buf, 0, outc); settle = 1; } bp = buf; if (tgetstr("rf", &bp) != 0 || tgetstr("if", &bp) != 0) { cat(buf); settle = 1; } } if (settle) { (void)putc('\r', stderr); (void)fflush(stderr); (void)sleep(1); /* Settle the terminal. */ } }
void initkbd() { register struct key_map *kp; register i,j; char *p = keyarea; char *ktmp; static char buf[1024]; /* Why do I have to do this again? */ if (!(ktmp = getenv("TERM"))) { (void) fprintf(stderr, "TERM environment variable not set\n"); exit (1); } if (tgetent(buf, ktmp) <= 0) return; km[0].k_str = tgetstr("kl", &p); km[0].k_val = KEY_LEFT; km[1].k_str = tgetstr("kr", &p); km[1].k_val = KEY_RIGHT; km[2].k_str = tgetstr("ku", &p); km[2].k_val = ctl('p'); km[3].k_str = tgetstr("kd", &p); km[3].k_val = ctl('n'); ktmp = tgetstr("ks",&p); if (ktmp) { (void) strcpy(ks_buf, ktmp); ks = ks_buf; tputs(ks, 1, charout); } ktmp = tgetstr("ke",&p); if (ktmp) { (void) strcpy(ke_buf, ktmp); ke = ke_buf; } /* Unmap arrow keys which conflict with our ctl keys */ /* Ignore unset, longer than length 1, and 1-1 mapped keys */ for (i = 0; i < N_KEY; i++) { kp = &km[i]; if (kp->k_str && (kp->k_str[1] == 0) && (kp->k_str[0] != kp->k_val)) for (j = 0; dont_use[j] != 0; j++) if (kp->k_str[0] == dont_use[j]) { kp->k_str = (char *)0; break; } } #ifdef TIOCSLTC (void)ioctl(fileno(stdin), TIOCGLTC, (char *)&old_chars); new_chars = old_chars; if (old_chars.t_lnextc == ctl('v')) new_chars.t_lnextc = -1; if (old_chars.t_rprntc == ctl('r')) new_chars.t_rprntc = -1; (void)ioctl(fileno(stdin), TIOCSLTC, (char *)&new_chars); #endif }
static void initialize_strings (void) { #if HAVE_TPUTS if (find_termcap) { const char *name; /* terminal capability name */ char term_buffer[2048]; /* terminal description */ static char *buffer; /* buffer for capabilities */ char *filler; /* cursor into allocated strings */ int success; /* tgetent results */ name = getenv ("TERM"); if (name == NULL) errexit (1, 0, _("Select a terminal through the TERM environment variable.")); success = tgetent (term_buffer, name); if (success < 0) errexit (1, 0, _("Could not access the termcap data base.")); if (success == 0) errexit (1, 0, _("Terminal type `%s' is not defined."), name); buffer = (char *) malloc (strlen (term_buffer)); filler = buffer; if (no_init_term) { termcap_init_string = NULL; termcap_end_string = NULL; } else { termcap_init_string = tgetstr ("ti", &filler); termcap_end_string = tgetstr ("te", &filler); } term_delete_start = tgetstr ("us", &filler); term_delete_end = tgetstr ("ue", &filler); term_insert_start = tgetstr ("so", &filler); term_insert_end = tgetstr ("se", &filler); } #endif /* HAVE_TPUTS */ /* Ensure some default strings. */ if (!overstrike) { if (!term_delete_start && !user_delete_start) { user_delete_start = "<s><del>"; } if (!term_delete_end && !user_delete_end) { user_delete_end = "</del></s>"; } if (!term_insert_start && !user_insert_start) { user_insert_start = "<u><ins>"; } if (!term_insert_end && !user_insert_end) { user_insert_end = "</ins></u>"; } } }
static void ft_select_print_one(t_selector *selector, int index, int *x, int *y) { t_select *select; select = ft_select_recover(); if ((index + ft_selected_get_page_offset()) == select->cursor_index) { tputs(tgetstr("us", NULL), 0, tputs_putchar); select->cursor_x = *x; select->cursor_y = *y - 1; } if (*y == select->win.ws_row) { *y = 0; select->cols++; *x += select->max_len + 2; } if (selector->is_selected) tputs(tgetstr("mr", NULL), 0, tputs_putchar); ft_putstr_fd(selector->str, select->tty); selector->y = *y; tputs(tgetstr("me", NULL), 0, tputs_putchar); tputs(tgoto(tgetstr("cm", NULL), *x, *y), 1, tputs_putchar); }
void turn_on(struct termios *term) { char buffer[2048]; if (tgetent(buffer, getenv("TERM")) < 1) { write(2, "TERM: not found\n", 16); exit(0); } tcgetattr(0, term); term->c_lflag &= ~(ICANON); term->c_lflag &= ~(ECHO); tputs(tgetstr("ve", NULL), 1, tputs_putchar); tcsetattr(0, 0, term); }
void return_selected(t_env *env) { t_item_list *lst; int printed; terminal_normal_mode(); ft_putstr(tgetstr("te", 0)); ft_putstr(tgetstr("ve", 0)); printed = 0; lst = env->items; while (lst) { if (lst->item->selected) { if (printed) ft_putchar(' '); else printed = 1; ft_putstr(lst->item->name); } lst = lst->next; } exit(0); }
int ft_press_key(t_list *list) { char buffer[5]; t_list *tmp; tmp = list; while (42) { ft_action(list); buffer[2] = 0; read(0, buffer, 5); tmp = ft_press_key2(tmp, buffer); if ((buffer[0] == 'q' || buffer[0] == 10) || (buffer[0] == 27 && buffer[2] == 0)) { ft_putstr(tgetstr("cl", NULL)); ft_putstr(tgetstr("me", NULL)); if (buffer[0] == 10) ft_print_list_selected(list); return (0); } } return (0); }
void print_words(t_environment *env) { int row; int column; int current; row = 0; while (row < env->height && row < env->word_count) { ft_putstr_fd(tgoto(tgetstr("cm", NULL), 0, row), 2); ft_putstr_fd(tgetstr("ce", NULL), 2); column = 0; while (((current = (env->height * column) + row)) < env->word_count) { turn_on_special_text(env, current); ft_putstr_fd(env->words[current], 2); turn_off_special_text(env, current); ft_putcharn_fd(' ', env->single_column_width - ft_strlen(env->words[current]), 2); column++; } row++; } }
void clear_command_line(t_char *list) { int i; int j; int numcols; numcols = get_num_cols(); j = 0; i = 0; while (list) { i++; list = list->next; } tputs(tgetstr("rc", NULL), 1, t_write); while (j <= (i + 3) / numcols) { tputs(tgetstr("ce", NULL), 1, t_write); if ((i + 3) > ((j + 1) * numcols)) tputs(tgetstr("do", NULL), 1, t_write); j++; } tputs(tgetstr("rc", NULL), 1, t_write); }
int ft_action(t_list *list) { t_list *tmp; ft_putstr(tgetstr("cl", NULL)); tmp = list; ft_action2(tmp); tmp = tmp->next; while (tmp != list) { ft_action2(tmp); tmp = tmp->next; } return (0); }
void apply_movenext(t_historic **historic) { t_comline *tmp; tmp = (*historic)->copy->comline; if (tmp->c == ' ') tmp = tmp->right; while (tmp && tmp->c != ' ') tmp = tmp->right; while (tmp && tmp->c == ' ') tmp = tmp->right; if (tmp) tmp = tmp->left; if (tmp && tmp->c == ' ') { while ((*historic)->copy->comline->col != tmp->col) { tputs(tgetstr("nd", NULL), 1, aff_c); (*historic)->copy->comline = (*historic)->copy->comline->right; if (check_ending((*historic)->copy->comline)) tputs(tgetstr("do", NULL), 1, aff_c); } } }