📄 common.c
字号:
/*ARGSUSED*/ed_tty_dsusp(EditLine *el __attribute__((__unused__)), int c __attribute__((__unused__))){ return (CC_NORM);}/* ed_tty_flush_output(): * Tty flush output characters * [^O] */protected el_action_t/*ARGSUSED*/ed_tty_flush_output(EditLine *el __attribute__((__unused__)), int c __attribute__((__unused__))){ return (CC_NORM);}/* ed_tty_sigquit(): * Tty quit character * [^\] */protected el_action_t/*ARGSUSED*/ed_tty_sigquit(EditLine *el __attribute__((__unused__)), int c __attribute__((__unused__))){ return (CC_NORM);}/* ed_tty_sigtstp(): * Tty suspend character * [^Z] */protected el_action_t/*ARGSUSED*/ed_tty_sigtstp(EditLine *el __attribute__((__unused__)), int c __attribute__((__unused__))){ return (CC_NORM);}/* ed_tty_stop_output(): * Tty disallow output characters * [^S] */protected el_action_t/*ARGSUSED*/ed_tty_stop_output(EditLine *el __attribute__((__unused__)), int c __attribute__((__unused__))){ return (CC_NORM);}/* ed_tty_start_output(): * Tty allow output characters * [^Q] */protected el_action_t/*ARGSUSED*/ed_tty_start_output(EditLine *el __attribute__((__unused__)), int c __attribute__((__unused__))){ return (CC_NORM);}/* ed_newline(): * Execute command * [^J] */protected el_action_t/*ARGSUSED*/ed_newline(EditLine *el, int c __attribute__((__unused__))){ re_goto_bottom(el); *el->el_line.lastchar++ = '\n'; *el->el_line.lastchar = '\0'; return (CC_NEWLINE);}/* ed_delete_prev_char(): * Delete the character to the left of the cursor * [^?] */protected el_action_t/*ARGSUSED*/ed_delete_prev_char(EditLine *el, int c __attribute__((__unused__))){ if (el->el_line.cursor <= el->el_line.buffer) return (CC_ERROR); c_delbefore(el, el->el_state.argument); el->el_line.cursor -= el->el_state.argument; if (el->el_line.cursor < el->el_line.buffer) el->el_line.cursor = el->el_line.buffer; return (CC_REFRESH);}/* ed_clear_screen(): * Clear screen leaving current line at the top * [^L] */protected el_action_t/*ARGSUSED*/ed_clear_screen(EditLine *el, int c __attribute__((__unused__))){ term_clear_screen(el); /* clear the whole real screen */ re_clear_display(el); /* reset everything */ return (CC_REFRESH);}/* ed_redisplay(): * Redisplay everything * ^R */protected el_action_t/*ARGSUSED*/ed_redisplay(EditLine *el __attribute__((__unused__)), int c __attribute__((__unused__))){ return (CC_REDISPLAY);}/* ed_start_over(): * Erase current line and start from scratch * [^G] */protected el_action_t/*ARGSUSED*/ed_start_over(EditLine *el, int c __attribute__((__unused__))){ ch_reset(el); return (CC_REFRESH);}/* ed_sequence_lead_in(): * First character in a bound sequence * Placeholder for external keys */protected el_action_t/*ARGSUSED*/ed_sequence_lead_in(EditLine *el __attribute__((__unused__)), int c __attribute__((__unused__))){ return (CC_NORM);}/* ed_prev_history(): * Move to the previous history line * [^P] [k] */protected el_action_t/*ARGSUSED*/ed_prev_history(EditLine *el, int c __attribute__((__unused__))){ char beep = 0; int sv_event = el->el_history.eventno; el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ if (el->el_history.eventno == 0) { /* save the current buffer * away */ (void) strncpy(el->el_history.buf, el->el_line.buffer, EL_BUFSIZ); el->el_history.last = el->el_history.buf + (el->el_line.lastchar - el->el_line.buffer); } el->el_history.eventno += el->el_state.argument; if (hist_get(el) == CC_ERROR) { if (el->el_map.type == MAP_VI) { el->el_history.eventno = sv_event; return CC_ERROR; } beep = 1; /* el->el_history.eventno was fixed by first call */ (void) hist_get(el); } if (beep) return CC_REFRESH_BEEP; return CC_REFRESH;}/* ed_next_history(): * Move to the next history line * [^N] [j] */protected el_action_t/*ARGSUSED*/ed_next_history(EditLine *el, int c __attribute__((__unused__))){ el_action_t beep = CC_REFRESH, rval; el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ el->el_history.eventno -= el->el_state.argument; if (el->el_history.eventno < 0) { el->el_history.eventno = 0; beep = CC_REFRESH_BEEP; } rval = hist_get(el); if (rval == CC_REFRESH) return beep; return rval;}/* ed_search_prev_history(): * Search previous in history for a line matching the current * next search history [M-P] [K] */protected el_action_t/*ARGSUSED*/ed_search_prev_history(EditLine *el, int c __attribute__((__unused__))){ const char *hp; int h; bool_t found = 0; el->el_chared.c_vcmd.action = NOP; el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ if (el->el_history.eventno < 0) {#ifdef DEBUG_EDIT (void) fprintf(el->el_errfile, "e_prev_search_hist(): eventno < 0;\n");#endif el->el_history.eventno = 0; return (CC_ERROR); } if (el->el_history.eventno == 0) { (void) strncpy(el->el_history.buf, el->el_line.buffer, EL_BUFSIZ); el->el_history.last = el->el_history.buf + (el->el_line.lastchar - el->el_line.buffer); } if (el->el_history.ref == NULL) return (CC_ERROR); hp = HIST_FIRST(el); if (hp == NULL) return (CC_ERROR); c_setpat(el); /* Set search pattern !! */ for (h = 1; h <= el->el_history.eventno; h++) hp = HIST_NEXT(el); while (hp != NULL) {#ifdef SDEBUG (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);#endif if ((strncmp(hp, el->el_line.buffer, (size_t) (el->el_line.lastchar - el->el_line.buffer)) || hp[el->el_line.lastchar - el->el_line.buffer]) && c_hmatch(el, hp)) { found++; break; } h++; hp = HIST_NEXT(el); } if (!found) {#ifdef SDEBUG (void) fprintf(el->el_errfile, "not found\n");#endif return (CC_ERROR); } el->el_history.eventno = h; return (hist_get(el));}/* ed_search_next_history(): * Search next in history for a line matching the current * [M-N] [J] */protected el_action_t/*ARGSUSED*/ed_search_next_history(EditLine *el, int c __attribute__((__unused__))){ const char *hp; int h; bool_t found = 0; el->el_chared.c_vcmd.action = NOP; el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ if (el->el_history.eventno == 0) return (CC_ERROR); if (el->el_history.ref == NULL) return (CC_ERROR); hp = HIST_FIRST(el); if (hp == NULL) return (CC_ERROR); c_setpat(el); /* Set search pattern !! */ for (h = 1; h < el->el_history.eventno && hp; h++) {#ifdef SDEBUG (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);#endif if ((strncmp(hp, el->el_line.buffer, (size_t) (el->el_line.lastchar - el->el_line.buffer)) || hp[el->el_line.lastchar - el->el_line.buffer]) && c_hmatch(el, hp)) found = h; hp = HIST_NEXT(el); } if (!found) { /* is it the current history number? */ if (!c_hmatch(el, el->el_history.buf)) {#ifdef SDEBUG (void) fprintf(el->el_errfile, "not found\n");#endif return (CC_ERROR); } } el->el_history.eventno = found; return (hist_get(el));}/* ed_prev_line(): * Move up one line * Could be [k] [^p] */protected el_action_t/*ARGSUSED*/ed_prev_line(EditLine *el, int c __attribute__((__unused__))){ char *ptr; int nchars = c_hpos(el); /* * Move to the line requested */ if (*(ptr = el->el_line.cursor) == '\n') ptr--; for (; ptr >= el->el_line.buffer; ptr--) if (*ptr == '\n' && --el->el_state.argument <= 0) break; if (el->el_state.argument > 0) return (CC_ERROR); /* * Move to the beginning of the line */ for (ptr--; ptr >= el->el_line.buffer && *ptr != '\n'; ptr--) continue; /* * Move to the character requested */ for (ptr++; nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n'; ptr++) continue; el->el_line.cursor = ptr; return (CC_CURSOR);}/* ed_next_line(): * Move down one line * Could be [j] [^n] */protected el_action_t/*ARGSUSED*/ed_next_line(EditLine *el, int c __attribute__((__unused__))){ char *ptr; int nchars = c_hpos(el); /* * Move to the line requested */ for (ptr = el->el_line.cursor; ptr < el->el_line.lastchar; ptr++) if (*ptr == '\n' && --el->el_state.argument <= 0) break; if (el->el_state.argument > 0) return (CC_ERROR); /* * Move to the character requested */ for (ptr++; nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n'; ptr++) continue; el->el_line.cursor = ptr; return (CC_CURSOR);}/* ed_command(): * Editline extended command * [M-X] [:] */protected el_action_t/*ARGSUSED*/ed_command(EditLine *el, int c __attribute__((__unused__))){ char tmpbuf[EL_BUFSIZ]; int tmplen; tmplen = c_gets(el, tmpbuf, "\n: "); term__putc('\n'); if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1) term_beep(el); el->el_map.current = el->el_map.key; re_clear_display(el); return CC_REFRESH;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -