?? display.c
字號:
/* Since _rl_backspace() doesn't know about invisible characters in the prompt, and there's no good way to tell it, we compensate for those characters here and call _rl_backspace() directly. */ if (wrap_offset && cursor_linenum == 0 && nleft < _rl_last_c_pos) { _rl_backspace (_rl_last_c_pos - nleft); if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) _rl_last_c_pos = _rl_col_width (&visible_line[pos], 0, nleft); else _rl_last_c_pos = nleft; } if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) _rl_move_cursor_relative (nleft, &invisible_line[pos]); else if (nleft != _rl_last_c_pos) _rl_move_cursor_relative (nleft, &invisible_line[pos]); } } else /* Do horizontal scrolling. */ {#define M_OFFSET(margin, offset) ((margin) == 0 ? offset : 0) int lmargin, ndisp, nleft, phys_c_pos, t; /* Always at top line. */ _rl_last_v_pos = 0; /* Compute where in the buffer the displayed line should start. This will be LMARGIN. */ /* The number of characters that will be displayed before the cursor. */ ndisp = c_pos - wrap_offset; nleft = prompt_visible_length + wrap_offset; /* Where the new cursor position will be on the screen. This can be longer than SCREENWIDTH; if it is, lmargin will be adjusted. */ phys_c_pos = c_pos - (last_lmargin ? last_lmargin : wrap_offset); t = _rl_screenwidth / 3; /* If the number of characters had already exceeded the screenwidth, last_lmargin will be > 0. */ /* If the number of characters to be displayed is more than the screen width, compute the starting offset so that the cursor is about two-thirds of the way across the screen. */ if (phys_c_pos > _rl_screenwidth - 2) { lmargin = c_pos - (2 * t); if (lmargin < 0) lmargin = 0; /* If the left margin would be in the middle of a prompt with invisible characters, don't display the prompt at all. */ if (wrap_offset && lmargin > 0 && lmargin < nleft) lmargin = nleft; } else if (ndisp < _rl_screenwidth - 2) /* XXX - was -1 */ lmargin = 0; else if (phys_c_pos < 1) { /* If we are moving back towards the beginning of the line and the last margin is no longer correct, compute a new one. */ lmargin = ((c_pos - 1) / t) * t; /* XXX */ if (wrap_offset && lmargin > 0 && lmargin < nleft) lmargin = nleft; } else lmargin = last_lmargin; /* If the first character on the screen isn't the first character in the display line, indicate this with a special character. */ if (lmargin > 0) line[lmargin] = '<'; /* If SCREENWIDTH characters starting at LMARGIN do not encompass the whole line, indicate that with a special character at the right edge of the screen. If LMARGIN is 0, we need to take the wrap offset into account. */ t = lmargin + M_OFFSET (lmargin, wrap_offset) + _rl_screenwidth; if (t < out) line[t - 1] = '>'; if (!rl_display_fixed || forced_display || lmargin != last_lmargin) { forced_display = 0; update_line (&visible_line[last_lmargin], &invisible_line[lmargin], 0, _rl_screenwidth + visible_wrap_offset, _rl_screenwidth + (lmargin ? 0 : wrap_offset), 0); /* If the visible new line is shorter than the old, but the number of invisible characters is greater, and we are at the end of the new line, we need to clear to eol. */ t = _rl_last_c_pos - M_OFFSET (lmargin, wrap_offset); if ((M_OFFSET (lmargin, wrap_offset) > visible_wrap_offset) && (_rl_last_c_pos == out) && t < visible_first_line_len) { nleft = _rl_screenwidth - t; _rl_clear_to_eol (nleft); } visible_first_line_len = out - lmargin - M_OFFSET (lmargin, wrap_offset); if (visible_first_line_len > _rl_screenwidth) visible_first_line_len = _rl_screenwidth; _rl_move_cursor_relative (c_pos - lmargin, &invisible_line[lmargin]); last_lmargin = lmargin; } } fflush (rl_outstream); /* Swap visible and non-visible lines. */ { char *vtemp = visible_line; int *itemp = vis_lbreaks, ntemp = vis_lbsize; visible_line = invisible_line; invisible_line = vtemp; vis_lbreaks = inv_lbreaks; inv_lbreaks = itemp; vis_lbsize = inv_lbsize; inv_lbsize = ntemp; rl_display_fixed = 0; /* If we are displaying on a single line, and last_lmargin is > 0, we are not displaying any invisible characters, so set visible_wrap_offset to 0. */ if (_rl_horizontal_scroll_mode && last_lmargin) visible_wrap_offset = 0; else visible_wrap_offset = wrap_offset; }}/* PWP: update_line() is based on finding the middle difference of each line on the screen; vis: /old first difference /beginning of line | /old last same /old EOL v v v vold: eddie> Oh, my little gruntle-buggy is to me, as lurgid asnew: eddie> Oh, my little buggy says to me, as lurgid as ^ ^ ^ ^ \beginning of line | \new last same \new end of line \new first difference All are character pointers for the sake of speed. Special cases for no differences, as well as for end of line additions must be handled. Could be made even smarter, but this works well enough */static voidupdate_line (old, new, current_line, omax, nmax, inv_botlin) register char *old, *new; int current_line, omax, nmax, inv_botlin;{ register char *ofd, *ols, *oe, *nfd, *nls, *ne; int temp, lendiff, wsatend, od, nd; int current_invis_chars; int col_lendiff, col_temp;#if defined (HANDLE_MULTIBYTE) mbstate_t ps_new, ps_old; int new_offset, old_offset, tmp;#endif /* If we're at the right edge of a terminal that supports xn, we're ready to wrap around, so do so. This fixes problems with knowing the exact cursor position and cut-and-paste with certain terminal emulators. In this calculation, TEMP is the physical screen position of the cursor. */ temp = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset); if (temp == _rl_screenwidth && _rl_term_autowrap && !_rl_horizontal_scroll_mode && _rl_last_v_pos == current_line - 1) {#if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) { wchar_t wc; mbstate_t ps; int tempwidth, bytes; size_t ret; /* This fixes only double-column characters, but if the wrapped character comsumes more than three columns, spaces will be inserted in the string buffer. */ if (_rl_wrapped_line[current_line] > 0) _rl_clear_to_eol (_rl_wrapped_line[current_line]); memset (&ps, 0, sizeof (mbstate_t)); ret = mbrtowc (&wc, new, MB_CUR_MAX, &ps); if (ret == (size_t)-1 || ret == (size_t)-2) { tempwidth = 1; ret = 1; } else if (ret == 0) tempwidth = 0; else tempwidth = wcwidth (wc); if (tempwidth > 0) { int count; bytes = ret; for (count = 0; count < bytes; count++) putc (new[count], rl_outstream); _rl_last_c_pos = tempwidth; _rl_last_v_pos++; memset (&ps, 0, sizeof (mbstate_t)); ret = mbrtowc (&wc, old, MB_CUR_MAX, &ps); if (ret != 0 && bytes != 0) { if (ret == (size_t)-1 || ret == (size_t)-2) memmove (old+bytes, old+1, strlen (old+1)); else memmove (old+bytes, old+ret, strlen (old+ret)); memcpy (old, new, bytes); } } else { putc (' ', rl_outstream); _rl_last_c_pos = 1; _rl_last_v_pos++; if (old[0] && new[0]) old[0] = new[0]; } } else#endif { if (new[0]) putc (new[0], rl_outstream); else putc (' ', rl_outstream); _rl_last_c_pos = 1; /* XXX */ _rl_last_v_pos++; if (old[0] && new[0]) old[0] = new[0]; } } /* Find first difference. */#if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) { memset (&ps_new, 0, sizeof(mbstate_t)); memset (&ps_old, 0, sizeof(mbstate_t)); new_offset = old_offset = 0; for (ofd = old, nfd = new; (ofd - old < omax) && *ofd && _rl_compare_chars(old, old_offset, &ps_old, new, new_offset, &ps_new); ) { old_offset = _rl_find_next_mbchar (old, old_offset, 1, MB_FIND_ANY); new_offset = _rl_find_next_mbchar (new, new_offset, 1, MB_FIND_ANY); ofd = old + old_offset; nfd = new + new_offset; } } else#endif for (ofd = old, nfd = new; (ofd - old < omax) && *ofd && (*ofd == *nfd); ofd++, nfd++) ; /* Move to the end of the screen line. ND and OD are used to keep track of the distance between ne and new and oe and old, respectively, to move a subtraction out of each loop. */ for (od = ofd - old, oe = ofd; od < omax && *oe; oe++, od++); for (nd = nfd - new, ne = nfd; nd < nmax && *ne; ne++, nd++); /* If no difference, continue to next line. */ if (ofd == oe && nfd == ne) return; wsatend = 1; /* flag for trailing whitespace */#if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) { ols = old + _rl_find_prev_mbchar (old, oe - old, MB_FIND_ANY); nls = new + _rl_find_prev_mbchar (new, ne - new, MB_FIND_ANY); while ((ols > ofd) && (nls > nfd)) { memset (&ps_old, 0, sizeof (mbstate_t)); memset (&ps_new, 0, sizeof (mbstate_t)); _rl_adjust_point (old, ols - old, &ps_old); _rl_adjust_point (new, nls - new, &ps_new); if (_rl_compare_chars (old, ols - old, &ps_old, new, nls - new, &ps_new) == 0) break; if (*ols == ' ') wsatend = 0; ols = old + _rl_find_prev_mbchar (old, ols - old, MB_FIND_ANY); nls = new + _rl_find_prev_mbchar (new, nls - new, MB_FIND_ANY); } } else {#endif /* HANDLE_MULTIBYTE */ ols = oe - 1; /* find last same */ nls = ne - 1; while ((ols > ofd) && (nls > nfd) && (*ols == *nls)) { if (*ols != ' ') wsatend = 0; ols--; nls--; }#if defined (HANDLE_MULTIBYTE) }#endif if (wsatend) { ols = oe; nls = ne; }#if defined (HANDLE_MULTIBYTE) /* This may not work for stateful encoding, but who cares? To handle stateful encoding properly, we have to scan each string from the beginning and compare. */ else if (_rl_compare_chars (ols, 0, NULL, nls, 0, NULL) == 0)#else else if (*ols != *nls)#endif { if (*ols) /* don't step past the NUL */ { if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) ols = old + _rl_find_next_mbchar (old, ols - old, 1, MB_FIND_ANY); else ols++; } if (*nls) { if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) nls = new + _rl_find_next_mbchar (new, nls - new, 1, MB_FIND_ANY); else nls++; } } /* count of invisible characters in the current invisible line. */ current_invis_chars = W_OFFSET (current_line, wrap_offset); if (_rl_last_v_pos != current_line) { _rl_move_vert (current_line); if (current_line == 0 && visible_wrap_offset) _rl_last_c_pos += visible_wrap_offset; } /* If this is the first line and there are invisible characters in the prompt string, and the prompt string has not changed, and the current cursor position is before the last invisible character in the prompt, and the index of the character to move to is past the end of the prompt string, then redraw the entire prompt string. We can only do this reliably if the terminal supports a `cr' capability. This is not an efficiency hack -- there is a problem with redrawing portions of the prompt string if they contain terminal escape sequences (like drawing the `unbold' sequence without a corresponding `bold') that manifests itself on certain terminals. */ lendiff = local_prompt ? strlen (local_prompt) : 0; od = ofd - old; /* index of first difference in visible line */ if (current_line == 0 && !_rl_horizontal_scroll_mode && _rl_term_cr && lendiff > prompt_visible_length && _rl_last_c_pos > 0 && od >= lendiff && _rl_last_c_pos <= prompt_last_invisible) {#if defined (__MSDOS__) putc ('\r', rl_outstream);#else tputs (_rl_term_cr, 1, _rl_output_character_function);#endif _rl_output_some_chars (local_prompt, lendiff); if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) _rl_last_c_pos = _rl_col_width (local_prompt, 0, lendiff); else _rl_last_c_pos = lendiff; } _rl_move_cursor_relative (od, old); /* if (len (new) > len (old)) lendiff == difference in buffer col_lendiff == difference on screen When not using multibyte characters, these are equal */ lendiff = (nls - nfd) - (ols - ofd); if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) col_lendiff = _rl_col_width (new, nfd - new, nls - new) - _rl_col_width (old, ofd - old, ols - old); else col_lendiff = lendiff; /* If we are changing the number of invisible characters in a line, and the spot of first difference is before the end of the invisible chars, lendiff needs to be adjusted. */ if (current_line == 0 && !_rl_horizontal_scroll_mode && current_invis_chars != visible_wrap_offset) { if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) { lendiff += visible_wrap_offset - current_invis_chars; col_lendiff += visible_wrap_offset - current_invis_chars; } else { lendiff += visible_wrap_offset - current_invis_chars; col_lendiff = lendiff; } } /* Insert (diff (len (old), len (new)) ch. */ temp = ne - nfd; if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) col_temp = _rl_col_width (new, nfd - new, ne - new); else col_temp = temp; if (col_lendiff > 0) /* XXX - was lendiff */ { /* Non-zero if we're increasing the number of lines. */ int gl = current_line >= _rl_vis_botlin && inv_botlin > _rl_vis_botlin; /* Sometimes it is cheaper to print the characters rather than use the terminal's capabilities. If we're growing the number of lines, make sure we actually cause the new line to wrap around on auto-wrapping terminals. */ if (_rl_terminal_can_insert && ((2 * col_temp) >= col_lendiff || _rl_term_IC) && (!_rl_term_autowrap || !gl)) { /* If lendiff > prompt_visible_length and _rl_last_c_pos == 0 and _rl_horizontal_scroll_mode == 1, inserting the characters with _rl_term_IC or _rl_term_ic will screw up the screen because of the invisible characters. We need to just draw them. */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -