void apply_movedown(t_historic **historic) { int col; struct winsize size; ioctl(0, TIOCGWINSZ, &size); if (check_pos(historic, size.ws_col, -1)) { tputs(tgetstr("do", NULL), 1, aff_c); tputs(tgoto(tgetstr("ch", NULL), 0, (*historic)->copy->comline->col % size.ws_col + 1), 1, aff_c); col = (*historic)->copy->comline->col + size.ws_col; while ((*historic)->copy->comline->col != col) (*historic)->copy->comline = (*historic)->copy->comline->right; } else if (check_pos(historic, size.ws_col, -2) && (*historic)->copy->comline->right->right) { tputs(tgetstr("do", NULL), 1, aff_c); while ((*historic)->copy->comline->right) (*historic)->copy->comline = (*historic)->copy->comline->right; tputs(tgoto(tgetstr("ch", NULL), 0, (*historic)->copy->comline->col % size.ws_col + 1), 1, aff_c); } }
/* * 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); }
int term_up(char **send, unsigned long int buff, t_comp *count, t_tab *stock) { char *cp; char *s1; (void)buff; if (!stock->list) return (0); cp = tgetstr("dl", NULL); s1 = tgoto(cp, 0, 0); if (my_tputs(s1, 0, my_putchar) == -1) return (-1); cp = tgetstr("ch", NULL); s1 = tgoto(cp, 0, 0); if (my_tputs(s1, 0, my_putchar) == -1) return (-1); prompt(stock); if (stock && stock->move && stock->list->next) stock->list = stock->list->next; free(*send); my_putstr(stock->list->data); *send = my_strdup(stock->list->data); count->save = my_strlen(stock->list->data); count->compt = count->save; stock->move = 1; return (0); }
static void print_outputs(t_j *j) { int i; int y; t_hist *tmp; PS(j->caps.cl); y = j->term.height - 1; i = -1; while (++i < OUTPUT_MAX) { tmp = j->output[i]; while (y > 0 && tmp != NULL) { PS(tgoto(j->caps.cm, 3, --y)); put_hightlight(SUB(tmp->str, tmp->length), SUB(j->ctrl_p_prompt.line.str, j->ctrl_p_prompt.line.length)); PC('\n'); tmp = tmp->prev; } y--; } PS(tgoto(j->caps.cm, 0, j->term.height - 1)); PS("SEARCH > "); PS(tgoto(j->caps.ch, 0, ft_promptput(&(j->ctrl_p_prompt), j->term.width - 9) + 9)); FL; }
/* * Insert nchunk blank line(s) onto the * screen, scrolling the last line on the * screen off the bottom. Use the scrolling * region if possible for a smoother display. * If no scrolling region, use a set * of insert and delete line sequences */ ttinsl(row, bot, nchunk) { register int i, nl; if (row == bot) { /* Case of one line insert is */ ttmove(row, 0); /* special */ tteeol(); return; } if (CS && SR) { /* Use scroll region and back index */ nl = bot - row; ttwindow(row,bot); ttmove(row, 0); while (nchunk--) putpad(SR, nl); ttnowindow(); return; } else if (insdel) { ttmove(1+bot-nchunk, 0); nl = nrow - ttrow; if (pDL) putpad(tgoto(pDL, 0, nchunk), nl); else for (i=0; i<nchunk; i++) /* For all lines in the chunk */ putpad(DL, nl); ttmove(row, 0); nl = nrow - ttrow; /* ttmove() changes ttrow */ if (pAL) putpad(tgoto(pAL, 0, nchunk), nl); else for (i=0; i<nchunk; i++) /* For all lines in the chunk */ putpad(AL, nl); ttrow = HUGE; ttcol = HUGE; } else panic("ttinsl: Can't insert/delete line"); }
/* * Delete nchunk line(s) from "row", replacing the * bottom line on the screen with a blank line. * Unless we're using the scrolling region, this is * done with a crafty sequences of insert and delete * lines. The presence of the echo area makes a * boundry condition go away. */ ttdell(row, bot, nchunk) { register int i, nl; if (row == bot) { /* One line special case */ ttmove(row, 0); tteeol(); return; } if (CS) { /* scrolling region */ nl = bot - row; ttwindow(row, bot); ttmove(bot, 0); while (nchunk--) putpad(SF, nl); ttnowindow(); } else if(insdel) { ttmove(row, 0); /* Else use insert/delete line */ nl = nrow - ttrow; if (pDL) putpad(tgoto(pDL, 0, nchunk), nl); else for (i=0; i<nchunk; i++) /* For all lines in the chunk */ putpad(DL, nl); ttmove(1+bot-nchunk,0); nl = nrow - ttrow; /* ttmove() changes ttrow */ if (pAL) putpad(tgoto(pAL, 0, nchunk), nl); else for (i=0; i<nchunk; i++) /* For all lines in the chunk */ putpad(AL, nl); ttrow = HUGE; ttcol = HUGE; } else panic("ttdell: Can't insert/delete line"); }
void print_rest(int cursor, t_line *list) { t_ws ws; int i; ioctl(0, TIOCGWINSZ, &ws); i = 0; list = obtain_list(cursor, list); cursor += len_prompt(); while (list) { ft_putchar(list->data); list = list->next; i++; } if ((cursor % ws.ws_col) != 0) { if ((cursor % ws.ws_col) > ws.ws_col - i) tputs(tgetstr("up", NULL), 1, tputs_putchar); i = (cursor % ws.ws_col); tputs(tgoto(tgetstr("ch", NULL), 0, i), 1, tputs_putchar); } else tputs(tgoto(tgetstr("ch", NULL), 0, 0), 1, tputs_putchar); }
void re_draw2(t_caps *caps) { int li; t_select *choices; choices = caps->head; tputs(tgoto(tgetstr("cm", NULL), 0, 0), 1, my_putchar); tputs(tgetstr("cd", NULL), 1, my_putchar); while (1) { li = choices->li; tputs(tgoto(tgetstr("cm", NULL), choices->co, li ), 1, my_putchar); if (choices->cursor == 1) tputs(tgetstr("us", NULL), 1, my_putchar); if (choices->select == 1) tputs(tgetstr("mr", NULL), 1, my_putchar); my_putstr(choices->name); if (choices->cursor == 1) tputs(tgetstr("ue", NULL), 1, my_putchar); if (choices->select == 1) tputs(tgetstr("me", NULL), 1, my_putchar); if (caps->tail == choices) break ; choices = choices->next; } choices = caps->cursor; tputs(tgoto(tgetstr("cm", NULL), choices->co, choices->li), 1, my_putchar); choices = caps->head; }
int apply_input(unsigned int* choice, unsigned int size_list, t_list_proc* list, char** path) { int ret; fd_set fds; struct timeval timeout; char c; unsigned int i; FD_ZERO(&fds); FD_SET(0, &fds); timeout.tv_sec = 0; timeout.tv_usec = 0; ret = select(1, &fds, 0, 0, &timeout); if (ret == -1) return fatal(2, strerror(errno), 1); else if (ret != 0 && FD_ISSET(0, &fds)) { if (read(0, &c, 1) == -1) return fatal(2, strerror(errno), 1); if (c == 'A') { tputs(tgoto(tgetstr("cm", 0), 1, *choice + 1), 1, id_print_char); id_print_char(' '); *choice = *choice - 1; if (*choice < 1) *choice = size_list; } else if (c == 'B') { tputs(tgoto(tgetstr("cm", 0), 1, *choice + 1), 1, id_print_char); id_print_char(' '); *choice = *choice + 1; if (*choice > size_list) *choice = 1; } else if (c == '\n') { i = 1; while (i < *choice) { list = list->next; i = i + 1; } *path = malloc(sizeof(char) * (strlen("/proc//") + strlen(list->pid) + 1)); if (*path == 0) return fatal(2, "Malloc fail", 1); strcpy(*path, "/proc/"); strcat(*path, list->pid); strcat(*path, "/"); } } return 0; }
void aff_screen(t_node *node, int i) { tputs(tgoto(tgetstr("cm", NULL), 0, i), 1, my_putchar); if (node->back == 0) tputs(tgetstr("us", NULL), 1, my_putchar); else tputs(tgetstr("mr", NULL), 1, my_putchar); my_putstr(node->choice); tputs(tgoto(tgetstr("cm", NULL), 0, i), 1, my_putchar); }
void move_balle(t_env* env) { tputs(tgoto(env->cm, env->balle.x, env->balle.y), 1, id_put); id_print_str("\033[01;40m "); env->balle.x = env->balle.x + env->balle.addx; env->balle.y = env->balle.y + env->balle.addy; tputs(tgoto(env->cm, env->balle.x, env->balle.y), 1, id_put); id_print_str("\033[01;40m0"); usleep(10000); }
static void ShowSign(char *string) { char *base = string; int ch, first, last; if (moveit != 0) { tputs(tgoto(moveit, 0, height - 1), 1, outc); tputs(wipeit, 1, outc); } while (*string != 0) { ch = *string; if (ch != ' ') { if (moveit != 0) { for (first = length - 2; first >= (string - base); first--) { if (first < length - 1) { tputs(tgoto(moveit, first + 1, height - 1), 1, outc); PutChar(' '); } tputs(tgoto(moveit, first, height - 1), 1, outc); PutChar(ch); } } else { last = ch; if (isalpha(ch)) { first = isupper(ch) ? 'A' : 'a'; } else if (isdigit(ch)) { first = '0'; } else { first = ch; } if (first < last) { Underline(1); while (first < last) { PutChar(first); Backup(); first++; } Underline(0); } } if (moveit != 0) Backup(); } StandOut(1); PutChar(ch); StandOut(0); fflush(stdout); string++; } if (moveit != 0) tputs(wipeit, 1, outc); putchar('\n'); }
static void ft_up_bis(t_sh *sh, t_window window) { tputs(tgoto((tgetstr("up", NULL)), 0, 0), 0, tputs_putchar); if (sh->prompt->x < window.col - 1) sh->prompt->x = -2; else sh->prompt->x = -1; while (sh->prompt->x++ < 0) tputs(tgoto((tgetstr("nd", NULL)), 0, 0), 0, tputs_putchar); sh->prompt->y = 1; }
void bonus_down(t_env* env) { tputs(tgoto(env->cm, env->bonusx, env->bonusy - 1), 1, id_put); id_print_char(' '); tputs(tgoto(env->cm, env->bonusx, env->bonusy), 1, id_put); id_print_char('#'); env->bonusy = env->bonusy + 1; if ( env->bonusy == env->h - 1) env->bonus = 0; }
FUNCTION CODE t_pos ( FUNINT line, /* in: line number (start at 1) */ /* -1 means use current line */ FUNINT column /* in: column number (start at 1) */ ) { FAST TEXT *cursor_string; #ifdef TERMINAL_TOL TEXT outstr[100]; /* formatted string for term. log */ #endif if ( line == 0xFFFFFFFF ) line = -1; if (ltype == T_CRT) { if (line < 0) { if (hcursor == NULL || creturn == NULL) { line = llines; /* go to screen bottom */ cursor_string = tgoto(cursor, column-1, line-1); tputs(cursor_string, 1, t_outc); } else /* use most recent line */ { tputs(creturn, 1, t_outc); if (column > 1) { cursor_string = tgoto(hcursor, 0, column-1); tputs(cursor_string, 1, t_outc); } } } else { cursor_string = tgoto(cursor, column-1, line-1); tputs(cursor_string, 1, t_outc); } } #ifdef TERMINAL_TOL if (term_log) { if (line < 0) line = 0; /* pick some reasonable number */ sprintf(outstr, "%%POS%02d%02d",line,column); /* format for %POSLLCC */ f_write(&tsf, outstr); } #endif return (SUCCESS); }
void ft_arrow_right(t_terminfo **info) { struct winsize w; ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); if ((*info)->pos_x == w.ws_col - 1) tputs(tgoto(tgetstr("do", NULL), 0, 0), 1, ft_int_putchar); else tputs(tgoto(tgetstr("nd", NULL), 0, 0), 1, ft_int_putchar); (*info)->pos_x++; if ((*info)->hl != 0 && (*info)->pos_x < (*info)->max_x) ft_ctrl_i(info); }
static void ft_space(sel_list *lalist, co_list *coord, char *pos) { tputs(tgetstr("ce", NULL), 1, ft_putc); tputs(tgoto(pos, (*coord).x, (*coord).y), 1, ft_putc); if ((*lalist).select == 0) { (*lalist).select = 1; tputs(tgetstr("mr", NULL), 1, ft_putc); tputs(tgetstr("us", NULL), 1, ft_putc); ft_putstr((*lalist).word); tputs(tgetstr("me", NULL), 1, ft_putc); tputs(tgoto(pos, (*coord).x, (*coord).y), 1, ft_putc); } }
/* * toggle displayed fields */ void change_fields(void) { int i, changed = 0; int row, col; char c, *p; char tmp[2] = " "; show_fields(); for (;;) { PUTP(tgoto(cm, 0, 0)); PUTP(top_clrtoeol); PUTP(tgoto(cm, 3, 0)); PUTP(mr); printf("Current Field Order: %s", Fields); PUTP(me); putchar('\n'); PUTP(tgoto(cm, 0, 1)); printf("Toggle fields with a-x, any other key to return: "); fflush(stdout); if (!Batch) { /* should always be true, but... */ tcsetattr(0, TCSAFLUSH, &Rawtty); read(0, &c, 1); tcsetattr(0, TCSAFLUSH, &Savetty); } i = toupper(c) - 'A'; if (i >= 0 && i < sizeof headers / sizeof headers[0]) { row = i % (Lines - 3) + 3; col = i / (Lines - 3) * 40; PUTP(tgoto(cm, col, row)); if ((p = strchr(Fields, i + 'A')) != NULL) { /* deselect Field */ *p = i + 'a'; putchar(' '); } else if ((p = strchr(Fields, i + 'a')) != NULL) { /* select previously */ *p = i + 'A'; /* deselected field */ putchar('*'); } else { /* select new field */ tmp[0] = i + 'A'; strcat(Fields, tmp); putchar('*'); } changed = 1; fflush(stdout); } else break; } if (changed) Numfields = make_header(); }
void wi_terminal_set_scroll(wi_terminal_t *terminal, wi_range_t range) { terminal->scroll = range; tputs(tgoto(terminal->cs, range.length, range.location), 0, _wi_terminal_putc); _wi_terminal_flush(); }
void ft_print_lst(t_lst **lst) { t_lst *tmp; int xy[2]; ft_bzero(xy, sizeof(int) * 2); tmp = *lst; if (((tgetnum("co") / (tmp->max_l + 3)) * tgetnum("li") < tmp->nbr_w)) print_word_fd("too small too print the argument list"); else { while (tmp->next != *lst) { while ((xy[1] < tgetnum("li")) && (tmp->next != *lst)) { tputs(tgoto(tgetstr("cm", NULL), xy[0], xy[1]++), 1, ft_putint); video_underl(tmp); tmp = tmp->next; } if (tmp->next != *lst) { xy[1] = 0; xy[0] = xy[0] + (tmp->max_l + 3); } } print_last_link(xy[1], xy[0], tmp); } }
void prompt(void) { int i; char *logname; char *pwd; char *home; i = 0; logname = NULL; pwd = NULL; home = NULL; tputs(tgoto(tgetstr("ch", NULL), 0, 0), 1, tputs_putchar); ft_putstr("\033[40m"); if ((logname = ft_getenv("LOGNAME"))) ft_putstr(logname); ft_putstr("\033[m\033[44m\033[30m"); if ((pwd = ft_getenv("PWD")) && (home = ft_getenv("HOME")) && !ft_strncmp(pwd, home, ft_strlen(home))) { ft_putstr("~"); i = ft_strlen(home); } if (pwd) ft_putstr(pwd + i); print_error(logname, pwd, home); }
static void tcapclose(void) { putpad(tgoto(CM, 0, term.t_nrow)); putpad(TE); tioflush(); tiorestore(); }
void ft_write_list(t_dlist *arg, t_dlist_node *node, struct termios term, t_dlist_node *ls_n) { arg->index = -1; arg->line = 0; arg->cur_col = 1; node = ft_write_start(arg, node, term); while (++arg->index != (int)arg->size) { if (tgetnum("li") <= 2) { ft_terminal_small(arg); break ; } ft_calc_size(arg, node); if (arg->cur_col + arg->size_col > tgetnum("co") && arg->cur_col != 1) { ft_terminal_small(arg); break ; } if (arg->line == 0 && arg->cur_col != 1) arg->size_col = 0; arg->line = ft_define_x_y(arg, node, arg->line, arg->cur_col); node = ft_write_line(arg, node); } tputs(tgoto(tgetstr("cm", NULL), ls_n->pos_x, ls_n->pos_y), 1, ft_putchar); if (arg->index == (int)arg->size) ft_underline(arg, ls_n); }
static TACommandVerdict tgoto_cmd(TAThread thread, TAInputStream stream) { char* cap; int col; int row; char* res; // Prepare cap = readString(&stream); col = readInt(&stream); row = readInt(&stream); START_TARGET_OPERATION(thread); // Execute res = tgoto(cap, col, row); END_TARGET_OPERATION(thread); // Response writePointer(thread, res); sendResponse(thread); return taDefaultVerdict; }
void apply_delete(t_historic **historic) { int win_size; t_comline *tmp; if ((*historic)->copy->comline->c != '\0') { tmp = (*historic)->copy->comline->right; (*historic)->copy->comline = (*historic)->copy->comline->left; (*historic)->copy->comline->right = tmp; if (tmp) tmp->left = (*historic)->copy->comline; if ((win_size = check_beginning((*historic)->copy->comline))) { 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->size--; edit_line(historic); update_linecol(historic); print_comline(historic); } }
/* * tstp: * Handle stop and start signals */ static void tstp(int dummy) { int y, x; y = cur_row; x = cur_col; mvcur(cur_row, cur_col, HEIGHT, 0); cur_row = HEIGHT; cur_col = 0; _puts(VE); _puts(TE); fflush(stdout); tcsetattr(0, TCSADRAIN, &__orig_termios); kill(getpid(), SIGSTOP); signal(SIGTSTP, tstp); tcsetattr(0, TCSADRAIN, &saved_tty); _puts(TI); _puts(VS); cur_row = y; cur_col = x; _puts(tgoto(CM, cur_row, cur_col)); display_redraw_screen(); fflush(stdout); }
int my_show_list(t_list *list, t_tools tool, char *command) { struct winsize argp; t_param par; par.length = 0; par.my_cmpt = 2; if ((list = my_keep_list(list)) == NULL) return (-1); tool = my_keep_tool(tool); argp = init_my_ioctl(); while (list && list->cmpt != 0) list = list->next; if (my_screen(argp, list) == -1 || (tputs(tgoto(tool.set_cursor, 0, 0), 1, &my_putchar_int)) == -1) return (-1); prompt(NULL); my_putstr(command); my_putchar('\n'); my_printer(&list, tool); while (list->cmpt != 0) { par.length = par.length + my_show(&list, tool, argp, par); if (par.my_cmpt == 2) par.my_cmpt = 1; } return (0); }
void apply_moveprev(t_historic **historic) { struct winsize size; t_comline *tmp; ioctl(0, TIOCGWINSZ, &size); tmp = (*historic)->copy->comline; if (tmp->c != '\0') { while (tmp->c != '\0' && tmp->c == ' ') tmp = tmp->left; while (tmp->c != '\0' && tmp->c != ' ') tmp = tmp->left; while ((*historic)->copy->comline->col != tmp->col) { (*historic)->copy->comline = (*historic)->copy->comline->left; if (check_beginning((*historic)->copy->comline)) { tputs(tgetstr("up", NULL), 1, aff_c); tputs(tgoto(tgetstr("ch", NULL), 0, size.ws_col), 1, aff_c); } else tputs(tgetstr("le", NULL), 1, aff_c); } } }
void ft_select_print(t_select *select, t_list *list) { t_list *cur; t_selector *selector; int y; int x; int index; y = 1; x = 0; index = 0; select->cols = 1; tputs(tgetstr("cl", NULL), 0, tputs_putchar); tputs(tgetstr("ho", NULL), 0, tputs_putchar); cur = ft_lstget_at(list, ft_selected_get_page_offset()); if (ft_select_get_max_words_by_page() == 0) ft_putstr_fd("Window size is too small", select->tty); while (cur && index < ft_select_get_max_words_by_page()) { selector = cur->content; ft_select_print_one(selector, index, &x, &y); y++; index++; cur = cur->next; } tputs(tgoto(tgetstr("cm", NULL), select->cursor_x, select->cursor_y), 1, tputs_putchar); }
void wi_terminal_move(wi_terminal_t *terminal, wi_point_t point) { terminal->location = point; tputs(tgoto(terminal->cm, point.x, point.y), 0, _wi_terminal_putc); _wi_terminal_flush(); }