display.c (157195) | display.c (165675) |
---|---|
1/* $FreeBSD: head/contrib/libreadline/display.c 157195 2006-03-27 23:53:05Z ache $ */ | 1/* $FreeBSD: head/contrib/libreadline/display.c 165675 2006-12-31 09:22:31Z ache $ */ |
2/* display.c -- readline redisplay facility. */ 3 | 2/* display.c -- readline redisplay facility. */ 3 |
4/* Copyright (C) 1987-2005 Free Software Foundation, Inc. | 4/* Copyright (C) 1987-2006 Free Software Foundation, Inc. |
5 6 This file is part of the GNU Readline Library, a library for 7 reading lines of text with interactive input and history editing. 8 9 The GNU Readline Library is free software; you can redistribute it 10 and/or modify it under the terms of the GNU General Public License 11 as published by the Free Software Foundation; either version 2, or 12 (at your option) any later version. --- 42 unchanged lines hidden (view full) --- 55 56#include "rlprivate.h" 57#include "xmalloc.h" 58 59#if !defined (strchr) && !defined (__STDC__) 60extern char *strchr (), *strrchr (); 61#endif /* !strchr && !__STDC__ */ 62 | 5 6 This file is part of the GNU Readline Library, a library for 7 reading lines of text with interactive input and history editing. 8 9 The GNU Readline Library is free software; you can redistribute it 10 and/or modify it under the terms of the GNU General Public License 11 as published by the Free Software Foundation; either version 2, or 12 (at your option) any later version. --- 42 unchanged lines hidden (view full) --- 55 56#include "rlprivate.h" 57#include "xmalloc.h" 58 59#if !defined (strchr) && !defined (__STDC__) 60extern char *strchr (), *strrchr (); 61#endif /* !strchr && !__STDC__ */ 62 |
63#if defined (HACK_TERMCAP_MOTION) 64extern char *_rl_term_forward_char; 65#endif 66 | |
67static void update_line PARAMS((char *, char *, int, int, int, int)); 68static void space_to_eol PARAMS((int)); 69static void delete_chars PARAMS((int)); 70static void insert_some_chars PARAMS((char *, int, int)); 71static void cr PARAMS((void)); 72 73#if defined (HANDLE_MULTIBYTE) 74static int _rl_col_width PARAMS((const char *, int, int)); 75static int *_rl_wrapped_line; 76#else 77# define _rl_col_width(l, s, e) (((e) <= (s)) ? 0 : (e) - (s)) 78#endif 79 80static int *inv_lbreaks, *vis_lbreaks; 81static int inv_lbsize, vis_lbsize; 82 83/* Heuristic used to decide whether it is faster to move from CUR to NEW | 63static void update_line PARAMS((char *, char *, int, int, int, int)); 64static void space_to_eol PARAMS((int)); 65static void delete_chars PARAMS((int)); 66static void insert_some_chars PARAMS((char *, int, int)); 67static void cr PARAMS((void)); 68 69#if defined (HANDLE_MULTIBYTE) 70static int _rl_col_width PARAMS((const char *, int, int)); 71static int *_rl_wrapped_line; 72#else 73# define _rl_col_width(l, s, e) (((e) <= (s)) ? 0 : (e) - (s)) 74#endif 75 76static int *inv_lbreaks, *vis_lbreaks; 77static int inv_lbsize, vis_lbsize; 78 79/* Heuristic used to decide whether it is faster to move from CUR to NEW |
84 by backing up or outputting a carriage return and moving forward. */ | 80 by backing up or outputting a carriage return and moving forward. CUR 81 and NEW are either both buffer positions or absolute screen positions. */ |
85#define CR_FASTER(new, cur) (((new) + 1) < ((cur) - (new))) 86 | 82#define CR_FASTER(new, cur) (((new) + 1) < ((cur) - (new))) 83 |
84/* _rl_last_c_pos is an absolute cursor position in multibyte locales and a 85 buffer index in others. This macro is used when deciding whether the 86 current cursor position is in the middle of a prompt string containing 87 invisible characters. */ 88#define PROMPT_ENDING_INDEX \ 89 ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) ? prompt_physical_chars : prompt_last_invisible+1) 90 91 |
|
87/* **************************************************************** */ 88/* */ 89/* Display stuff */ 90/* */ 91/* **************************************************************** */ 92 93/* This is the stuff that is hard for me. I never seem to write good 94 display routines in C. Let's see how I do this time. */ --- 36 unchanged lines hidden (view full) --- 131/* NOTE: _rl_last_c_pos is used as a buffer index when not in a locale 132 supporting multibyte characters, and an absolute cursor position when 133 in such a locale. This is an artifact of the donated multibyte support. 134 Care must be taken when modifying its value. */ 135int _rl_last_c_pos = 0; 136int _rl_last_v_pos = 0; 137 138static int cpos_adjusted; | 92/* **************************************************************** */ 93/* */ 94/* Display stuff */ 95/* */ 96/* **************************************************************** */ 97 98/* This is the stuff that is hard for me. I never seem to write good 99 display routines in C. Let's see how I do this time. */ --- 36 unchanged lines hidden (view full) --- 136/* NOTE: _rl_last_c_pos is used as a buffer index when not in a locale 137 supporting multibyte characters, and an absolute cursor position when 138 in such a locale. This is an artifact of the donated multibyte support. 139 Care must be taken when modifying its value. */ 140int _rl_last_c_pos = 0; 141int _rl_last_v_pos = 0; 142 143static int cpos_adjusted; |
144static int cpos_buffer_position; |
|
139 140/* Number of lines currently on screen minus 1. */ 141int _rl_vis_botlin = 0; 142 143/* Variables used only in this file. */ 144/* The last left edge of text that was displayed. This is used when 145 doing horizontal scrolling. It shifts in thirds of a screenwidth. */ 146static int last_lmargin; --- 11 unchanged lines hidden (view full) --- 158 159/* Default and initial buffer size. Can grow. */ 160static int line_size = 1024; 161 162/* Variables to keep track of the expanded prompt string, which may 163 include invisible characters. */ 164 165static char *local_prompt, *local_prompt_prefix; | 145 146/* Number of lines currently on screen minus 1. */ 147int _rl_vis_botlin = 0; 148 149/* Variables used only in this file. */ 150/* The last left edge of text that was displayed. This is used when 151 doing horizontal scrolling. It shifts in thirds of a screenwidth. */ 152static int last_lmargin; --- 11 unchanged lines hidden (view full) --- 164 165/* Default and initial buffer size. Can grow. */ 166static int line_size = 1024; 167 168/* Variables to keep track of the expanded prompt string, which may 169 include invisible characters. */ 170 171static char *local_prompt, *local_prompt_prefix; |
172static int local_prompt_len; |
|
166static int prompt_visible_length, prompt_prefix_length; 167 168/* The number of invisible characters in the line currently being 169 displayed on the screen. */ 170static int visible_wrap_offset; 171 172/* The number of invisible characters in the prompt string. Static so it 173 can be shared between rl_redisplay and update_line */ --- 19 unchanged lines hidden (view full) --- 193 194/* These are getting numerous enough that it's time to create a struct. */ 195 196static char *saved_local_prompt; 197static char *saved_local_prefix; 198static int saved_last_invisible; 199static int saved_visible_length; 200static int saved_prefix_length; | 173static int prompt_visible_length, prompt_prefix_length; 174 175/* The number of invisible characters in the line currently being 176 displayed on the screen. */ 177static int visible_wrap_offset; 178 179/* The number of invisible characters in the prompt string. Static so it 180 can be shared between rl_redisplay and update_line */ --- 19 unchanged lines hidden (view full) --- 200 201/* These are getting numerous enough that it's time to create a struct. */ 202 203static char *saved_local_prompt; 204static char *saved_local_prefix; 205static int saved_last_invisible; 206static int saved_visible_length; 207static int saved_prefix_length; |
208static int saved_local_length; |
|
201static int saved_invis_chars_first_line; 202static int saved_physical_chars; 203 204/* Expand the prompt string S and return the number of visible 205 characters in *LP, if LP is not null. This is currently more-or-less 206 a placeholder for expansion. LIP, if non-null is a place to store the 207 index of the last invisible character in the returned string. NIFLP, 208 if non-zero, is a place to store the number of invisible characters in --- 7 unchanged lines hidden (view full) --- 216 the returned string; all characters except those between \001 and 217 \002 are assumed to be `visible'. */ 218 219static char * 220expand_prompt (pmt, lp, lip, niflp, vlp) 221 char *pmt; 222 int *lp, *lip, *niflp, *vlp; 223{ | 209static int saved_invis_chars_first_line; 210static int saved_physical_chars; 211 212/* Expand the prompt string S and return the number of visible 213 characters in *LP, if LP is not null. This is currently more-or-less 214 a placeholder for expansion. LIP, if non-null is a place to store the 215 index of the last invisible character in the returned string. NIFLP, 216 if non-zero, is a place to store the number of invisible characters in --- 7 unchanged lines hidden (view full) --- 224 the returned string; all characters except those between \001 and 225 \002 are assumed to be `visible'. */ 226 227static char * 228expand_prompt (pmt, lp, lip, niflp, vlp) 229 char *pmt; 230 int *lp, *lip, *niflp, *vlp; 231{ |
224 char *r, *ret, *p; | 232 char *r, *ret, *p, *igstart; |
225 int l, rl, last, ignoring, ninvis, invfl, invflset, ind, pind, physchars; 226 227 /* Short-circuit if we can. */ 228 if ((MB_CUR_MAX <= 1 || rl_byte_oriented) && strchr (pmt, RL_PROMPT_START_IGNORE) == 0) 229 { 230 r = savestring (pmt); 231 if (lp) 232 *lp = strlen (r); --- 7 unchanged lines hidden (view full) --- 240 } 241 242 l = strlen (pmt); 243 r = ret = (char *)xmalloc (l + 1); 244 245 invfl = 0; /* invisible chars in first line of prompt */ 246 invflset = 0; /* we only want to set invfl once */ 247 | 233 int l, rl, last, ignoring, ninvis, invfl, invflset, ind, pind, physchars; 234 235 /* Short-circuit if we can. */ 236 if ((MB_CUR_MAX <= 1 || rl_byte_oriented) && strchr (pmt, RL_PROMPT_START_IGNORE) == 0) 237 { 238 r = savestring (pmt); 239 if (lp) 240 *lp = strlen (r); --- 7 unchanged lines hidden (view full) --- 248 } 249 250 l = strlen (pmt); 251 r = ret = (char *)xmalloc (l + 1); 252 253 invfl = 0; /* invisible chars in first line of prompt */ 254 invflset = 0; /* we only want to set invfl once */ 255 |
256 igstart = 0; |
|
248 for (rl = ignoring = last = ninvis = physchars = 0, p = pmt; p && *p; p++) 249 { 250 /* This code strips the invisible character string markers 251 RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE */ | 257 for (rl = ignoring = last = ninvis = physchars = 0, p = pmt; p && *p; p++) 258 { 259 /* This code strips the invisible character string markers 260 RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE */ |
252 if (*p == RL_PROMPT_START_IGNORE) | 261 if (ignoring == 0 && *p == RL_PROMPT_START_IGNORE) /* XXX - check ignoring? */ |
253 { | 262 { |
254 ignoring++; | 263 ignoring = 1; 264 igstart = p; |
255 continue; 256 } 257 else if (ignoring && *p == RL_PROMPT_END_IGNORE) 258 { 259 ignoring = 0; | 265 continue; 266 } 267 else if (ignoring && *p == RL_PROMPT_END_IGNORE) 268 { 269 ignoring = 0; |
260 if (p[-1] != RL_PROMPT_START_IGNORE) | 270 if (p != (igstart + 1)) |
261 last = r - ret - 1; 262 continue; 263 } 264 else 265 { 266#if defined (HANDLE_MULTIBYTE) 267 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 268 { --- 83 unchanged lines hidden (view full) --- 352 char *p, *t; 353 int c; 354 355 /* Clear out any saved values. */ 356 FREE (local_prompt); 357 FREE (local_prompt_prefix); 358 359 local_prompt = local_prompt_prefix = (char *)0; | 271 last = r - ret - 1; 272 continue; 273 } 274 else 275 { 276#if defined (HANDLE_MULTIBYTE) 277 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 278 { --- 83 unchanged lines hidden (view full) --- 362 char *p, *t; 363 int c; 364 365 /* Clear out any saved values. */ 366 FREE (local_prompt); 367 FREE (local_prompt_prefix); 368 369 local_prompt = local_prompt_prefix = (char *)0; |
370 local_prompt_len = 0; |
|
360 prompt_last_invisible = prompt_invis_chars_first_line = 0; 361 prompt_visible_length = prompt_physical_chars = 0; 362 363 if (prompt == 0 || *prompt == 0) 364 return (0); 365 366 p = strrchr (prompt, '\n'); 367 if (!p) 368 { 369 /* The prompt is only one logical line, though it might wrap. */ 370 local_prompt = expand_prompt (prompt, &prompt_visible_length, 371 &prompt_last_invisible, 372 &prompt_invis_chars_first_line, 373 &prompt_physical_chars); 374 local_prompt_prefix = (char *)0; | 371 prompt_last_invisible = prompt_invis_chars_first_line = 0; 372 prompt_visible_length = prompt_physical_chars = 0; 373 374 if (prompt == 0 || *prompt == 0) 375 return (0); 376 377 p = strrchr (prompt, '\n'); 378 if (!p) 379 { 380 /* The prompt is only one logical line, though it might wrap. */ 381 local_prompt = expand_prompt (prompt, &prompt_visible_length, 382 &prompt_last_invisible, 383 &prompt_invis_chars_first_line, 384 &prompt_physical_chars); 385 local_prompt_prefix = (char *)0; |
386 local_prompt_len = local_prompt ? strlen (local_prompt) : 0; |
|
375 return (prompt_visible_length); 376 } 377 else 378 { 379 /* The prompt spans multiple lines. */ 380 t = ++p; 381 local_prompt = expand_prompt (p, &prompt_visible_length, 382 &prompt_last_invisible, 383 (int *)NULL, 384 &prompt_physical_chars); 385 c = *t; *t = '\0'; 386 /* The portion of the prompt string up to and including the 387 final newline is now null-terminated. */ 388 local_prompt_prefix = expand_prompt (prompt, &prompt_prefix_length, 389 (int *)NULL, 390 &prompt_invis_chars_first_line, 391 (int *)NULL); 392 *t = c; | 387 return (prompt_visible_length); 388 } 389 else 390 { 391 /* The prompt spans multiple lines. */ 392 t = ++p; 393 local_prompt = expand_prompt (p, &prompt_visible_length, 394 &prompt_last_invisible, 395 (int *)NULL, 396 &prompt_physical_chars); 397 c = *t; *t = '\0'; 398 /* The portion of the prompt string up to and including the 399 final newline is now null-terminated. */ 400 local_prompt_prefix = expand_prompt (prompt, &prompt_prefix_length, 401 (int *)NULL, 402 &prompt_invis_chars_first_line, 403 (int *)NULL); 404 *t = c; |
405 local_prompt_len = local_prompt ? strlen (local_prompt) : 0; |
|
393 return (prompt_prefix_length); 394 } 395} 396 397/* Initialize the VISIBLE_LINE and INVISIBLE_LINE arrays, and their associated 398 arrays of line break markers. MINSIZE is the minimum size of VISIBLE_LINE 399 and INVISIBLE_LINE; if it is greater than LINE_SIZE, LINE_SIZE is 400 increased. If the lines have already been allocated, this ensures that --- 40 unchanged lines hidden (view full) --- 441} 442 443/* Basic redisplay algorithm. */ 444void 445rl_redisplay () 446{ 447 register int in, out, c, linenum, cursor_linenum; 448 register char *line; | 406 return (prompt_prefix_length); 407 } 408} 409 410/* Initialize the VISIBLE_LINE and INVISIBLE_LINE arrays, and their associated 411 arrays of line break markers. MINSIZE is the minimum size of VISIBLE_LINE 412 and INVISIBLE_LINE; if it is greater than LINE_SIZE, LINE_SIZE is 413 increased. If the lines have already been allocated, this ensures that --- 40 unchanged lines hidden (view full) --- 454} 455 456/* Basic redisplay algorithm. */ 457void 458rl_redisplay () 459{ 460 register int in, out, c, linenum, cursor_linenum; 461 register char *line; |
449 int c_pos, inv_botlin, lb_botlin, lb_linenum, o_cpos; | 462 int inv_botlin, lb_botlin, lb_linenum, o_cpos; |
450 int newlines, lpos, temp, modmark, n0, num; 451 char *prompt_this_line; 452#if defined (HANDLE_MULTIBYTE) 453 wchar_t wc; 454 size_t wc_bytes; 455 int wc_width; 456 mbstate_t ps; 457 int _rl_wrapped_multicolumn = 0; --- 7 unchanged lines hidden (view full) --- 465 466 if (invisible_line == 0 || vis_lbreaks == 0) 467 { 468 init_line_structures (0); 469 rl_on_new_line (); 470 } 471 472 /* Draw the line into the buffer. */ | 463 int newlines, lpos, temp, modmark, n0, num; 464 char *prompt_this_line; 465#if defined (HANDLE_MULTIBYTE) 466 wchar_t wc; 467 size_t wc_bytes; 468 int wc_width; 469 mbstate_t ps; 470 int _rl_wrapped_multicolumn = 0; --- 7 unchanged lines hidden (view full) --- 478 479 if (invisible_line == 0 || vis_lbreaks == 0) 480 { 481 init_line_structures (0); 482 rl_on_new_line (); 483 } 484 485 /* Draw the line into the buffer. */ |
473 c_pos = -1; | 486 cpos_buffer_position = -1; |
474 475 line = invisible_line; 476 out = inv_botlin = 0; 477 478 /* Mark the line as modified or not. We only do this for history 479 lines. */ 480 modmark = 0; 481 if (_rl_mark_modified_lines && current_history () && rl_undo_list) --- 10 unchanged lines hidden (view full) --- 492 rl_display_fixed = 0; 493 494 /* If the prompt to be displayed is the `primary' readline prompt (the 495 one passed to readline()), use the values we have already expanded. 496 If not, use what's already in rl_display_prompt. WRAP_OFFSET is the 497 number of non-visible characters in the prompt string. */ 498 if (rl_display_prompt == rl_prompt || local_prompt) 499 { | 487 488 line = invisible_line; 489 out = inv_botlin = 0; 490 491 /* Mark the line as modified or not. We only do this for history 492 lines. */ 493 modmark = 0; 494 if (_rl_mark_modified_lines && current_history () && rl_undo_list) --- 10 unchanged lines hidden (view full) --- 505 rl_display_fixed = 0; 506 507 /* If the prompt to be displayed is the `primary' readline prompt (the 508 one passed to readline()), use the values we have already expanded. 509 If not, use what's already in rl_display_prompt. WRAP_OFFSET is the 510 number of non-visible characters in the prompt string. */ 511 if (rl_display_prompt == rl_prompt || local_prompt) 512 { |
500 int local_len = local_prompt ? strlen (local_prompt) : 0; | |
501 if (local_prompt_prefix && forced_display) 502 _rl_output_some_chars (local_prompt_prefix, strlen (local_prompt_prefix)); 503 | 513 if (local_prompt_prefix && forced_display) 514 _rl_output_some_chars (local_prompt_prefix, strlen (local_prompt_prefix)); 515 |
504 if (local_len > 0) | 516 if (local_prompt_len > 0) |
505 { | 517 { |
506 temp = local_len + out + 2; | 518 temp = local_prompt_len + out + 2; |
507 if (temp >= line_size) 508 { 509 line_size = (temp + 1024) - (temp % 1024); 510 visible_line = (char *)xrealloc (visible_line, line_size); 511 line = invisible_line = (char *)xrealloc (invisible_line, line_size); 512 } | 519 if (temp >= line_size) 520 { 521 line_size = (temp + 1024) - (temp % 1024); 522 visible_line = (char *)xrealloc (visible_line, line_size); 523 line = invisible_line = (char *)xrealloc (invisible_line, line_size); 524 } |
513 strncpy (line + out, local_prompt, local_len); 514 out += local_len; | 525 strncpy (line + out, local_prompt, local_prompt_len); 526 out += local_prompt_len; |
515 } 516 line[out] = '\0'; | 527 } 528 line[out] = '\0'; |
517 wrap_offset = local_len - prompt_visible_length; | 529 wrap_offset = local_prompt_len - prompt_visible_length; |
518 } 519 else 520 { 521 int pmtlen; 522 prompt_this_line = strrchr (rl_display_prompt, '\n'); 523 if (!prompt_this_line) 524 prompt_this_line = rl_display_prompt; 525 else --- 84 unchanged lines hidden (view full) --- 610 the first physical line of the prompt. 611 wrap_offset - prompt_invis_chars_first_line is the number of invis 612 chars on the second line. */ 613 614 /* what if lpos is already >= _rl_screenwidth before we start drawing the 615 contents of the command line? */ 616 while (lpos >= _rl_screenwidth) 617 { | 530 } 531 else 532 { 533 int pmtlen; 534 prompt_this_line = strrchr (rl_display_prompt, '\n'); 535 if (!prompt_this_line) 536 prompt_this_line = rl_display_prompt; 537 else --- 84 unchanged lines hidden (view full) --- 622 the first physical line of the prompt. 623 wrap_offset - prompt_invis_chars_first_line is the number of invis 624 chars on the second line. */ 625 626 /* what if lpos is already >= _rl_screenwidth before we start drawing the 627 contents of the command line? */ 628 while (lpos >= _rl_screenwidth) 629 { |
630 int z; |
|
618 /* fix from Darin Johnson <darin@acuson.com> for prompt string with 619 invisible characters that is longer than the screen width. The 620 prompt_invis_chars_first_line variable could be made into an array 621 saying how many invisible characters there are per line, but that's 622 probably too much work for the benefit gained. How many people have 623 prompts that exceed two physical lines? 624 Additional logic fix from Edward Catmur <ed@catmur.co.uk> */ 625#if defined (HANDLE_MULTIBYTE) | 631 /* fix from Darin Johnson <darin@acuson.com> for prompt string with 632 invisible characters that is longer than the screen width. The 633 prompt_invis_chars_first_line variable could be made into an array 634 saying how many invisible characters there are per line, but that's 635 probably too much work for the benefit gained. How many people have 636 prompts that exceed two physical lines? 637 Additional logic fix from Edward Catmur <ed@catmur.co.uk> */ 638#if defined (HANDLE_MULTIBYTE) |
626 n0 = num; 627 temp = local_prompt ? strlen (local_prompt) : 0; 628 while (num < temp) | 639 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) |
629 { | 640 { |
630 if (_rl_col_width (local_prompt, n0, num) > _rl_screenwidth) | 641 n0 = num; 642 temp = local_prompt_len; 643 while (num < temp) |
631 { | 644 { |
632 num = _rl_find_prev_mbchar (local_prompt, num, MB_FIND_ANY); 633 break; | 645 z = _rl_col_width (local_prompt, n0, num); 646 if (z > _rl_screenwidth) 647 { 648 num = _rl_find_prev_mbchar (local_prompt, num, MB_FIND_ANY); 649 break; 650 } 651 else if (z == _rl_screenwidth) 652 break; 653 num++; |
634 } | 654 } |
635 num++; | 655 temp = num; |
636 } | 656 } |
637 temp = num + 638#else 639 temp = ((newlines + 1) * _rl_screenwidth) + | 657 else |
640#endif /* !HANDLE_MULTIBYTE */ | 658#endif /* !HANDLE_MULTIBYTE */ |
641 ((local_prompt_prefix == 0) ? ((newlines == 0) ? prompt_invis_chars_first_line 642 : ((newlines == 1) ? wrap_offset : 0)) 643 : ((newlines == 0) ? wrap_offset :0)); | 659 temp = ((newlines + 1) * _rl_screenwidth); 660 661 /* Now account for invisible characters in the current line. */ 662 temp += ((local_prompt_prefix == 0) ? ((newlines == 0) ? prompt_invis_chars_first_line 663 : ((newlines == 1) ? wrap_offset : 0)) 664 : ((newlines == 0) ? wrap_offset :0)); |
644 645 inv_lbreaks[++newlines] = temp; 646#if defined (HANDLE_MULTIBYTE) | 665 666 inv_lbreaks[++newlines] = temp; 667#if defined (HANDLE_MULTIBYTE) |
647 lpos -= _rl_col_width (local_prompt, n0, num); 648#else 649 lpos -= _rl_screenwidth; | 668 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 669 lpos -= _rl_col_width (local_prompt, n0, num); 670 else |
650#endif | 671#endif |
672 lpos -= _rl_screenwidth; |
|
651 } 652 653 prompt_last_screen_line = newlines; 654 655 /* Draw the rest of the line (after the prompt) into invisible_line, keeping | 673 } 674 675 prompt_last_screen_line = newlines; 676 677 /* Draw the rest of the line (after the prompt) into invisible_line, keeping |
656 track of where the cursor is (c_pos), the number of the line containing | 678 track of where the cursor is (cpos_buffer_position), the number of the line containing |
657 the cursor (lb_linenum), the last line number (lb_botlin and inv_botlin). 658 It maintains an array of line breaks for display (inv_lbreaks). 659 This handles expanding tabs for display and displaying meta characters. */ 660 lb_linenum = 0; 661#if defined (HANDLE_MULTIBYTE) 662 in = 0; 663 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 664 { --- 36 unchanged lines hidden (view full) --- 701 line_size *= 2; 702 visible_line = (char *)xrealloc (visible_line, line_size); 703 invisible_line = (char *)xrealloc (invisible_line, line_size); 704 line = invisible_line; 705 } 706 707 if (in == rl_point) 708 { | 679 the cursor (lb_linenum), the last line number (lb_botlin and inv_botlin). 680 It maintains an array of line breaks for display (inv_lbreaks). 681 This handles expanding tabs for display and displaying meta characters. */ 682 lb_linenum = 0; 683#if defined (HANDLE_MULTIBYTE) 684 in = 0; 685 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 686 { --- 36 unchanged lines hidden (view full) --- 723 line_size *= 2; 724 visible_line = (char *)xrealloc (visible_line, line_size); 725 invisible_line = (char *)xrealloc (invisible_line, line_size); 726 line = invisible_line; 727 } 728 729 if (in == rl_point) 730 { |
709 c_pos = out; | 731 cpos_buffer_position = out; |
710 lb_linenum = newlines; 711 } 712 713#if defined (HANDLE_MULTIBYTE) 714 if (META_CHAR (c) && _rl_output_meta_chars == 0) /* XXX - clean up */ 715#else 716 if (META_CHAR (c)) 717#endif --- 77 unchanged lines hidden (view full) --- 795 { 796 /* The space will be removed in update_line() */ 797 line[out++] = ' '; 798 _rl_wrapped_multicolumn++; 799 CHECK_LPOS(); 800 } 801 if (in == rl_point) 802 { | 732 lb_linenum = newlines; 733 } 734 735#if defined (HANDLE_MULTIBYTE) 736 if (META_CHAR (c) && _rl_output_meta_chars == 0) /* XXX - clean up */ 737#else 738 if (META_CHAR (c)) 739#endif --- 77 unchanged lines hidden (view full) --- 817 { 818 /* The space will be removed in update_line() */ 819 line[out++] = ' '; 820 _rl_wrapped_multicolumn++; 821 CHECK_LPOS(); 822 } 823 if (in == rl_point) 824 { |
803 c_pos = out; | 825 cpos_buffer_position = out; |
804 lb_linenum = newlines; 805 } 806 for (i = in; i < in+wc_bytes; i++) 807 line[out++] = rl_line_buffer[i]; 808 for (i = 0; i < wc_width; i++) 809 CHECK_LPOS(); 810 } 811 else --- 14 unchanged lines hidden (view full) --- 826 wc_bytes = mbrtowc (&wc, rl_line_buffer + in, rl_end - in, &ps); 827 } 828 else 829 in++; 830#endif 831 832 } 833 line[out] = '\0'; | 826 lb_linenum = newlines; 827 } 828 for (i = in; i < in+wc_bytes; i++) 829 line[out++] = rl_line_buffer[i]; 830 for (i = 0; i < wc_width; i++) 831 CHECK_LPOS(); 832 } 833 else --- 14 unchanged lines hidden (view full) --- 848 wc_bytes = mbrtowc (&wc, rl_line_buffer + in, rl_end - in, &ps); 849 } 850 else 851 in++; 852#endif 853 854 } 855 line[out] = '\0'; |
834 if (c_pos < 0) | 856 if (cpos_buffer_position < 0) |
835 { | 857 { |
836 c_pos = out; | 858 cpos_buffer_position = out; |
837 lb_linenum = newlines; 838 } 839 840 inv_botlin = lb_botlin = newlines; 841 CHECK_INV_LBREAKS (); 842 inv_lbreaks[newlines+1] = out; 843 cursor_linenum = lb_linenum; 844 | 859 lb_linenum = newlines; 860 } 861 862 inv_botlin = lb_botlin = newlines; 863 CHECK_INV_LBREAKS (); 864 inv_lbreaks[newlines+1] = out; 865 cursor_linenum = lb_linenum; 866 |
845 /* C_POS == position in buffer where cursor should be placed. | 867 /* CPOS_BUFFER_POSITION == position in buffer where cursor should be placed. |
846 CURSOR_LINENUM == line number where the cursor should be placed. */ 847 848 /* PWP: now is when things get a bit hairy. The visible and invisible 849 line buffers are really multiple lines, which would wrap every 850 (screenwidth - 1) characters. Go through each in turn, finding 851 the changed region and updating it. The line order is top to bottom. */ 852 853 /* If we can move the cursor up and down, then use multiple lines, --- 28 unchanged lines hidden (view full) --- 882#define INV_LLEN(l) (inv_lbreaks[l+1] - inv_lbreaks[l]) 883#define VIS_CHARS(line) (visible_line + vis_lbreaks[line]) 884#define VIS_LINE(line) ((line) > _rl_vis_botlin) ? "" : VIS_CHARS(line) 885#define INV_LINE(line) (invisible_line + inv_lbreaks[line]) 886 887 /* For each line in the buffer, do the updating display. */ 888 for (linenum = 0; linenum <= inv_botlin; linenum++) 889 { | 868 CURSOR_LINENUM == line number where the cursor should be placed. */ 869 870 /* PWP: now is when things get a bit hairy. The visible and invisible 871 line buffers are really multiple lines, which would wrap every 872 (screenwidth - 1) characters. Go through each in turn, finding 873 the changed region and updating it. The line order is top to bottom. */ 874 875 /* If we can move the cursor up and down, then use multiple lines, --- 28 unchanged lines hidden (view full) --- 904#define INV_LLEN(l) (inv_lbreaks[l+1] - inv_lbreaks[l]) 905#define VIS_CHARS(line) (visible_line + vis_lbreaks[line]) 906#define VIS_LINE(line) ((line) > _rl_vis_botlin) ? "" : VIS_CHARS(line) 907#define INV_LINE(line) (invisible_line + inv_lbreaks[line]) 908 909 /* For each line in the buffer, do the updating display. */ 910 for (linenum = 0; linenum <= inv_botlin; linenum++) 911 { |
912 /* This can lead us astray if we execute a program that changes 913 the locale from a non-multibyte to a multibyte one. */ |
|
890 o_cpos = _rl_last_c_pos; 891 cpos_adjusted = 0; 892 update_line (VIS_LINE(linenum), INV_LINE(linenum), linenum, 893 VIS_LLEN(linenum), INV_LLEN(linenum), inv_botlin); 894 895 /* update_line potentially changes _rl_last_c_pos, but doesn't 896 take invisible characters into account, since _rl_last_c_pos 897 is an absolute cursor position in a multibyte locale. See 898 if compensating here is the right thing, or if we have to 899 change update_line itself. There is one case in which 900 update_line adjusts _rl_last_c_pos itself (so it can pass 901 _rl_move_cursor_relative accurate values); it communicates | 914 o_cpos = _rl_last_c_pos; 915 cpos_adjusted = 0; 916 update_line (VIS_LINE(linenum), INV_LINE(linenum), linenum, 917 VIS_LLEN(linenum), INV_LLEN(linenum), inv_botlin); 918 919 /* update_line potentially changes _rl_last_c_pos, but doesn't 920 take invisible characters into account, since _rl_last_c_pos 921 is an absolute cursor position in a multibyte locale. See 922 if compensating here is the right thing, or if we have to 923 change update_line itself. There is one case in which 924 update_line adjusts _rl_last_c_pos itself (so it can pass 925 _rl_move_cursor_relative accurate values); it communicates |
902 this back by setting cpos_adjusted */ | 926 this back by setting cpos_adjusted. If we assume that 927 _rl_last_c_pos is correct (an absolute cursor position) each 928 time update_line is called, then we can assume in our 929 calculations that o_cpos does not need to be adjusted by 930 wrap_offset. */ |
903 if (linenum == 0 && (MB_CUR_MAX > 1 && rl_byte_oriented == 0) && 904 cpos_adjusted == 0 && 905 _rl_last_c_pos != o_cpos && 906 _rl_last_c_pos > wrap_offset && 907 o_cpos < prompt_last_invisible) 908 _rl_last_c_pos -= wrap_offset; 909 910 /* If this is the line with the prompt, we might need to --- 52 unchanged lines hidden (view full) --- 963 964 /* We have to reprint the prompt if it contains invisible 965 characters, since it's not generally OK to just reprint 966 the characters from the current cursor position. But we 967 only need to reprint it if the cursor is before the last 968 invisible character in the prompt string. */ 969 nleft = prompt_visible_length + wrap_offset; 970 if (cursor_linenum == 0 && wrap_offset > 0 && _rl_last_c_pos > 0 && | 931 if (linenum == 0 && (MB_CUR_MAX > 1 && rl_byte_oriented == 0) && 932 cpos_adjusted == 0 && 933 _rl_last_c_pos != o_cpos && 934 _rl_last_c_pos > wrap_offset && 935 o_cpos < prompt_last_invisible) 936 _rl_last_c_pos -= wrap_offset; 937 938 /* If this is the line with the prompt, we might need to --- 52 unchanged lines hidden (view full) --- 991 992 /* We have to reprint the prompt if it contains invisible 993 characters, since it's not generally OK to just reprint 994 the characters from the current cursor position. But we 995 only need to reprint it if the cursor is before the last 996 invisible character in the prompt string. */ 997 nleft = prompt_visible_length + wrap_offset; 998 if (cursor_linenum == 0 && wrap_offset > 0 && _rl_last_c_pos > 0 && |
971 _rl_last_c_pos <= prompt_last_invisible && local_prompt) | 999#if 0 1000 _rl_last_c_pos <= PROMPT_ENDING_INDEX && local_prompt) 1001#else 1002 _rl_last_c_pos < PROMPT_ENDING_INDEX && local_prompt) 1003#endif |
972 { 973#if defined (__MSDOS__) 974 putc ('\r', rl_outstream); 975#else 976 if (_rl_term_cr) 977 tputs (_rl_term_cr, 1, _rl_output_character_function); 978#endif 979 _rl_output_some_chars (local_prompt, nleft); 980 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 981 _rl_last_c_pos = _rl_col_width (local_prompt, 0, nleft) - wrap_offset; 982 else 983 _rl_last_c_pos = nleft; 984 } 985 986 /* Where on that line? And where does that line start 987 in the buffer? */ 988 pos = inv_lbreaks[cursor_linenum]; 989 /* nleft == number of characters in the line buffer between the | 1004 { 1005#if defined (__MSDOS__) 1006 putc ('\r', rl_outstream); 1007#else 1008 if (_rl_term_cr) 1009 tputs (_rl_term_cr, 1, _rl_output_character_function); 1010#endif 1011 _rl_output_some_chars (local_prompt, nleft); 1012 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 1013 _rl_last_c_pos = _rl_col_width (local_prompt, 0, nleft) - wrap_offset; 1014 else 1015 _rl_last_c_pos = nleft; 1016 } 1017 1018 /* Where on that line? And where does that line start 1019 in the buffer? */ 1020 pos = inv_lbreaks[cursor_linenum]; 1021 /* nleft == number of characters in the line buffer between the |
990 start of the line and the cursor position. */ 991 nleft = c_pos - pos; | 1022 start of the line and the desired cursor position. */ 1023 nleft = cpos_buffer_position - pos; |
992 993 /* NLEFT is now a number of characters in a buffer. When in a 994 multibyte locale, however, _rl_last_c_pos is an absolute cursor 995 position that doesn't take invisible characters in the prompt 996 into account. We use a fudge factor to compensate. */ 997 998 /* Since _rl_backspace() doesn't know about invisible characters in the 999 prompt, and there's no good way to tell it, we compensate for 1000 those characters here and call _rl_backspace() directly. */ 1001 if (wrap_offset && cursor_linenum == 0 && nleft < _rl_last_c_pos) 1002 { | 1024 1025 /* NLEFT is now a number of characters in a buffer. When in a 1026 multibyte locale, however, _rl_last_c_pos is an absolute cursor 1027 position that doesn't take invisible characters in the prompt 1028 into account. We use a fudge factor to compensate. */ 1029 1030 /* Since _rl_backspace() doesn't know about invisible characters in the 1031 prompt, and there's no good way to tell it, we compensate for 1032 those characters here and call _rl_backspace() directly. */ 1033 if (wrap_offset && cursor_linenum == 0 && nleft < _rl_last_c_pos) 1034 { |
1035 /* TX == new physical cursor position in multibyte locale. */ |
|
1003 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 1004 tx = _rl_col_width (&visible_line[pos], 0, nleft) - visible_wrap_offset; 1005 else 1006 tx = nleft; 1007 if (_rl_last_c_pos > tx) 1008 { 1009 _rl_backspace (_rl_last_c_pos - tx); /* XXX */ 1010 _rl_last_c_pos = tx; --- 17 unchanged lines hidden (view full) --- 1028 1029 /* Always at top line. */ 1030 _rl_last_v_pos = 0; 1031 1032 /* Compute where in the buffer the displayed line should start. This 1033 will be LMARGIN. */ 1034 1035 /* The number of characters that will be displayed before the cursor. */ | 1036 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 1037 tx = _rl_col_width (&visible_line[pos], 0, nleft) - visible_wrap_offset; 1038 else 1039 tx = nleft; 1040 if (_rl_last_c_pos > tx) 1041 { 1042 _rl_backspace (_rl_last_c_pos - tx); /* XXX */ 1043 _rl_last_c_pos = tx; --- 17 unchanged lines hidden (view full) --- 1061 1062 /* Always at top line. */ 1063 _rl_last_v_pos = 0; 1064 1065 /* Compute where in the buffer the displayed line should start. This 1066 will be LMARGIN. */ 1067 1068 /* The number of characters that will be displayed before the cursor. */ |
1036 ndisp = c_pos - wrap_offset; | 1069 ndisp = cpos_buffer_position - wrap_offset; |
1037 nleft = prompt_visible_length + wrap_offset; 1038 /* Where the new cursor position will be on the screen. This can be 1039 longer than SCREENWIDTH; if it is, lmargin will be adjusted. */ | 1070 nleft = prompt_visible_length + wrap_offset; 1071 /* Where the new cursor position will be on the screen. This can be 1072 longer than SCREENWIDTH; if it is, lmargin will be adjusted. */ |
1040 phys_c_pos = c_pos - (last_lmargin ? last_lmargin : wrap_offset); | 1073 phys_c_pos = cpos_buffer_position - (last_lmargin ? last_lmargin : wrap_offset); |
1041 t = _rl_screenwidth / 3; 1042 1043 /* If the number of characters had already exceeded the screenwidth, 1044 last_lmargin will be > 0. */ 1045 1046 /* If the number of characters to be displayed is more than the screen 1047 width, compute the starting offset so that the cursor is about 1048 two-thirds of the way across the screen. */ 1049 if (phys_c_pos > _rl_screenwidth - 2) 1050 { | 1074 t = _rl_screenwidth / 3; 1075 1076 /* If the number of characters had already exceeded the screenwidth, 1077 last_lmargin will be > 0. */ 1078 1079 /* If the number of characters to be displayed is more than the screen 1080 width, compute the starting offset so that the cursor is about 1081 two-thirds of the way across the screen. */ 1082 if (phys_c_pos > _rl_screenwidth - 2) 1083 { |
1051 lmargin = c_pos - (2 * t); | 1084 lmargin = cpos_buffer_position - (2 * t); |
1052 if (lmargin < 0) 1053 lmargin = 0; 1054 /* If the left margin would be in the middle of a prompt with 1055 invisible characters, don't display the prompt at all. */ 1056 if (wrap_offset && lmargin > 0 && lmargin < nleft) 1057 lmargin = nleft; 1058 } 1059 else if (ndisp < _rl_screenwidth - 2) /* XXX - was -1 */ 1060 lmargin = 0; 1061 else if (phys_c_pos < 1) 1062 { 1063 /* If we are moving back towards the beginning of the line and 1064 the last margin is no longer correct, compute a new one. */ | 1085 if (lmargin < 0) 1086 lmargin = 0; 1087 /* If the left margin would be in the middle of a prompt with 1088 invisible characters, don't display the prompt at all. */ 1089 if (wrap_offset && lmargin > 0 && lmargin < nleft) 1090 lmargin = nleft; 1091 } 1092 else if (ndisp < _rl_screenwidth - 2) /* XXX - was -1 */ 1093 lmargin = 0; 1094 else if (phys_c_pos < 1) 1095 { 1096 /* If we are moving back towards the beginning of the line and 1097 the last margin is no longer correct, compute a new one. */ |
1065 lmargin = ((c_pos - 1) / t) * t; /* XXX */ | 1098 lmargin = ((cpos_buffer_position - 1) / t) * t; /* XXX */ |
1066 if (wrap_offset && lmargin > 0 && lmargin < nleft) 1067 lmargin = nleft; 1068 } 1069 else 1070 lmargin = last_lmargin; 1071 1072 /* If the first character on the screen isn't the first character 1073 in the display line, indicate this with a special character. */ --- 28 unchanged lines hidden (view full) --- 1102 { 1103 nleft = _rl_screenwidth - t; 1104 _rl_clear_to_eol (nleft); 1105 } 1106 visible_first_line_len = out - lmargin - M_OFFSET (lmargin, wrap_offset); 1107 if (visible_first_line_len > _rl_screenwidth) 1108 visible_first_line_len = _rl_screenwidth; 1109 | 1099 if (wrap_offset && lmargin > 0 && lmargin < nleft) 1100 lmargin = nleft; 1101 } 1102 else 1103 lmargin = last_lmargin; 1104 1105 /* If the first character on the screen isn't the first character 1106 in the display line, indicate this with a special character. */ --- 28 unchanged lines hidden (view full) --- 1135 { 1136 nleft = _rl_screenwidth - t; 1137 _rl_clear_to_eol (nleft); 1138 } 1139 visible_first_line_len = out - lmargin - M_OFFSET (lmargin, wrap_offset); 1140 if (visible_first_line_len > _rl_screenwidth) 1141 visible_first_line_len = _rl_screenwidth; 1142 |
1110 _rl_move_cursor_relative (c_pos - lmargin, &invisible_line[lmargin]); | 1143 _rl_move_cursor_relative (cpos_buffer_position - lmargin, &invisible_line[lmargin]); |
1111 last_lmargin = lmargin; 1112 } 1113 } 1114 fflush (rl_outstream); 1115 1116 /* Swap visible and non-visible lines. */ 1117 { 1118 char *vtemp = visible_line; --- 41 unchanged lines hidden (view full) --- 1160 int current_line, omax, nmax, inv_botlin; 1161{ 1162 register char *ofd, *ols, *oe, *nfd, *nls, *ne; 1163 int temp, lendiff, wsatend, od, nd; 1164 int current_invis_chars; 1165 int col_lendiff, col_temp; 1166#if defined (HANDLE_MULTIBYTE) 1167 mbstate_t ps_new, ps_old; | 1144 last_lmargin = lmargin; 1145 } 1146 } 1147 fflush (rl_outstream); 1148 1149 /* Swap visible and non-visible lines. */ 1150 { 1151 char *vtemp = visible_line; --- 41 unchanged lines hidden (view full) --- 1193 int current_line, omax, nmax, inv_botlin; 1194{ 1195 register char *ofd, *ols, *oe, *nfd, *nls, *ne; 1196 int temp, lendiff, wsatend, od, nd; 1197 int current_invis_chars; 1198 int col_lendiff, col_temp; 1199#if defined (HANDLE_MULTIBYTE) 1200 mbstate_t ps_new, ps_old; |
1168 int new_offset, old_offset, tmp; | 1201 int new_offset, old_offset; |
1169#endif 1170 1171 /* If we're at the right edge of a terminal that supports xn, we're 1172 ready to wrap around, so do so. This fixes problems with knowing 1173 the exact cursor position and cut-and-paste with certain terminal 1174 emulators. In this calculation, TEMP is the physical screen 1175 position of the cursor. */ 1176 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) --- 216 unchanged lines hidden (view full) --- 1393 string, then redraw the entire prompt string. We can only do this 1394 reliably if the terminal supports a `cr' capability. 1395 1396 This is not an efficiency hack -- there is a problem with redrawing 1397 portions of the prompt string if they contain terminal escape 1398 sequences (like drawing the `unbold' sequence without a corresponding 1399 `bold') that manifests itself on certain terminals. */ 1400 | 1202#endif 1203 1204 /* If we're at the right edge of a terminal that supports xn, we're 1205 ready to wrap around, so do so. This fixes problems with knowing 1206 the exact cursor position and cut-and-paste with certain terminal 1207 emulators. In this calculation, TEMP is the physical screen 1208 position of the cursor. */ 1209 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) --- 216 unchanged lines hidden (view full) --- 1426 string, then redraw the entire prompt string. We can only do this 1427 reliably if the terminal supports a `cr' capability. 1428 1429 This is not an efficiency hack -- there is a problem with redrawing 1430 portions of the prompt string if they contain terminal escape 1431 sequences (like drawing the `unbold' sequence without a corresponding 1432 `bold') that manifests itself on certain terminals. */ 1433 |
1401 lendiff = local_prompt ? strlen (local_prompt) : 0; | 1434 lendiff = local_prompt_len; |
1402 od = ofd - old; /* index of first difference in visible line */ 1403 if (current_line == 0 && !_rl_horizontal_scroll_mode && 1404 _rl_term_cr && lendiff > prompt_visible_length && _rl_last_c_pos > 0 && | 1435 od = ofd - old; /* index of first difference in visible line */ 1436 if (current_line == 0 && !_rl_horizontal_scroll_mode && 1437 _rl_term_cr && lendiff > prompt_visible_length && _rl_last_c_pos > 0 && |
1405 od >= lendiff && _rl_last_c_pos <= prompt_last_invisible) | 1438 od >= lendiff && _rl_last_c_pos < PROMPT_ENDING_INDEX) |
1406 { 1407#if defined (__MSDOS__) 1408 putc ('\r', rl_outstream); 1409#else 1410 tputs (_rl_term_cr, 1, _rl_output_character_function); 1411#endif 1412 _rl_output_some_chars (local_prompt, lendiff); 1413 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 1414 { 1415 /* We take wrap_offset into account here so we can pass correct 1416 information to _rl_move_cursor_relative. */ 1417 _rl_last_c_pos = _rl_col_width (local_prompt, 0, lendiff) - wrap_offset; 1418 cpos_adjusted = 1; 1419 } 1420 else 1421 _rl_last_c_pos = lendiff; 1422 } 1423 | 1439 { 1440#if defined (__MSDOS__) 1441 putc ('\r', rl_outstream); 1442#else 1443 tputs (_rl_term_cr, 1, _rl_output_character_function); 1444#endif 1445 _rl_output_some_chars (local_prompt, lendiff); 1446 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 1447 { 1448 /* We take wrap_offset into account here so we can pass correct 1449 information to _rl_move_cursor_relative. */ 1450 _rl_last_c_pos = _rl_col_width (local_prompt, 0, lendiff) - wrap_offset; 1451 cpos_adjusted = 1; 1452 } 1453 else 1454 _rl_last_c_pos = lendiff; 1455 } 1456 |
1457 /* When this function returns, _rl_last_c_pos is correct, and an absolute 1458 cursor postion in multibyte mode, but a buffer index when not in a 1459 multibyte locale. */ |
|
1424 _rl_move_cursor_relative (od, old); | 1460 _rl_move_cursor_relative (od, old); |
1461#if 1 1462#if defined (HANDLE_MULTIBYTE) 1463 /* We need to indicate that the cursor position is correct in the presence of 1464 invisible characters in the prompt string. Let's see if setting this when 1465 we make sure we're at the end of the drawn prompt string works. */ 1466 if (current_line == 0 && MB_CUR_MAX > 1 && rl_byte_oriented == 0 && _rl_last_c_pos == prompt_physical_chars) 1467 cpos_adjusted = 1; 1468#endif 1469#endif |
|
1425 1426 /* if (len (new) > len (old)) 1427 lendiff == difference in buffer 1428 col_lendiff == difference on screen 1429 When not using multibyte characters, these are equal */ 1430 lendiff = (nls - nfd) - (ols - ofd); 1431 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 1432 col_lendiff = _rl_col_width (new, nfd - new, nls - new) - _rl_col_width (old, ofd - old, ols - old); --- 211 unchanged lines hidden (view full) --- 1644 1645 return 0; 1646} 1647 1648/* Actually update the display, period. */ 1649int 1650rl_forced_update_display () 1651{ | 1470 1471 /* if (len (new) > len (old)) 1472 lendiff == difference in buffer 1473 col_lendiff == difference on screen 1474 When not using multibyte characters, these are equal */ 1475 lendiff = (nls - nfd) - (ols - ofd); 1476 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 1477 col_lendiff = _rl_col_width (new, nfd - new, nls - new) - _rl_col_width (old, ofd - old, ols - old); --- 211 unchanged lines hidden (view full) --- 1689 1690 return 0; 1691} 1692 1693/* Actually update the display, period. */ 1694int 1695rl_forced_update_display () 1696{ |
1697 register char *temp; 1698 |
|
1652 if (visible_line) 1653 { | 1699 if (visible_line) 1700 { |
1654 register char *temp = visible_line; 1655 | 1701 temp = visible_line; |
1656 while (*temp) 1657 *temp++ = '\0'; 1658 } 1659 rl_on_new_line (); 1660 forced_display++; 1661 (*rl_redisplay_function) (); 1662 return 0; 1663} --- 18 unchanged lines hidden (view full) --- 1682 /* If we have multibyte characters, NEW is indexed by the buffer point in 1683 a multibyte string, but _rl_last_c_pos is the display position. In 1684 this case, NEW's display position is not obvious and must be 1685 calculated. We need to account for invisible characters in this line, 1686 as long as we are past them and they are counted by _rl_col_width. */ 1687 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 1688 { 1689 dpos = _rl_col_width (data, 0, new); | 1702 while (*temp) 1703 *temp++ = '\0'; 1704 } 1705 rl_on_new_line (); 1706 forced_display++; 1707 (*rl_redisplay_function) (); 1708 return 0; 1709} --- 18 unchanged lines hidden (view full) --- 1728 /* If we have multibyte characters, NEW is indexed by the buffer point in 1729 a multibyte string, but _rl_last_c_pos is the display position. In 1730 this case, NEW's display position is not obvious and must be 1731 calculated. We need to account for invisible characters in this line, 1732 as long as we are past them and they are counted by _rl_col_width. */ 1733 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 1734 { 1735 dpos = _rl_col_width (data, 0, new); |
1690 if (dpos > woff) 1691 dpos -= woff; | 1736 if (dpos > prompt_last_invisible) /* XXX - don't use woff here */ 1737 { 1738 dpos -= woff; 1739 /* Since this will be assigned to _rl_last_c_pos at the end (more 1740 precisely, _rl_last_c_pos == dpos when this function returns), 1741 let the caller know. */ 1742 cpos_adjusted = 1; 1743 } |
1692 } 1693 else 1694#endif 1695 dpos = new; 1696 1697 /* If we don't have to do anything, then return. */ 1698 if (cpos == dpos) 1699 return; 1700 1701 /* It may be faster to output a CR, and then move forwards instead 1702 of moving backwards. */ 1703 /* i == current physical cursor position. */ 1704#if defined (HANDLE_MULTIBYTE) 1705 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 1706 i = _rl_last_c_pos; 1707 else 1708#endif 1709 i = _rl_last_c_pos - woff; | 1744 } 1745 else 1746#endif 1747 dpos = new; 1748 1749 /* If we don't have to do anything, then return. */ 1750 if (cpos == dpos) 1751 return; 1752 1753 /* It may be faster to output a CR, and then move forwards instead 1754 of moving backwards. */ 1755 /* i == current physical cursor position. */ 1756#if defined (HANDLE_MULTIBYTE) 1757 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 1758 i = _rl_last_c_pos; 1759 else 1760#endif 1761 i = _rl_last_c_pos - woff; |
1710 if (new == 0 || CR_FASTER (new, _rl_last_c_pos) || | 1762 if (dpos == 0 || CR_FASTER (dpos, _rl_last_c_pos) || |
1711 (_rl_term_autowrap && i == _rl_screenwidth)) 1712 { 1713#if defined (__MSDOS__) 1714 putc ('\r', rl_outstream); 1715#else 1716 tputs (_rl_term_cr, 1, _rl_output_character_function); 1717#endif /* !__MSDOS__ */ 1718 cpos = _rl_last_c_pos = 0; --- 5 unchanged lines hidden (view full) --- 1724 to move the cursor forward if there is one, else print that 1725 portion of the output buffer again. Which is cheaper? */ 1726 1727 /* The above comment is left here for posterity. It is faster 1728 to print one character (non-control) than to print a control 1729 sequence telling the terminal to move forward one character. 1730 That kind of control is for people who don't know what the 1731 data is underneath the cursor. */ | 1763 (_rl_term_autowrap && i == _rl_screenwidth)) 1764 { 1765#if defined (__MSDOS__) 1766 putc ('\r', rl_outstream); 1767#else 1768 tputs (_rl_term_cr, 1, _rl_output_character_function); 1769#endif /* !__MSDOS__ */ 1770 cpos = _rl_last_c_pos = 0; --- 5 unchanged lines hidden (view full) --- 1776 to move the cursor forward if there is one, else print that 1777 portion of the output buffer again. Which is cheaper? */ 1778 1779 /* The above comment is left here for posterity. It is faster 1780 to print one character (non-control) than to print a control 1781 sequence telling the terminal to move forward one character. 1782 That kind of control is for people who don't know what the 1783 data is underneath the cursor. */ |
1732#if defined (HACK_TERMCAP_MOTION) 1733 if (_rl_term_forward_char) 1734 { 1735 for (i = cpos; i < dpos; i++) 1736 tputs (_rl_term_forward_char, 1, _rl_output_character_function); 1737 } 1738 else 1739#endif /* HACK_TERMCAP_MOTION */ | 1784 1785 /* However, we need a handle on where the current display position is 1786 in the buffer for the immediately preceding comment to be true. 1787 In multibyte locales, we don't currently have that info available. 1788 Without it, we don't know where the data we have to display begins 1789 in the buffer and we have to go back to the beginning of the screen 1790 line. In this case, we can use the terminal sequence to move forward 1791 if it's available. */ |
1740 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 1741 { | 1792 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) 1793 { |
1742 tputs (_rl_term_cr, 1, _rl_output_character_function); 1743 for (i = 0; i < new; i++) 1744 putc (data[i], rl_outstream); | 1794 if (_rl_term_forward_char) 1795 { 1796 for (i = cpos; i < dpos; i++) 1797 tputs (_rl_term_forward_char, 1, _rl_output_character_function); 1798 } 1799 else 1800 { 1801 tputs (_rl_term_cr, 1, _rl_output_character_function); 1802 for (i = 0; i < new; i++) 1803 putc (data[i], rl_outstream); 1804 } |
1745 } 1746 else 1747 for (i = cpos; i < new; i++) 1748 putc (data[i], rl_outstream); 1749 } 1750 1751#if defined (HANDLE_MULTIBYTE) 1752 /* NEW points to the buffer point, but _rl_last_c_pos is the display point. --- 132 unchanged lines hidden (view full) --- 1885 msg_saved_prompt = 1; 1886 } 1887 rl_display_prompt = msg_buf; 1888 local_prompt = expand_prompt (msg_buf, &prompt_visible_length, 1889 &prompt_last_invisible, 1890 &prompt_invis_chars_first_line, 1891 &prompt_physical_chars); 1892 local_prompt_prefix = (char *)NULL; | 1805 } 1806 else 1807 for (i = cpos; i < new; i++) 1808 putc (data[i], rl_outstream); 1809 } 1810 1811#if defined (HANDLE_MULTIBYTE) 1812 /* NEW points to the buffer point, but _rl_last_c_pos is the display point. --- 132 unchanged lines hidden (view full) --- 1945 msg_saved_prompt = 1; 1946 } 1947 rl_display_prompt = msg_buf; 1948 local_prompt = expand_prompt (msg_buf, &prompt_visible_length, 1949 &prompt_last_invisible, 1950 &prompt_invis_chars_first_line, 1951 &prompt_physical_chars); 1952 local_prompt_prefix = (char *)NULL; |
1953 local_prompt_len = local_prompt ? strlen (local_prompt) : 0; |
|
1893 (*rl_redisplay_function) (); 1894 1895 return 0; 1896} 1897#else /* !USE_VARARGS */ 1898int 1899rl_message (format, arg1, arg2) 1900 char *format; --- 7 unchanged lines hidden (view full) --- 1908 rl_save_prompt (); 1909 msg_saved_prompt = 1; 1910 } 1911 local_prompt = expand_prompt (msg_buf, &prompt_visible_length, 1912 &prompt_last_invisible, 1913 &prompt_invis_chars_first_line, 1914 &prompt_physical_chars); 1915 local_prompt_prefix = (char *)NULL; | 1954 (*rl_redisplay_function) (); 1955 1956 return 0; 1957} 1958#else /* !USE_VARARGS */ 1959int 1960rl_message (format, arg1, arg2) 1961 char *format; --- 7 unchanged lines hidden (view full) --- 1969 rl_save_prompt (); 1970 msg_saved_prompt = 1; 1971 } 1972 local_prompt = expand_prompt (msg_buf, &prompt_visible_length, 1973 &prompt_last_invisible, 1974 &prompt_invis_chars_first_line, 1975 &prompt_physical_chars); 1976 local_prompt_prefix = (char *)NULL; |
1977 local_prompt_len = local_prompt ? strlen (local_prompt) : 0; |
|
1916 (*rl_redisplay_function) (); 1917 1918 return 0; 1919} 1920#endif /* !USE_VARARGS */ 1921 1922/* How to clear things from the "echo-area". */ 1923int --- 20 unchanged lines hidden (view full) --- 1944} 1945 1946void 1947rl_save_prompt () 1948{ 1949 saved_local_prompt = local_prompt; 1950 saved_local_prefix = local_prompt_prefix; 1951 saved_prefix_length = prompt_prefix_length; | 1978 (*rl_redisplay_function) (); 1979 1980 return 0; 1981} 1982#endif /* !USE_VARARGS */ 1983 1984/* How to clear things from the "echo-area". */ 1985int --- 20 unchanged lines hidden (view full) --- 2006} 2007 2008void 2009rl_save_prompt () 2010{ 2011 saved_local_prompt = local_prompt; 2012 saved_local_prefix = local_prompt_prefix; 2013 saved_prefix_length = prompt_prefix_length; |
2014 saved_local_length = local_prompt_len; |
|
1952 saved_last_invisible = prompt_last_invisible; 1953 saved_visible_length = prompt_visible_length; 1954 saved_invis_chars_first_line = prompt_invis_chars_first_line; 1955 saved_physical_chars = prompt_physical_chars; 1956 1957 local_prompt = local_prompt_prefix = (char *)0; | 2015 saved_last_invisible = prompt_last_invisible; 2016 saved_visible_length = prompt_visible_length; 2017 saved_invis_chars_first_line = prompt_invis_chars_first_line; 2018 saved_physical_chars = prompt_physical_chars; 2019 2020 local_prompt = local_prompt_prefix = (char *)0; |
2021 local_prompt_len = 0; |
|
1958 prompt_last_invisible = prompt_visible_length = prompt_prefix_length = 0; 1959 prompt_invis_chars_first_line = prompt_physical_chars = 0; 1960} 1961 1962void 1963rl_restore_prompt () 1964{ 1965 FREE (local_prompt); 1966 FREE (local_prompt_prefix); 1967 1968 local_prompt = saved_local_prompt; 1969 local_prompt_prefix = saved_local_prefix; | 2022 prompt_last_invisible = prompt_visible_length = prompt_prefix_length = 0; 2023 prompt_invis_chars_first_line = prompt_physical_chars = 0; 2024} 2025 2026void 2027rl_restore_prompt () 2028{ 2029 FREE (local_prompt); 2030 FREE (local_prompt_prefix); 2031 2032 local_prompt = saved_local_prompt; 2033 local_prompt_prefix = saved_local_prefix; |
2034 local_prompt_len = saved_local_length; |
|
1970 prompt_prefix_length = saved_prefix_length; 1971 prompt_last_invisible = saved_last_invisible; 1972 prompt_visible_length = saved_visible_length; 1973 prompt_invis_chars_first_line = saved_invis_chars_first_line; 1974 prompt_physical_chars = saved_physical_chars; 1975 1976 /* can test saved_local_prompt to see if prompt info has been saved. */ 1977 saved_local_prompt = saved_local_prefix = (char *)0; | 2035 prompt_prefix_length = saved_prefix_length; 2036 prompt_last_invisible = saved_last_invisible; 2037 prompt_visible_length = saved_visible_length; 2038 prompt_invis_chars_first_line = saved_invis_chars_first_line; 2039 prompt_physical_chars = saved_physical_chars; 2040 2041 /* can test saved_local_prompt to see if prompt info has been saved. */ 2042 saved_local_prompt = saved_local_prefix = (char *)0; |
2043 saved_local_length = 0; |
|
1978 saved_last_invisible = saved_visible_length = saved_prefix_length = 0; 1979 saved_invis_chars_first_line = saved_physical_chars = 0; 1980} 1981 1982char * 1983_rl_make_prompt_for_search (pchar) 1984 int pchar; 1985{ --- 172 unchanged lines hidden (view full) --- 2158 } 2159 _rl_move_vert (_rl_vis_botlin); 2160 /* If we've wrapped lines, remove the final xterm line-wrap flag. */ 2161 if (full_lines && _rl_term_autowrap && (VIS_LLEN(_rl_vis_botlin) == _rl_screenwidth)) 2162 { 2163 char *last_line; 2164 2165 last_line = &visible_line[vis_lbreaks[_rl_vis_botlin]]; | 2044 saved_last_invisible = saved_visible_length = saved_prefix_length = 0; 2045 saved_invis_chars_first_line = saved_physical_chars = 0; 2046} 2047 2048char * 2049_rl_make_prompt_for_search (pchar) 2050 int pchar; 2051{ --- 172 unchanged lines hidden (view full) --- 2224 } 2225 _rl_move_vert (_rl_vis_botlin); 2226 /* If we've wrapped lines, remove the final xterm line-wrap flag. */ 2227 if (full_lines && _rl_term_autowrap && (VIS_LLEN(_rl_vis_botlin) == _rl_screenwidth)) 2228 { 2229 char *last_line; 2230 2231 last_line = &visible_line[vis_lbreaks[_rl_vis_botlin]]; |
2166 _rl_move_cursor_relative (_rl_screenwidth - 1, last_line); | 2232 cpos_buffer_position = -1; /* don't know where we are in buffer */ 2233 _rl_move_cursor_relative (_rl_screenwidth - 1, last_line); /* XXX */ |
2167 _rl_clear_to_eol (0); 2168 putc (last_line[_rl_screenwidth - 1], rl_outstream); 2169 } 2170 _rl_vis_botlin = 0; 2171 rl_crlf (); 2172 fflush (rl_outstream); 2173 rl_display_fixed++; 2174} --- 26 unchanged lines hidden (view full) --- 2201 rl_save_prompt (); 2202 2203 rl_display_prompt = t; 2204 local_prompt = expand_prompt (t, &prompt_visible_length, 2205 &prompt_last_invisible, 2206 &prompt_invis_chars_first_line, 2207 &prompt_physical_chars); 2208 local_prompt_prefix = (char *)NULL; | 2234 _rl_clear_to_eol (0); 2235 putc (last_line[_rl_screenwidth - 1], rl_outstream); 2236 } 2237 _rl_vis_botlin = 0; 2238 rl_crlf (); 2239 fflush (rl_outstream); 2240 rl_display_fixed++; 2241} --- 26 unchanged lines hidden (view full) --- 2268 rl_save_prompt (); 2269 2270 rl_display_prompt = t; 2271 local_prompt = expand_prompt (t, &prompt_visible_length, 2272 &prompt_last_invisible, 2273 &prompt_invis_chars_first_line, 2274 &prompt_physical_chars); 2275 local_prompt_prefix = (char *)NULL; |
2276 local_prompt_len = local_prompt ? strlen (local_prompt) : 0; |
|
2209 2210 rl_forced_update_display (); 2211 2212 rl_display_prompt = oldp; 2213 rl_restore_prompt(); 2214} 2215 2216/* Redisplay the current line after a SIGWINCH is received. */ --- 86 unchanged lines hidden (view full) --- 2303 In the case of multibyte characters with stateful encoding, we have to 2304 scan from the beginning of the string to take the state into account. */ 2305static int 2306_rl_col_width (str, start, end) 2307 const char *str; 2308 int start, end; 2309{ 2310 wchar_t wc; | 2277 2278 rl_forced_update_display (); 2279 2280 rl_display_prompt = oldp; 2281 rl_restore_prompt(); 2282} 2283 2284/* Redisplay the current line after a SIGWINCH is received. */ --- 86 unchanged lines hidden (view full) --- 2371 In the case of multibyte characters with stateful encoding, we have to 2372 scan from the beginning of the string to take the state into account. */ 2373static int 2374_rl_col_width (str, start, end) 2375 const char *str; 2376 int start, end; 2377{ 2378 wchar_t wc; |
2311 mbstate_t ps = {0}; | 2379 mbstate_t ps; |
2312 int tmp, point, width, max; 2313 2314 if (end <= start) 2315 return 0; 2316 | 2380 int tmp, point, width, max; 2381 2382 if (end <= start) 2383 return 0; 2384 |
2385 memset (&ps, 0, sizeof (mbstate_t)); 2386 |
|
2317 point = 0; 2318 max = end; 2319 2320 while (point < start) 2321 { 2322 tmp = mbrlen (str + point, max, &ps); 2323 if (MB_INVALIDCH ((size_t)tmp)) 2324 { --- 58 unchanged lines hidden --- | 2387 point = 0; 2388 max = end; 2389 2390 while (point < start) 2391 { 2392 tmp = mbrlen (str + point, max, &ps); 2393 if (MB_INVALIDCH ((size_t)tmp)) 2394 { --- 58 unchanged lines hidden --- |