"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "display.c" between
readline-7.0-rc1.tar.gz and readline-7.0-rc2.tar.gz

About: GNU Readline library - get a line from a user with editing. Release candidate.

display.c  (readline-7.0-rc1):display.c  (readline-7.0-rc2)
skipping to change at line 122 skipping to change at line 122
/* Heuristic used to decide whether it is faster to move from CUR to NEW /* Heuristic used to decide whether it is faster to move from CUR to NEW
by backing up or outputting a carriage return and moving forward. CUR by backing up or outputting a carriage return and moving forward. CUR
and NEW are either both buffer positions or absolute screen positions. */ and NEW are either both buffer positions or absolute screen positions. */
#define CR_FASTER(new, cur) (((new) + 1) < ((cur) - (new))) #define CR_FASTER(new, cur) (((new) + 1) < ((cur) - (new)))
/* _rl_last_c_pos is an absolute cursor position in multibyte locales and a /* _rl_last_c_pos is an absolute cursor position in multibyte locales and a
buffer index in others. This macro is used when deciding whether the buffer index in others. This macro is used when deciding whether the
current cursor position is in the middle of a prompt string containing current cursor position is in the middle of a prompt string containing
invisible characters. XXX - might need to take `modmark' into account. */ invisible characters. XXX - might need to take `modmark' into account. */
/* XXX - only valid when tested against _rl_last_c_pos; buffer indices need
to use prompt_last_invisible directly. */
#define PROMPT_ENDING_INDEX \ #define PROMPT_ENDING_INDEX \
((MB_CUR_MAX > 1 && rl_byte_oriented == 0) ? prompt_physical_chars : prompt_la st_invisible+1) ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) ? prompt_physical_chars : prompt_la st_invisible+1)
/* **************************************************************** */ /* **************************************************************** */
/* */ /* */
/* Display stuff */ /* Display stuff */
/* */ /* */
/* **************************************************************** */ /* **************************************************************** */
/* This is the stuff that is hard for me. I never seem to write good /* This is the stuff that is hard for me. I never seem to write good
skipping to change at line 828 skipping to change at line 830
temp += wadjust; temp += wadjust;
inv_lbreaks[++newlines] = temp; inv_lbreaks[++newlines] = temp;
#if defined (HANDLE_MULTIBYTE) #if defined (HANDLE_MULTIBYTE)
/* lpos is a physical cursor position, so it needs to take the invisible /* lpos is a physical cursor position, so it needs to take the invisible
characters into account. */ characters into account. */
if (mb_cur_max > 1 && rl_byte_oriented == 0 && prompt_multibyte_chars > 0) if (mb_cur_max > 1 && rl_byte_oriented == 0 && prompt_multibyte_chars > 0)
lpos -= _rl_col_width (local_prompt, n0, num, 1) - wadjust; lpos -= _rl_col_width (local_prompt, n0, num, 1) - wadjust;
else else
#endif #endif
lpos -= _rl_screenwidth - wadjust; lpos -= _rl_screenwidth; /* all physical cursor positions */
} }
prompt_last_screen_line = newlines; prompt_last_screen_line = newlines;
/* Draw the rest of the line (after the prompt) into invisible_line, keeping /* Draw the rest of the line (after the prompt) into invisible_line, keeping
track of where the cursor is (cpos_buffer_position), the number of the line containing track of where the cursor is (cpos_buffer_position), the number of the line containing
the cursor (lb_linenum), the last line number (lb_botlin and inv_botlin). the cursor (lb_linenum), the last line number (lb_botlin and inv_botlin).
It maintains an array of line breaks for display (inv_lbreaks). It maintains an array of line breaks for display (inv_lbreaks).
This handles expanding tabs for display and displaying meta characters. */ This handles expanding tabs for display and displaying meta characters. */
lb_linenum = 0; lb_linenum = 0;
skipping to change at line 1390 skipping to change at line 1392
static void static void
update_line (old, new, current_line, omax, nmax, inv_botlin) update_line (old, new, current_line, omax, nmax, inv_botlin)
register char *old, *new; register char *old, *new;
int current_line, omax, nmax, inv_botlin; int current_line, omax, nmax, inv_botlin;
{ {
register char *ofd, *ols, *oe, *nfd, *nls, *ne; register char *ofd, *ols, *oe, *nfd, *nls, *ne;
int temp, lendiff, wsatend, od, nd, twidth, o_cpos; int temp, lendiff, wsatend, od, nd, twidth, o_cpos;
int current_invis_chars; int current_invis_chars;
int col_lendiff, col_temp; int col_lendiff, col_temp;
int bytes_to_insert; int bytes_to_insert;
int mb_cur_max = MB_CUR_MAX;
#if defined (HANDLE_MULTIBYTE) #if defined (HANDLE_MULTIBYTE)
mbstate_t ps_new, ps_old; mbstate_t ps_new, ps_old;
int new_offset, old_offset; int new_offset, old_offset;
#endif #endif
/* If we're at the right edge of a terminal that supports xn, we're /* 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 ready to wrap around, so do so. This fixes problems with knowing
the exact cursor position and cut-and-paste with certain terminal the exact cursor position and cut-and-paste with certain terminal
emulators. In this calculation, TEMP is the physical screen emulators. In this calculation, TEMP is the physical screen
position of the cursor. */ position of the cursor. */
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
temp = _rl_last_c_pos; temp = _rl_last_c_pos;
else else
temp = _rl_last_c_pos - WRAP_OFFSET (_rl_last_v_pos, visible_wrap_offset); temp = _rl_last_c_pos - WRAP_OFFSET (_rl_last_v_pos, visible_wrap_offset);
if (temp == _rl_screenwidth && _rl_term_autowrap && !_rl_horizontal_scroll_mod e if (temp == _rl_screenwidth && _rl_term_autowrap && !_rl_horizontal_scroll_mod e
&& _rl_last_v_pos == current_line - 1) && _rl_last_v_pos == current_line - 1)
{ {
#if defined (HANDLE_MULTIBYTE) #if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
{ {
wchar_t wc; wchar_t wc;
mbstate_t ps; mbstate_t ps;
int tempwidth, bytes; int tempwidth, bytes;
size_t ret; size_t ret;
/* This fixes only double-column characters, but if the wrapped /* This fixes only double-column characters, but if the wrapped
character consumes more than three columns, spaces will be character consumes more than three columns, spaces will be
inserted in the string buffer. */ inserted in the string buffer. */
if (current_line < line_state_visible->wbsize && line_state_visible->wr apped_line[current_line] > 0) if (current_line < line_state_visible->wbsize && line_state_visible->wr apped_line[current_line] > 0)
_rl_clear_to_eol (line_state_visible->wrapped_line[current_line]); _rl_clear_to_eol (line_state_visible->wrapped_line[current_line]);
memset (&ps, 0, sizeof (mbstate_t)); memset (&ps, 0, sizeof (mbstate_t));
ret = mbrtowc (&wc, new, MB_CUR_MAX, &ps); ret = mbrtowc (&wc, new, mb_cur_max, &ps);
if (MB_INVALIDCH (ret)) if (MB_INVALIDCH (ret))
{ {
tempwidth = 1; tempwidth = 1;
ret = 1; ret = 1;
} }
else if (MB_NULLWCH (ret)) else if (MB_NULLWCH (ret))
tempwidth = 0; tempwidth = 0;
else else
tempwidth = WCWIDTH (wc); tempwidth = WCWIDTH (wc);
if (tempwidth > 0) if (tempwidth > 0)
{ {
int count, i; int count, i;
bytes = ret; bytes = ret;
for (count = 0; count < bytes; count++) for (count = 0; count < bytes; count++)
putc (new[count], rl_outstream); putc (new[count], rl_outstream);
_rl_last_c_pos = tempwidth; _rl_last_c_pos = tempwidth;
_rl_last_v_pos++; _rl_last_v_pos++;
memset (&ps, 0, sizeof (mbstate_t)); memset (&ps, 0, sizeof (mbstate_t));
ret = mbrtowc (&wc, old, MB_CUR_MAX, &ps); ret = mbrtowc (&wc, old, mb_cur_max, &ps);
if (ret != 0 && bytes != 0) if (ret != 0 && bytes != 0)
{ {
if (MB_INVALIDCH (ret)) if (MB_INVALIDCH (ret))
ret = 1; ret = 1;
memmove (old+bytes, old+ret, strlen (old+ret)); memmove (old+bytes, old+ret, strlen (old+ret));
memcpy (old, new, bytes); memcpy (old, new, bytes);
/* Fix up indices if we copy data from one line to another */ /* Fix up indices if we copy data from one line to another */
omax += bytes - ret; omax += bytes - ret;
for (i = current_line+1; i <= inv_botlin+1; i++) for (i = current_line+1; i <= inv_botlin+1; i++)
vis_lbreaks[i] += bytes - ret; vis_lbreaks[i] += bytes - ret;
skipping to change at line 1480 skipping to change at line 1483
putc (' ', rl_outstream); putc (' ', rl_outstream);
_rl_last_c_pos = 1; _rl_last_c_pos = 1;
_rl_last_v_pos++; _rl_last_v_pos++;
if (old[0] && new[0]) if (old[0] && new[0])
old[0] = new[0]; old[0] = new[0];
} }
} }
/* Find first difference. */ /* Find first difference. */
#if defined (HANDLE_MULTIBYTE) #if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
{ {
/* See if the old line is a subset of the new line, so that the /* See if the old line is a subset of the new line, so that the
only change is adding characters. */ only change is adding characters. */
temp = (omax < nmax) ? omax : nmax; temp = (omax < nmax) ? omax : nmax;
if (memcmp (old, new, temp) == 0) /* adding at the end */ if (memcmp (old, new, temp) == 0) /* adding at the end */
{ {
new_offset = old_offset = temp; new_offset = old_offset = temp;
ofd = old + temp; ofd = old + temp;
nfd = new + temp; nfd = new + temp;
} }
skipping to change at line 1537 skipping to change at line 1540
of the distance between ne and new and oe and old, respectively, to of the distance between ne and new and oe and old, respectively, to
move a subtraction out of each loop. */ move a subtraction out of each loop. */
for (od = ofd - old, oe = ofd; od < omax && *oe; oe++, od++); for (od = ofd - old, oe = ofd; od < omax && *oe; oe++, od++);
for (nd = nfd - new, ne = nfd; nd < nmax && *ne; ne++, nd++); for (nd = nfd - new, ne = nfd; nd < nmax && *ne; ne++, nd++);
/* If no difference, continue to next line. */ /* If no difference, continue to next line. */
if (ofd == oe && nfd == ne) if (ofd == oe && nfd == ne)
return; return;
#if defined (HANDLE_MULTIBYTE) #if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0 && _rl_utf8locale) if (mb_cur_max > 1 && rl_byte_oriented == 0 && _rl_utf8locale)
{ {
wchar_t wc; wchar_t wc;
mbstate_t ps = { 0 }; mbstate_t ps = { 0 };
int t; int t;
/* If the first character in the difference is a zero-width character, /* If the first character in the difference is a zero-width character,
assume it's a combining character and back one up so the two base assume it's a combining character and back one up so the two base
characters no longer compare equivalently. */ characters no longer compare equivalently. */
t = mbrtowc (&wc, ofd, MB_CUR_MAX, &ps); t = mbrtowc (&wc, ofd, mb_cur_max, &ps);
if (t > 0 && UNICODE_COMBINING_CHAR (wc) && WCWIDTH (wc) == 0) if (t > 0 && UNICODE_COMBINING_CHAR (wc) && WCWIDTH (wc) == 0)
{ {
old_offset = _rl_find_prev_mbchar (old, ofd - old, MB_FIND_ANY); old_offset = _rl_find_prev_mbchar (old, ofd - old, MB_FIND_ANY);
new_offset = _rl_find_prev_mbchar (new, nfd - new, MB_FIND_ANY); new_offset = _rl_find_prev_mbchar (new, nfd - new, MB_FIND_ANY);
ofd = old + old_offset; /* equal by definition */ ofd = old + old_offset; /* equal by definition */
nfd = new + new_offset; nfd = new + new_offset;
} }
} }
#endif #endif
wsatend = 1; /* flag for trailing whitespace */ wsatend = 1; /* flag for trailing whitespace */
#if defined (HANDLE_MULTIBYTE) #if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
{ {
ols = old + _rl_find_prev_mbchar (old, oe - old, MB_FIND_ANY); ols = old + _rl_find_prev_mbchar (old, oe - old, MB_FIND_ANY);
nls = new + _rl_find_prev_mbchar (new, ne - new, MB_FIND_ANY); nls = new + _rl_find_prev_mbchar (new, ne - new, MB_FIND_ANY);
while ((ols > ofd) && (nls > nfd)) while ((ols > ofd) && (nls > nfd))
{ {
memset (&ps_old, 0, sizeof (mbstate_t)); memset (&ps_old, 0, sizeof (mbstate_t));
memset (&ps_new, 0, sizeof (mbstate_t)); memset (&ps_new, 0, sizeof (mbstate_t));
#if 0 #if 0
skipping to change at line 1618 skipping to change at line 1621
/* This may not work for stateful encoding, but who cares? To handle /* This may not work for stateful encoding, but who cares? To handle
stateful encoding properly, we have to scan each string from the stateful encoding properly, we have to scan each string from the
beginning and compare. */ beginning and compare. */
else if (_rl_compare_chars (ols, 0, NULL, nls, 0, NULL) == 0) else if (_rl_compare_chars (ols, 0, NULL, nls, 0, NULL) == 0)
#else #else
else if (*ols != *nls) else if (*ols != *nls)
#endif #endif
{ {
if (*ols) /* don't step past the NUL */ if (*ols) /* don't step past the NUL */
{ {
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
ols = old + _rl_find_next_mbchar (old, ols - old, 1, MB_FIND_ANY); ols = old + _rl_find_next_mbchar (old, ols - old, 1, MB_FIND_ANY);
else else
ols++; ols++;
} }
if (*nls) if (*nls)
{ {
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
nls = new + _rl_find_next_mbchar (new, nls - new, 1, MB_FIND_ANY); nls = new + _rl_find_next_mbchar (new, nls - new, 1, MB_FIND_ANY);
else else
nls++; nls++;
} }
} }
/* count of invisible characters in the current invisible line. */ /* count of invisible characters in the current invisible line. */
current_invis_chars = W_OFFSET (current_line, wrap_offset); current_invis_chars = W_OFFSET (current_line, wrap_offset);
if (_rl_last_v_pos != current_line) if (_rl_last_v_pos != current_line)
{ {
_rl_move_vert (current_line); _rl_move_vert (current_line);
/* We have moved up to a new screen line. This line may or may not have /* We have moved up to a new screen line. This line may or may not have
invisible characters on it, but we do our best to recalculate invisible characters on it, but we do our best to recalculate
visible_wrap_offset based on what we know. */ visible_wrap_offset based on what we know. */
if (current_line == 0) if (current_line == 0)
visible_wrap_offset = prompt_invis_chars_first_line; /* XXX */ visible_wrap_offset = prompt_invis_chars_first_line; /* XXX */
if ((MB_CUR_MAX == 1 || rl_byte_oriented) && current_line == 0 && visible_ wrap_offset) if ((mb_cur_max == 1 || rl_byte_oriented) && current_line == 0 && visible_ wrap_offset)
_rl_last_c_pos += visible_wrap_offset; _rl_last_c_pos += visible_wrap_offset;
} }
/* If this is the first line and there are invisible characters in the /* 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 prompt string, and the prompt string has not changed, and the current
cursor position is before the last invisible character in the prompt, 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 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 string, then redraw the entire prompt string. We can only do this
reliably if the terminal supports a `cr' capability. reliably if the terminal supports a `cr' capability.
skipping to change at line 1673 skipping to change at line 1676
This is not an efficiency hack -- there is a problem with redrawing This is not an efficiency hack -- there is a problem with redrawing
portions of the prompt string if they contain terminal escape portions of the prompt string if they contain terminal escape
sequences (like drawing the `unbold' sequence without a corresponding sequences (like drawing the `unbold' sequence without a corresponding
`bold') that manifests itself on certain terminals. */ `bold') that manifests itself on certain terminals. */
lendiff = local_prompt_len; lendiff = local_prompt_len;
if (lendiff > nmax) if (lendiff > nmax)
lendiff = nmax; lendiff = nmax;
od = ofd - old; /* index of first difference in visible line */ od = ofd - old; /* index of first difference in visible line */
nd = nfd - new; nd = nfd - new; /* nd, od are buffer indexes */
if (current_line == 0 && !_rl_horizontal_scroll_mode && if (current_line == 0 && !_rl_horizontal_scroll_mode &&
_rl_term_cr && lendiff > prompt_visible_length && _rl_last_c_pos > 0 && _rl_term_cr && lendiff > prompt_visible_length && _rl_last_c_pos > 0 &&
(((od > 0 || nd > 0) && (od < PROMPT_ENDING_INDEX || nd < PROMPT_ENDING_IN DEX)) || (((od > 0 || nd > 0) && (od <= prompt_last_invisible || nd <= prompt_last_ invisible)) ||
((od >= lendiff) && _rl_last_c_pos < PROMPT_ENDING_INDEX))) ((od >= lendiff) && _rl_last_c_pos < PROMPT_ENDING_INDEX)))
{ {
#if defined (__MSDOS__) #if defined (__MSDOS__)
putc ('\r', rl_outstream); putc ('\r', rl_outstream);
#else #else
tputs (_rl_term_cr, 1, _rl_output_character_function); tputs (_rl_term_cr, 1, _rl_output_character_function);
#endif #endif
if (modmark) if (modmark)
_rl_output_some_chars ("*", 1); _rl_output_some_chars ("*", 1);
_rl_output_some_chars (local_prompt, lendiff); _rl_output_some_chars (local_prompt, lendiff);
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
{ {
/* We take wrap_offset into account here so we can pass correct /* We take wrap_offset into account here so we can pass correct
information to _rl_move_cursor_relative. */ information to _rl_move_cursor_relative. */
_rl_last_c_pos = _rl_col_width (local_prompt, 0, lendiff, 1) - wrap_off set + modmark; _rl_last_c_pos = _rl_col_width (local_prompt, 0, lendiff, 1) - wrap_off set + modmark;
cpos_adjusted = 1; cpos_adjusted = 1;
} }
else else
_rl_last_c_pos = lendiff + modmark; _rl_last_c_pos = lendiff + modmark;
/* Now if we have printed the prompt string because the first difference /* Now if we have printed the prompt string because the first difference
was within the prompt, see if we need to recompute where the lines was within the prompt, see if we need to recompute where the lines
differ. Check whether where we are now is past the last place where differ. Check whether where we are now is past the last place where
the old and new lines are the same and short-circuit now if we are. */ the old and new lines are the same and short-circuit now if we are. */
if ((od < PROMPT_ENDING_INDEX || nd < PROMPT_ENDING_INDEX) && if ((od <= prompt_last_invisible || nd <= prompt_last_invisible) &&
omax == nmax && omax == nmax &&
lendiff > (ols-old) && lendiff > (nls-new)) lendiff > (ols-old) && lendiff > (nls-new))
return; return;
/* XXX - we need to fix up our calculations if we are now past the /* XXX - we need to fix up our calculations if we are now past the
old ofd/nfd and the prompt length (or line length) has changed. old ofd/nfd and the prompt length (or line length) has changed.
We punt on the problem and do a dumb update. We'd like to be able We punt on the problem and do a dumb update. We'd like to be able
to just output the prompt from the beginning of the line up to the to just output the prompt from the beginning of the line up to the
first difference, but you don't know the number of invisible first difference, but you don't know the number of invisible
characters in that case. characters in that case.
This needs a lot of work to be efficient. */ This needs a lot of work to be efficient. */
if ((od < PROMPT_ENDING_INDEX || nd < PROMPT_ENDING_INDEX)) if ((od <= prompt_last_invisible || nd <= prompt_last_invisible))
{ {
nfd = new + lendiff; /* number of characters we output above */ nfd = new + lendiff; /* number of characters we output above */
nd = lendiff; nd = lendiff;
/* Do a dumb update and return */ /* Do a dumb update and return */
temp = ne - nfd; temp = ne - nfd;
if (temp > 0) if (temp > 0)
{ {
_rl_output_some_chars (nfd, temp); _rl_output_some_chars (nfd, temp);
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
_rl_last_c_pos += _rl_col_width (new, nd, ne - new, 1); _rl_last_c_pos += _rl_col_width (new, nd, ne - new, 1);
else else
_rl_last_c_pos += temp; _rl_last_c_pos += temp;
} }
if (nmax < omax) if (nmax < omax)
goto clear_rest_of_line; /* XXX */ goto clear_rest_of_line; /* XXX */
else else
return; return;
} }
} }
skipping to change at line 1746 skipping to change at line 1749
/* When this function returns, _rl_last_c_pos is correct, and an absolute /* When this function returns, _rl_last_c_pos is correct, and an absolute
cursor position in multibyte mode, but a buffer index when not in a cursor position in multibyte mode, but a buffer index when not in a
multibyte locale. */ multibyte locale. */
_rl_move_cursor_relative (od, old); _rl_move_cursor_relative (od, old);
#if defined (HANDLE_MULTIBYTE) #if defined (HANDLE_MULTIBYTE)
/* We need to indicate that the cursor position is correct in the presence of /* We need to indicate that the cursor position is correct in the presence of
invisible characters in the prompt string. Let's see if setting this when invisible characters in the prompt string. Let's see if setting this when
we make sure we're at the end of the drawn prompt string works. */ we make sure we're at the end of the drawn prompt string works. */
if (current_line == 0 && MB_CUR_MAX > 1 && rl_byte_oriented == 0 && if (current_line == 0 && mb_cur_max > 1 && rl_byte_oriented == 0 &&
(_rl_last_c_pos > 0 || o_cpos > 0) && (_rl_last_c_pos > 0 || o_cpos > 0) &&
_rl_last_c_pos == prompt_physical_chars) _rl_last_c_pos == prompt_physical_chars)
cpos_adjusted = 1; cpos_adjusted = 1;
#endif #endif
/* if (len (new) > len (old)) /* if (len (new) > len (old))
lendiff == difference in buffer (bytes) lendiff == difference in buffer (bytes)
col_lendiff == difference on screen (columns) col_lendiff == difference on screen (columns)
When not using multibyte characters, these are equal */ When not using multibyte characters, these are equal */
lendiff = (nls - nfd) - (ols - ofd); lendiff = (nls - nfd) - (ols - ofd);
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
col_lendiff = _rl_col_width (new, nfd - new, nls - new, 1) - _rl_col_width ( old, ofd - old, ols - old, 1); col_lendiff = _rl_col_width (new, nfd - new, nls - new, 1) - _rl_col_width ( old, ofd - old, ols - old, 1);
else else
col_lendiff = lendiff; col_lendiff = lendiff;
/* If we are changing the number of invisible characters in a line, and /* 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, the spot of first difference is before the end of the invisible chars,
lendiff needs to be adjusted. */ lendiff needs to be adjusted. */
if (current_line == 0 && /* !_rl_horizontal_scroll_mode && */ if (current_line == 0 && /* !_rl_horizontal_scroll_mode && */
current_invis_chars != visible_wrap_offset) current_invis_chars != visible_wrap_offset)
{ {
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
{ {
lendiff += visible_wrap_offset - current_invis_chars; lendiff += visible_wrap_offset - current_invis_chars;
col_lendiff += visible_wrap_offset - current_invis_chars; col_lendiff += visible_wrap_offset - current_invis_chars;
} }
else else
{ {
lendiff += visible_wrap_offset - current_invis_chars; lendiff += visible_wrap_offset - current_invis_chars;
col_lendiff = lendiff; col_lendiff = lendiff;
} }
} }
/* We use temp as a count of the number of bytes from the first difference /* We use temp as a count of the number of bytes from the first difference
to the end of the new line. col_temp is the corresponding number of to the end of the new line. col_temp is the corresponding number of
screen columns. A `dumb' update moves to the spot of first difference screen columns. A `dumb' update moves to the spot of first difference
and writes TEMP bytes. */ and writes TEMP bytes. */
/* Insert (diff (len (old), len (new)) ch. */ /* Insert (diff (len (old), len (new)) ch. */
temp = ne - nfd; temp = ne - nfd;
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
col_temp = _rl_col_width (new, nfd - new, ne - new, 1); col_temp = _rl_col_width (new, nfd - new, ne - new, 1);
else else
col_temp = temp; col_temp = temp;
/* how many bytes from the new line buffer to write to the display */ /* how many bytes from the new line buffer to write to the display */
bytes_to_insert = nls - nfd; bytes_to_insert = nls - nfd;
/* col_lendiff > 0 if we are adding characters to the line */ /* col_lendiff > 0 if we are adding characters to the line */
if (col_lendiff > 0) /* XXX - was lendiff */ if (col_lendiff > 0) /* XXX - was lendiff */
{ {
skipping to change at line 1837 skipping to change at line 1840
_rl_term_IC or _rl_term_ic will screw up the screen because of the _rl_term_IC or _rl_term_ic will screw up the screen because of the
invisible characters. We need to just draw them. */ invisible characters. We need to just draw them. */
/* The same thing happens if we're trying to draw before the last /* The same thing happens if we're trying to draw before the last
invisible character in the prompt string or we're increasing the invisible character in the prompt string or we're increasing the
number of invisible characters in the line and we're not drawing number of invisible characters in the line and we're not drawing
the entire prompt string. */ the entire prompt string. */
if (*ols && ((_rl_horizontal_scroll_mode && if (*ols && ((_rl_horizontal_scroll_mode &&
_rl_last_c_pos == 0 && _rl_last_c_pos == 0 &&
lendiff > prompt_visible_length && lendiff > prompt_visible_length &&
current_invis_chars > 0) == 0) && current_invis_chars > 0) == 0) &&
(((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && (((mb_cur_max > 1 && rl_byte_oriented == 0) &&
current_line == 0 && wrap_offset && current_line == 0 && wrap_offset &&
((nfd - new) <= prompt_last_invisible) && ((nfd - new) <= prompt_last_invisible) &&
(col_lendiff < prompt_visible_length)) == 0) && (col_lendiff < prompt_visible_length)) == 0) &&
(visible_wrap_offset >= current_invis_chars)) (visible_wrap_offset >= current_invis_chars))
{ {
open_some_spaces (col_lendiff); open_some_spaces (col_lendiff);
_rl_output_some_chars (nfd, bytes_to_insert); _rl_output_some_chars (nfd, bytes_to_insert);
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
_rl_last_c_pos += _rl_col_width (nfd, 0, bytes_to_insert, 1); _rl_last_c_pos += _rl_col_width (nfd, 0, bytes_to_insert, 1);
else else
_rl_last_c_pos += bytes_to_insert; _rl_last_c_pos += bytes_to_insert;
} }
else if ((MB_CUR_MAX == 1 || rl_byte_oriented != 0) && *ols == 0 && len diff > 0) else if ((mb_cur_max == 1 || rl_byte_oriented != 0) && *ols == 0 && len diff > 0)
{ {
/* At the end of a line the characters do not have to /* At the end of a line the characters do not have to
be "inserted". They can just be placed on the screen. */ be "inserted". They can just be placed on the screen. */
_rl_output_some_chars (nfd, temp); _rl_output_some_chars (nfd, temp);
_rl_last_c_pos += col_temp; _rl_last_c_pos += col_temp;
return; return;
} }
else /* just write from first difference to end of new line */ else /* just write from first difference to end of new line */
{ {
_rl_output_some_chars (nfd, temp); _rl_output_some_chars (nfd, temp);
_rl_last_c_pos += col_temp; _rl_last_c_pos += col_temp;
/* If nfd begins before the last invisible character in the /* If nfd begins before the last invisible character in the
prompt, adjust _rl_last_c_pos to account for wrap_offset prompt, adjust _rl_last_c_pos to account for wrap_offset
and set cpos_adjusted to let the caller know. */ and set cpos_adjusted to let the caller know. */
if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && current_line == 0 && displaying_prompt_first_line && wrap_offset && ((nfd - new) <= prompt_last_in visible)) if ((mb_cur_max > 1 && rl_byte_oriented == 0) && current_line == 0 && displaying_prompt_first_line && wrap_offset && ((nfd - new) <= prompt_last_in visible))
{ {
_rl_last_c_pos -= wrap_offset; _rl_last_c_pos -= wrap_offset;
cpos_adjusted = 1; cpos_adjusted = 1;
} }
return; return;
} }
if (bytes_to_insert > lendiff) if (bytes_to_insert > lendiff)
{ {
/* If nfd begins before the last invisible character in the /* If nfd begins before the last invisible character in the
prompt, adjust _rl_last_c_pos to account for wrap_offset prompt, adjust _rl_last_c_pos to account for wrap_offset
and set cpos_adjusted to let the caller know. */ and set cpos_adjusted to let the caller know. */
if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && current_line == 0 && displaying_prompt_first_line && wrap_offset && ((nfd - new) <= prompt_last_in visible)) if ((mb_cur_max > 1 && rl_byte_oriented == 0) && current_line == 0 && displaying_prompt_first_line && wrap_offset && ((nfd - new) <= prompt_last_in visible))
{ {
_rl_last_c_pos -= wrap_offset; _rl_last_c_pos -= wrap_offset;
cpos_adjusted = 1; cpos_adjusted = 1;
} }
} }
} }
else else
{ {
/* cannot insert chars, write to EOL */ /* cannot insert chars, write to EOL */
_rl_output_some_chars (nfd, temp); _rl_output_some_chars (nfd, temp);
_rl_last_c_pos += col_temp; _rl_last_c_pos += col_temp;
/* If we're in a multibyte locale and were before the last invisible /* If we're in a multibyte locale and were before the last invisible
char in the current line (which implies we just output some invisibl e char in the current line (which implies we just output some invisibl e
characters) we need to adjust _rl_last_c_pos, since it represents characters) we need to adjust _rl_last_c_pos, since it represents
a physical character position. */ a physical character position. */
/* The current_line*rl_screenwidth+prompt_invis_chars_first_line is a /* The current_line*rl_screenwidth+prompt_invis_chars_first_line is a
crude attempt to compute how far into the new line buffer we are. crude attempt to compute how far into the new line buffer we are.
It doesn't work well in the face of multibyte characters and needs It doesn't work well in the face of multibyte characters and needs
to be rethought. XXX */ to be rethought. XXX */
if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && if ((mb_cur_max > 1 && rl_byte_oriented == 0) &&
current_line == prompt_last_screen_line && wrap_offset && current_line == prompt_last_screen_line && wrap_offset &&
displaying_prompt_first_line && displaying_prompt_first_line &&
wrap_offset != prompt_invis_chars_first_line && wrap_offset != prompt_invis_chars_first_line &&
((nfd-new) < (prompt_last_invisible-(current_line*_rl_screenwidth +prompt_invis_chars_first_line)))) ((nfd-new) < (prompt_last_invisible-(current_line*_rl_screenwidth +prompt_invis_chars_first_line))))
{ {
_rl_last_c_pos -= wrap_offset - prompt_invis_chars_first_line; _rl_last_c_pos -= wrap_offset - prompt_invis_chars_first_line;
cpos_adjusted = 1; cpos_adjusted = 1;
} }
} }
} }
skipping to change at line 1942 skipping to change at line 1945
/* Copy (new) chars to screen from first diff to last match, /* Copy (new) chars to screen from first diff to last match,
overwriting what is there. */ overwriting what is there. */
if (bytes_to_insert > 0) if (bytes_to_insert > 0)
{ {
/* If nfd begins at the prompt, or before the invisible /* If nfd begins at the prompt, or before the invisible
characters in the prompt, we need to adjust _rl_last_c_pos characters in the prompt, we need to adjust _rl_last_c_pos
in a multibyte locale to account for the wrap offset and in a multibyte locale to account for the wrap offset and
set cpos_adjusted accordingly. */ set cpos_adjusted accordingly. */
_rl_output_some_chars (nfd, bytes_to_insert); _rl_output_some_chars (nfd, bytes_to_insert);
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
{ {
_rl_last_c_pos += _rl_col_width (nfd, 0, bytes_to_insert, 1); _rl_last_c_pos += _rl_col_width (nfd, 0, bytes_to_insert, 1);
if (current_line == 0 && wrap_offset && if (current_line == 0 && wrap_offset &&
displaying_prompt_first_line && displaying_prompt_first_line &&
_rl_last_c_pos > wrap_offset && _rl_last_c_pos > wrap_offset &&
((nfd - new) <= prompt_last_invisible)) ((nfd - new) <= prompt_last_invisible))
{ {
_rl_last_c_pos -= wrap_offset; _rl_last_c_pos -= wrap_offset;
cpos_adjusted = 1; cpos_adjusted = 1;
} }
skipping to change at line 1977 skipping to change at line 1980
else else
{ {
if (temp > 0) if (temp > 0)
{ {
/* If nfd begins at the prompt, or before the invisible /* If nfd begins at the prompt, or before the invisible
characters in the prompt, we need to adjust _rl_last_c_pos characters in the prompt, we need to adjust _rl_last_c_pos
in a multibyte locale to account for the wrap offset and in a multibyte locale to account for the wrap offset and
set cpos_adjusted accordingly. */ set cpos_adjusted accordingly. */
_rl_output_some_chars (nfd, temp); _rl_output_some_chars (nfd, temp);
_rl_last_c_pos += col_temp; /* XXX */ _rl_last_c_pos += col_temp; /* XXX */
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
{ {
if (current_line == 0 && wrap_offset && if (current_line == 0 && wrap_offset &&
displaying_prompt_first_line && displaying_prompt_first_line &&
_rl_last_c_pos > wrap_offset && _rl_last_c_pos > wrap_offset &&
((nfd - new) <= prompt_last_invisible)) ((nfd - new) <= prompt_last_invisible))
{ {
_rl_last_c_pos -= wrap_offset; _rl_last_c_pos -= wrap_offset;
cpos_adjusted = 1; cpos_adjusted = 1;
} }
} }
} }
clear_rest_of_line: clear_rest_of_line:
lendiff = (oe - old) - (ne - new); lendiff = (oe - old) - (ne - new);
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
col_lendiff = _rl_col_width (old, 0, oe - old, 1) - _rl_col_width (ne w, 0, ne - new, 1); col_lendiff = _rl_col_width (old, 0, oe - old, 1) - _rl_col_width (ne w, 0, ne - new, 1);
else else
col_lendiff = lendiff; col_lendiff = lendiff;
/* If we've already printed over the entire width of the screen, /* If we've already printed over the entire width of the screen,
including the old material, then col_lendiff doesn't matter and including the old material, then col_lendiff doesn't matter and
space_to_eol will insert too many spaces. XXX - maybe we should space_to_eol will insert too many spaces. XXX - maybe we should
adjust col_lendiff based on the difference between _rl_last_c_pos adjust col_lendiff based on the difference between _rl_last_c_pos
and _rl_screenwidth */ and _rl_screenwidth */
if (col_lendiff && ((MB_CUR_MAX == 1 || rl_byte_oriented) || (_rl_last_ c_pos < _rl_screenwidth))) if (col_lendiff && ((mb_cur_max == 1 || rl_byte_oriented) || (_rl_last_ c_pos < _rl_screenwidth)))
{ {
if (_rl_term_autowrap && current_line < inv_botlin) if (_rl_term_autowrap && current_line < inv_botlin)
space_to_eol (col_lendiff); space_to_eol (col_lendiff);
else else
_rl_clear_to_eol (col_lendiff); _rl_clear_to_eol (col_lendiff);
} }
} }
} }
} }
skipping to change at line 2027 skipping to change at line 2030
visible_line[0] = '\0'; visible_line[0] = '\0';
_rl_last_c_pos = _rl_last_v_pos = 0; _rl_last_c_pos = _rl_last_v_pos = 0;
_rl_vis_botlin = last_lmargin = 0; _rl_vis_botlin = last_lmargin = 0;
if (vis_lbreaks) if (vis_lbreaks)
vis_lbreaks[0] = vis_lbreaks[1] = 0; vis_lbreaks[0] = vis_lbreaks[1] = 0;
visible_wrap_offset = 0; visible_wrap_offset = 0;
return 0; return 0;
} }
/* Clear all screen lines occupied by the current readline line buffer
(visible line) */
int
rl_clear_visible_line ()
{
int curr_line;
/* Make sure we move to column 0 so we clear the entire line */
#if defined (__MSDOS__)
putc ('\r', rl_outstream);
#else
tputs (_rl_term_cr, 1, _rl_output_character_function);
#endif
_rl_last_c_pos = 0;
/* Move to the last screen line of the current visible line */
_rl_move_vert (_rl_vis_botlin);
/* And erase screen lines going up to line 0 (first visible line) */
for (curr_line = _rl_last_v_pos; curr_line >= 0; curr_line--)
{
_rl_move_vert (curr_line);
_rl_clear_to_eol (0);
}
return 0;
}
/* Tell the update routines that we have moved onto a new line with the /* Tell the update routines that we have moved onto a new line with the
prompt already displayed. Code originally from the version of readline prompt already displayed. Code originally from the version of readline
distributed with CLISP. rl_expand_prompt must have already been called distributed with CLISP. rl_expand_prompt must have already been called
(explicitly or implicitly). This still doesn't work exactly right. */ (explicitly or implicitly). This still doesn't work exactly right. */
int int
rl_on_new_line_with_prompt () rl_on_new_line_with_prompt ()
{ {
int prompt_size, i, l, real_screenwidth, newlines; int prompt_size, i, l, real_screenwidth, newlines;
char *prompt_last_line, *lprompt; char *prompt_last_line, *lprompt;
skipping to change at line 2133 skipping to change at line 2164
void void
_rl_move_cursor_relative (new, data) _rl_move_cursor_relative (new, data)
int new; int new;
const char *data; const char *data;
{ {
register int i; register int i;
int woff; /* number of invisible chars on current line */ int woff; /* number of invisible chars on current line */
int cpos, dpos; /* current and desired cursor positions */ int cpos, dpos; /* current and desired cursor positions */
int adjust; int adjust;
int in_invisline; int in_invisline;
int mb_cur_max = MB_CUR_MAX;
woff = WRAP_OFFSET (_rl_last_v_pos, wrap_offset); woff = WRAP_OFFSET (_rl_last_v_pos, wrap_offset);
cpos = _rl_last_c_pos; cpos = _rl_last_c_pos;
if (cpos == 0 && cpos == new) if (cpos == 0 && cpos == new)
return; return;
#if defined (HANDLE_MULTIBYTE) #if defined (HANDLE_MULTIBYTE)
/* If we have multibyte characters, NEW is indexed by the buffer point in /* If we have multibyte characters, NEW is indexed by the buffer point in
a multibyte string, but _rl_last_c_pos is the display position. In a multibyte string, but _rl_last_c_pos is the display position. In
this case, NEW's display position is not obvious and must be this case, NEW's display position is not obvious and must be
calculated. We need to account for invisible characters in this line, calculated. We need to account for invisible characters in this line,
as long as we are past them and they are counted by _rl_col_width. */ as long as we are past them and they are counted by _rl_col_width. */
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
{ {
adjust = 1; adjust = 1;
/* Try to short-circuit common cases and eliminate a bunch of multibyte /* Try to short-circuit common cases and eliminate a bunch of multibyte
character function calls. */ character function calls. */
/* 1. prompt string */ /* 1. prompt string */
if (new == local_prompt_len && memcmp (data, local_prompt, new) == 0) if (new == local_prompt_len && memcmp (data, local_prompt, new) == 0)
{ {
dpos = prompt_physical_chars; dpos = prompt_physical_chars;
cpos_adjusted = 1; cpos_adjusted = 1;
adjust = 0; adjust = 0;
skipping to change at line 2214 skipping to change at line 2246
dpos = new; dpos = new;
/* If we don't have to do anything, then return. */ /* If we don't have to do anything, then return. */
if (cpos == dpos) if (cpos == dpos)
return; return;
/* It may be faster to output a CR, and then move forwards instead /* It may be faster to output a CR, and then move forwards instead
of moving backwards. */ of moving backwards. */
/* i == current physical cursor position. */ /* i == current physical cursor position. */
#if defined (HANDLE_MULTIBYTE) #if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
i = _rl_last_c_pos; i = _rl_last_c_pos;
else else
#endif #endif
i = _rl_last_c_pos - woff; i = _rl_last_c_pos - woff;
if (dpos == 0 || CR_FASTER (dpos, _rl_last_c_pos) || if (dpos == 0 || CR_FASTER (dpos, _rl_last_c_pos) ||
(_rl_term_autowrap && i == _rl_screenwidth)) (_rl_term_autowrap && i == _rl_screenwidth))
{ {
#if defined (__MSDOS__) #if defined (__MSDOS__)
putc ('\r', rl_outstream); putc ('\r', rl_outstream);
#else #else
skipping to change at line 2249 skipping to change at line 2281
That kind of control is for people who don't know what the That kind of control is for people who don't know what the
data is underneath the cursor. */ data is underneath the cursor. */
/* However, we need a handle on where the current display position is /* However, we need a handle on where the current display position is
in the buffer for the immediately preceding comment to be true. in the buffer for the immediately preceding comment to be true.
In multibyte locales, we don't currently have that info available. In multibyte locales, we don't currently have that info available.
Without it, we don't know where the data we have to display begins Without it, we don't know where the data we have to display begins
in the buffer and we have to go back to the beginning of the screen in the buffer and we have to go back to the beginning of the screen
line. In this case, we can use the terminal sequence to move forward line. In this case, we can use the terminal sequence to move forward
if it's available. */ if it's available. */
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) if (mb_cur_max > 1 && rl_byte_oriented == 0)
{ {
if (_rl_term_forward_char) if (_rl_term_forward_char)
{ {
for (i = cpos; i < dpos; i++) for (i = cpos; i < dpos; i++)
tputs (_rl_term_forward_char, 1, _rl_output_character_function); tputs (_rl_term_forward_char, 1, _rl_output_character_function);
} }
else else
{ {
tputs (_rl_term_cr, 1, _rl_output_character_function); tputs (_rl_term_cr, 1, _rl_output_character_function);
for (i = 0; i < new; i++) for (i = 0; i < new; i++)
 End of changes. 39 change blocks. 
35 lines changed or deleted 67 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS