📄 getline.c
字号:
{"M-5", "digit-argument"}, {"M-6", "digit-argument"}, {"M-7", "digit-argument"}, {"M-8", "digit-argument"}, {"M-9", "digit-argument"}, {"\r", "newline"}, {"\n", "newline"}, {"M-o", "repeat-history"}, {"M-C-v", "vi-mode"},};/* * Define the default key-bindings in vi mode. Note that in vi-mode * meta-key bindings are command-mode bindings. For example M-i first * switches to command mode if not already in that mode, then moves * the cursor one position right, as in vi. */static const KtKeyBinding gl_vi_bindings[] = { {"^D", "list-or-eof"}, {"^G", "list-glob"}, {"^H", "backward-delete-char"}, {"\t", "complete-word"}, {"\r", "newline"}, {"\n", "newline"}, {"^L", "clear-screen"}, {"^N", "down-history"}, {"^P", "up-history"}, {"^R", "redisplay"}, {"^U", "backward-kill-line"}, {"^W", "backward-delete-word"}, {"^X^F", "read-from-file"}, {"^X^R", "read-init-files"}, {"^X*", "expand-filename"}, {"^?", "backward-delete-char"}, {"M- ", "cursor-right"}, {"M-$", "end-of-line"}, {"M-*", "expand-filename"}, {"M-+", "down-history"}, {"M--", "up-history"}, {"M-<", "beginning-of-history"}, {"M->", "end-of-history"}, {"M-^", "beginning-of-line"}, {"M-;", "repeat-find-char"}, {"M-,", "invert-refind-char"}, {"M-|", "goto-column"}, {"M-~", "change-case"}, {"M-.", "vi-repeat-change"}, {"M-%", "find-parenthesis"}, {"M-0", "digit-argument"}, {"M-1", "digit-argument"}, {"M-2", "digit-argument"}, {"M-3", "digit-argument"}, {"M-4", "digit-argument"}, {"M-5", "digit-argument"}, {"M-6", "digit-argument"}, {"M-7", "digit-argument"}, {"M-8", "digit-argument"}, {"M-9", "digit-argument"}, {"M-a", "vi-append"}, {"M-A", "vi-append-at-eol"}, {"M-b", "backward-word"}, {"M-B", "backward-word"}, {"M-C", "vi-change-rest-of-line"}, {"M-cb", "vi-backward-change-word"}, {"M-cB", "vi-backward-change-word"}, {"M-cc", "vi-change-line"}, {"M-ce", "vi-forward-change-word"}, {"M-cE", "vi-forward-change-word"}, {"M-cw", "vi-forward-change-word"}, {"M-cW", "vi-forward-change-word"}, {"M-cF", "vi-backward-change-find"}, {"M-cf", "vi-forward-change-find"}, {"M-cT", "vi-backward-change-to"}, {"M-ct", "vi-forward-change-to"}, {"M-c;", "vi-change-refind"}, {"M-c,", "vi-change-invert-refind"}, {"M-ch", "vi-backward-change-char"}, {"M-c^H", "vi-backward-change-char"}, {"M-c^?", "vi-backward-change-char"}, {"M-cl", "vi-forward-change-char"}, {"M-c ", "vi-forward-change-char"}, {"M-c^", "vi-change-to-bol"}, {"M-c0", "vi-change-to-bol"}, {"M-c$", "vi-change-rest-of-line"}, {"M-c|", "vi-change-to-column"}, {"M-c%", "vi-change-to-parenthesis"}, {"M-dh", "backward-delete-char"}, {"M-d^H", "backward-delete-char"}, {"M-d^?", "backward-delete-char"}, {"M-dl", "forward-delete-char"}, {"M-d ", "forward-delete-char"}, {"M-dd", "delete-line"}, {"M-db", "backward-delete-word"}, {"M-dB", "backward-delete-word"}, {"M-de", "forward-delete-word"}, {"M-dE", "forward-delete-word"}, {"M-dw", "forward-delete-word"}, {"M-dW", "forward-delete-word"}, {"M-dF", "backward-delete-find"}, {"M-df", "forward-delete-find"}, {"M-dT", "backward-delete-to"}, {"M-dt", "forward-delete-to"}, {"M-d;", "delete-refind"}, {"M-d,", "delete-invert-refind"}, {"M-d^", "backward-kill-line"}, {"M-d0", "backward-kill-line"}, {"M-d$", "kill-line"}, {"M-D", "kill-line"}, {"M-d|", "delete-to-column"}, {"M-d%", "delete-to-parenthesis"}, {"M-e", "forward-word"}, {"M-E", "forward-word"}, {"M-f", "forward-find-char"}, {"M-F", "backward-find-char"}, {"M--", "up-history"}, {"M-h", "cursor-left"}, {"M-H", "beginning-of-history"}, {"M-i", "vi-insert"}, {"M-I", "vi-insert-at-bol"}, {"M-j", "down-history"}, {"M-J", "history-search-forward"}, {"M-k", "up-history"}, {"M-K", "history-search-backward"}, {"M-l", "cursor-right"}, {"M-L", "end-of-history"}, {"M-n", "history-re-search-forward"}, {"M-N", "history-re-search-backward"}, {"M-p", "append-yank"}, {"M-P", "yank"}, {"M-r", "vi-replace-char"}, {"M-R", "vi-overwrite"}, {"M-s", "vi-forward-change-char"}, {"M-S", "vi-change-line"}, {"M-t", "forward-to-char"}, {"M-T", "backward-to-char"}, {"M-u", "vi-undo"}, {"M-w", "forward-to-word"}, {"M-W", "forward-to-word"}, {"M-x", "forward-delete-char"}, {"M-X", "backward-delete-char"}, {"M-yh", "backward-copy-char"}, {"M-y^H", "backward-copy-char"}, {"M-y^?", "backward-copy-char"}, {"M-yl", "forward-copy-char"}, {"M-y ", "forward-copy-char"}, {"M-ye", "forward-copy-word"}, {"M-yE", "forward-copy-word"}, {"M-yw", "forward-copy-word"}, {"M-yW", "forward-copy-word"}, {"M-yb", "backward-copy-word"}, {"M-yB", "backward-copy-word"}, {"M-yf", "forward-copy-find"}, {"M-yF", "backward-copy-find"}, {"M-yt", "forward-copy-to"}, {"M-yT", "backward-copy-to"}, {"M-y;", "copy-refind"}, {"M-y,", "copy-invert-refind"}, {"M-y^", "copy-to-bol"}, {"M-y0", "copy-to-bol"}, {"M-y$", "copy-rest-of-line"}, {"M-yy", "copy-line"}, {"M-Y", "copy-line"}, {"M-y|", "copy-to-column"}, {"M-y%", "copy-to-parenthesis"}, {"M-^E", "emacs-mode"}, {"M-^H", "cursor-left"}, {"M-^?", "cursor-left"}, {"M-^L", "clear-screen"}, {"M-^N", "down-history"}, {"M-^P", "up-history"}, {"M-^R", "redisplay"}, {"M-^D", "list-or-eof"}, {"M-\r", "newline"}, {"M-\t", "complete-word"}, {"M-\n", "newline"}, {"M-^X^R", "read-init-files"}, {"M-^Xh", "list-history"}, {"M-^XH", "list-history"}, {"down", "down-history"}, {"up", "up-history"}, {"left", "cursor-left"}, {"right", "cursor-right"},};/*....................................................................... * Create a new GetLine object. * * Input: * linelen size_t The maximum line length to allow for. * histlen size_t The number of bytes to allocate for recording * a circular buffer of history lines. * Output: * return GetLine * The new object, or NULL on error. */GetLine *new_GetLine(size_t linelen, size_t histlen){ GetLine *gl; /* The object to be returned */ int i;/* * Check the arguments. */ if(linelen < 10) { fprintf(stderr, "new_GetLine: Line length too small.\n"); return NULL; };/* * Allocate the container. */ gl = (GetLine *) malloc(sizeof(GetLine)); if(!gl) { fprintf(stderr, "new_GetLine: Insufficient memory.\n"); return NULL; };/* * Before attempting any operation that might fail, initialize the * container at least up to the point at which it can safely be passed * to del_GetLine(). */ gl->glh = NULL; gl->cpl = NULL; gl->cpl_fn = cpl_file_completions; gl->cpl_data = NULL; gl->ef = NULL; gl->capmem = NULL; gl->term = NULL; gl->is_term = 0; gl->is_net = 0; gl->net_may_block = 0; gl->net_read_attempt = 0; gl->nkey = 0; gl->user_event_value = 0; gl->input_fd = -1; gl->output_fd = -1; gl->input_fp = NULL; gl->output_fp = NULL; gl->file_fp = NULL; gl->linelen = linelen; gl->line = NULL; gl->cutbuf = NULL; gl->linelen = linelen; gl->prompt = ""; gl->prompt_len = 0; gl->prompt_changed = 0; gl->prompt_style = GL_LITERAL_PROMPT; gl->vi.undo.line = NULL; gl->vi.undo.buff_curpos = 0; gl->vi.undo.ntotal = 0; gl->vi.undo.saved = 0; gl->vi.repeat.fn = 0; gl->vi.repeat.count = 0; gl->vi.repeat.input_curpos = 0; gl->vi.repeat.command_curpos = 0; gl->vi.repeat.input_char = '\0'; gl->vi.repeat.saved = 0; gl->vi.repeat.active = 0; gl->sig_mem = NULL; gl->sigs = NULL;#ifndef __MINGW32__ sigemptyset(&gl->old_signal_set); sigemptyset(&gl->new_signal_set);#endif gl->bindings = NULL; gl->ntotal = 0; gl->buff_curpos = 0; gl->term_curpos = 0; gl->buff_mark = 0; gl->insert_curpos = 0; gl->insert = 1; gl->number = -1; gl->endline = 0; gl->current_fn = 0; gl->current_count = 0; gl->preload_id = 0; gl->preload_history = 0; gl->keyseq_count = 0; gl->last_search = -1; gl->editor = GL_EMACS_MODE; gl->silence_bell = 0; gl->vi.command = 0; gl->vi.find_forward = 0; gl->vi.find_onto = 0; gl->vi.find_char = '\0'; gl->left = NULL; gl->right = NULL; gl->up = NULL; gl->down = NULL; gl->home = NULL; gl->bol = 0; gl->clear_eol = NULL; gl->clear_eod = NULL; gl->u_arrow = NULL; gl->d_arrow = NULL; gl->l_arrow = NULL; gl->r_arrow = NULL; gl->sound_bell = NULL; gl->bold = NULL; gl->underline = NULL; gl->standout = NULL; gl->dim = NULL; gl->reverse = NULL; gl->blink = NULL; gl->text_attr_off = NULL; gl->nline = 0; gl->ncolumn = 0;#ifdef USE_TERMINFO gl->left_n = NULL; gl->right_n = NULL;#elif defined(USE_TERMCAP) gl->tgetent_buf = NULL; gl->tgetstr_buf = NULL;#endif gl->app_file = NULL; gl->user_file = NULL; gl->configured = 0; gl->echo = 1; gl->last_signal = -1;#ifdef HAVE_SELECT gl->fd_node_mem = NULL; gl->fd_nodes = NULL; FD_ZERO(&gl->rfds); FD_ZERO(&gl->wfds); FD_ZERO(&gl->ufds); gl->max_fd = 0;#endif/* * Allocate the history buffer. */ gl->glh = _new_GlHistory(histlen); if(!gl->glh) return del_GetLine(gl);/* * Allocate the resource object for file-completion. */ gl->cpl = new_WordCompletion(); if(!gl->cpl) return del_GetLine(gl);/* * Allocate the resource object for file-completion. */ gl->ef = new_ExpandFile(); if(!gl->ef) return del_GetLine(gl);/* * Allocate a string-segment memory allocator for use in storing terminal * capablity strings. */ gl->capmem = _new_StringGroup(CAPMEM_SEGMENT_SIZE); if(!gl->capmem) return del_GetLine(gl);/* * Allocate a line buffer, leaving 2 extra characters for the terminating * '\n' and '\0' characters */ gl->line = (char *) malloc(linelen + 2); if(!gl->line) { fprintf(stderr, "new_GetLine: Insufficient memory to allocate line buffer.\n"); return del_GetLine(gl); }; gl->line[0] = '\0';/* * Allocate a cut buffer. */ gl->cutbuf = (char *) malloc(linelen + 2); if(!gl->cutbuf) { fprintf(stderr, "new_GetLine: Insufficient memory to allocate cut buffer.\n"); return del_GetLine(gl); }; gl->cutbuf[0] = '\0';/* * Allocate a vi undo buffer. */ gl->vi.undo.line = (char *) malloc(linelen + 2); if(!gl->vi.undo.line) { fprintf(stderr,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -