📄 term.c
字号:
* Reset arrow key bindings */private voidterm_reset_arrow(el) EditLine *el;{ fkey_t *arrow = el->el_term.t_fkey; static char strA[] = {033, '[', 'A', '\0'}; static char strB[] = {033, '[', 'B', '\0'}; static char strC[] = {033, '[', 'C', '\0'}; static char strD[] = {033, '[', 'D', '\0'}; static char stOA[] = {033, 'O', 'A', '\0'}; static char stOB[] = {033, 'O', 'B', '\0'}; static char stOC[] = {033, 'O', 'C', '\0'}; static char stOD[] = {033, 'O', 'D', '\0'}; key_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type); key_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type); key_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type); key_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type); key_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type); key_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type); key_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type); key_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type); if (el->el_map.type == MAP_VI) { key_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type); key_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type); key_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type); key_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type); key_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type); key_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type); key_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type); key_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type); }}/* term_set_arrow(): * Set an arrow key binding */protected intterm_set_arrow(el, name, fun, type) EditLine *el; char *name; key_value_t *fun; int type;{ fkey_t *arrow = el->el_term.t_fkey; int i; for (i = 0; i < A_K_NKEYS; i++) if (strcmp(name, arrow[i].name) == 0) { arrow[i].fun = *fun; arrow[i].type = type; return 0; } return -1;}/* term_clear_arrow(): * Clear an arrow key binding */protected intterm_clear_arrow(el, name) EditLine *el; char *name;{ fkey_t *arrow = el->el_term.t_fkey; int i; for (i = 0; i < A_K_NKEYS; i++) if (strcmp(name, arrow[i].name) == 0) { arrow[i].type = XK_NOD; return 0; } return -1;}/* term_print_arrow(): * Print the arrow key bindings */protected voidterm_print_arrow(el, name) EditLine *el; char *name;{ int i; fkey_t *arrow = el->el_term.t_fkey; for (i = 0; i < A_K_NKEYS; i++) if (*name == '\0' || strcmp(name, arrow[i].name) == 0) if (arrow[i].type != XK_NOD) key_kprint(el, arrow[i].name, &arrow[i].fun, arrow[i].type);}/* term_bind_arrow(): * Bind the arrow keys */protected voidterm_bind_arrow(el) EditLine *el;{ el_action_t *map, *dmap; int i, j; char *p; fkey_t *arrow = el->el_term.t_fkey; /* Check if the components needed are initialized */ if (el->el_term.t_buf == NULL || el->el_map.key == NULL) return; map = el->el_map.type == MAP_VI ? el->el_map.alt : el->el_map.key; dmap = el->el_map.type == MAP_VI ? el->el_map.vic : el->el_map.emacs; term_reset_arrow(el); for (i = 0; i < 4; i++) { p = el->el_term.t_str[arrow[i].key]; if (p && *p) { j = (unsigned char) *p; /* * Assign the arrow keys only if: * * 1. They are multi-character arrow keys and the user * has not re-assigned the leading character, or * has re-assigned the leading character to be * ED_SEQUENCE_LEAD_IN * 2. They are single arrow keys pointing to an unassigned key. */ if (arrow[i].type == XK_NOD) key_clear(el, map, p); else { if (p[1] && (dmap[j] == map[j] || map[j] == ED_SEQUENCE_LEAD_IN)) { key_add(el, p, &arrow[i].fun, arrow[i].type); map[j] = ED_SEQUENCE_LEAD_IN; } else if (map[j] == ED_UNASSIGNED) { key_clear(el, map, p); if (arrow[i].type == XK_CMD) map[j] = arrow[i].fun.cmd; else key_add(el, p, &arrow[i].fun, arrow[i].type); } } } }}/* term__putc(): * Add a character */protected voidterm__putc(c) int c;{ (void) fputc(c, term_outfile);} /* end term__putc *//* term__flush(): * Flush output */protected voidterm__flush(){ (void) fflush(term_outfile);} /* end term__flush *//* term_telltc(): * Print the current termcap characteristics */protected int/*ARGSUSED*/term_telltc(el, argc, argv) EditLine *el; int argc; char **argv;{ struct termcapstr *t; char **ts; char upbuf[EL_BUFSIZ]; (void) fprintf(el->el_outfile, "\n\tYour terminal has the\n"); (void) fprintf(el->el_outfile, "\tfollowing characteristics:\n\n"); (void) fprintf(el->el_outfile, "\tIt has %d columns and %d lines\n", Val(T_co), Val(T_li)); (void) fprintf(el->el_outfile, "\tIt has %s meta key\n", EL_HAS_META ? "a" : "no"); (void) fprintf(el->el_outfile, "\tIt can%suse tabs\n", EL_CAN_TAB ? " " : "not ");#ifdef notyet (void) fprintf(el->el_outfile, "\tIt %s automatic margins\n", (T_Margin&MARGIN_AUTO)? "has": "does not have"); if (T_Margin & MARGIN_AUTO) (void) fprintf(el->el_outfile, "\tIt %s magic margins\n", (T_Margin&MARGIN_MAGIC)?"has":"does not have");#endif for (t = tstr, ts = el->el_term.t_str; t->name != NULL; t++, ts++) (void) fprintf(el->el_outfile, "\t%25s (%s) == %s\n", t->long_name, t->name, *ts && **ts ? key__decode_str(*ts, upbuf, "") : "(empty)"); (void) fputc('\n', el->el_outfile); return 0;}/* term_settc(): * Change the current terminal characteristics */protected int/*ARGSUSED*/term_settc(el, argc, argv) EditLine *el; int argc; char **argv;{ struct termcapstr *ts; struct termcapval *tv; char *what, *how; if (argv == NULL || argv[1] == NULL || argv[2] == NULL) return -1; what = argv[1]; how = argv[2]; /* * Do the strings first */ for (ts = tstr; ts->name != NULL; ts++) if (strcmp(ts->name, what) == 0) break; if (ts->name != NULL) { term_alloc(el, ts, how); term_setflags(el); return 0; } /* * Do the numeric ones second */ for (tv = tval; tv->name != NULL; tv++) if (strcmp(tv->name, what) == 0) break; if (tv->name != NULL) { if (tv == &tval[T_pt] || tv == &tval[T_km] #ifdef notyet || tv == &tval[T_am] || tv == &tval[T_xn]#endif ) { if (strcmp(how, "yes") == 0) el->el_term.t_val[tv - tval] = 1; else if (strcmp(how, "no") == 0) el->el_term.t_val[tv - tval] = 0; else { (void) fprintf(el->el_errfile, "settc: Bad value `%s'.\n", how); return -1; } term_setflags(el); term_change_size(el, Val(T_li), Val(T_co)); return 0; } else { el->el_term.t_val[tv - tval] = atoi(how); el->el_term.t_size.v = Val(T_co); el->el_term.t_size.h = Val(T_li); if (tv == &tval[T_co] || tv == &tval[T_li]) term_change_size(el, Val(T_li), Val(T_co)); return 0; } } return -1;}/* term_echotc(): * Print the termcap string out with variable substitution */protected int/*ARGSUSED*/term_echotc(el, argc, argv) EditLine *el; int argc; char **argv;{ char *cap, *scap; int arg_need, arg_cols, arg_rows; int verbose = 0, silent = 0; char *area; static char *fmts = "%s\n", *fmtd = "%d\n"; struct termcapstr *t; char buf[TC_BUFSIZE]; area = buf; if (argv == NULL || argv[1] == NULL) return -1; argv++; if (argv[0][0] == '-') { switch (argv[0][1]) { case 'v': verbose = 1; break; case 's': silent = 1; break; default: /* stderror(ERR_NAME | ERR_TCUSAGE); */ break; } argv++; } if (!*argv || *argv[0] == '\0') return 0; if (strcmp(*argv, "tabs") == 0) { (void) fprintf(el->el_outfile, fmts, EL_CAN_TAB ? "yes" : "no"); return 0; } else if (strcmp(*argv, "meta") == 0) { (void) fprintf(el->el_outfile, fmts, Val(T_km) ? "yes" : "no"); return 0; }#ifdef notyet else if (strcmp(*argv, "xn") == 0) { (void) fprintf(el->el_outfile, fmts, T_Margin & MARGIN_MAGIC ? "yes" : "no"); return 0; } else if (strcmp(*argv, "am") == 0) { (void) fprintf(el->el_outfile, fmts, T_Margin & MARGIN_AUTO ? "yes" : "no"); return 0; }#endif else if (strcmp(*argv, "baud") == 0) { int i; for (i = 0; baud_rate[i].b_name != NULL; i++) if (el->el_tty.t_speed == baud_rate[i].b_rate) { (void) fprintf(el->el_outfile, fmts, baud_rate[i].b_name); return 0; } (void) fprintf(el->el_outfile, fmtd, 0); return 0; } else if (strcmp(*argv, "rows") == 0 || strcmp(*argv, "lines") == 0) { (void) fprintf(el->el_outfile, fmtd, Val(T_li)); return 0; } else if (strcmp(*argv, "cols") == 0) { (void) fprintf(el->el_outfile, fmtd, Val(T_co)); return 0; } /* * Try to use our local definition first */ scap = NULL; for (t = tstr; t->name != NULL; t++) if (strcmp(t->name, *argv) == 0) { scap = el->el_term.t_str[t - tstr]; break; } if (t->name == NULL) scap = tgetstr(*argv, &area); if (!scap || scap[0] == '\0') { if (!silent) (void) fprintf(el->el_errfile, "echotc: Termcap parameter `%s' not found.\n", *argv); return -1; } /* * Count home many values we need for this capability. */ for (cap = scap, arg_need = 0; *cap; cap++) if (*cap == '%') switch (*++cap) { case 'd': case '2': case '3': case '.': case '+': arg_need++; break; case '%': case '>': case 'i': case 'r': case 'n': case 'B': case 'D': break; default: /* * hpux has lot's of them... */ if (verbose) (void) fprintf(el->el_errfile, "echotc: Warning: unknown termcap %% `%c'.\n", *cap); /* This is bad, but I won't complain */ break; } switch (arg_need) { case 0: argv++; if (*argv && *argv[0]) { if (!silent) (void) fprintf(el->el_errfile, "echotc: Warning: Extra argument `%s'.\n", *argv); return -1; } (void) tputs(scap, 1, term__putc); break; case 1: argv++; if (!*argv || *argv[0] == '\0') { if (!silent) (void) fprintf(el->el_errfile, "echotc: Warning: Missing argument.\n"); return -1; } arg_cols = 0; arg_rows = atoi(*argv); argv++; if (*argv && *argv[0]) { if (!silent) (void) fprintf(el->el_errfile, "echotc: Warning: Extra argument `%s'.\n", *argv); return -1; } (void) tputs(tgoto(scap, arg_cols, arg_rows), 1, term__putc); break; default: /* This is wrong, but I will ignore it... */ if (verbose) (void) fprintf(el->el_errfile, "echotc: Warning: Too many required arguments (%d).\n", arg_need); /*FALLTHROUGH*/ case 2: argv++; if (!*argv || *argv[0] == '\0') { if (!silent) (void) fprintf(el->el_errfile, "echotc: Warning: Missing argument.\n"); return -1; } arg_cols = atoi(*argv); argv++; if (!*argv || *argv[0] == '\0') { if (!silent) (void) fprintf(el->el_errfile, "echotc: Warning: Missing argument.\n"); return -1; } arg_rows = atoi(*argv); argv++; if (*argv && *argv[0]) { if (!silent) (void) fprintf(el->el_errfile, "echotc: Warning: Extra argument `%s'.\n", *argv); return -1; } (void) tputs(tgoto(scap, arg_cols, arg_rows), arg_rows, term__putc); break; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -