1 /* display.c -- readline redisplay facility. */
3 /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
5 This file is part of the GNU Readline Library, a library for
6 reading lines of text with interactive input and history editing.
8 The GNU Readline Library is free software; you can redistribute it
9 and/or modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2, or
11 (at your option) any later version.
13 The GNU Readline Library is distributed in the hope that it will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 The GNU General Public License is often shipped with GNU software, and
19 is generally kept in a file called COPYING or LICENSE. If you do not
20 have a copy of the license, write to the Free Software Foundation,
21 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
22 #define READLINE_LIBRARY
24 #if defined (HAVE_CONFIG_H)
28 #include <sys/types.h>
30 #if defined (HAVE_UNISTD_H)
32 #endif /* HAVE_UNISTD_H */
34 #include "posixstat.h"
36 #if defined (HAVE_STDLIB_H)
39 # include "ansi_stdlib.h"
40 #endif /* HAVE_STDLIB_H */
44 /* System-specific feature definitions and include files. */
47 /* Termcap library stuff. */
50 /* Some standard library routines. */
54 #include "rlprivate.h"
57 #if !defined (strchr) && !defined (__STDC__)
58 extern char *strchr (), *strrchr ();
59 #endif /* !strchr && !__STDC__ */
61 #if defined (HACK_TERMCAP_MOTION)
62 extern char *_rl_term_forward_char
;
65 static void update_line
__P((char *, char *, int, int, int, int));
66 static void space_to_eol
__P((int));
67 static void delete_chars
__P((int));
68 static void insert_some_chars
__P((char *, int));
69 static void cr
__P((void));
71 static int *inv_lbreaks
, *vis_lbreaks
;
72 static int inv_lbsize
, vis_lbsize
;
74 /* Heuristic used to decide whether it is faster to move from CUR to NEW
75 by backing up or outputting a carriage return and moving forward. */
76 #define CR_FASTER(new, cur) (((new) + 1) < ((cur) - (new)))
78 /* **************************************************************** */
82 /* **************************************************************** */
84 /* This is the stuff that is hard for me. I never seem to write good
85 display routines in C. Let's see how I do this time. */
87 /* (PWP) Well... Good for a simple line updater, but totally ignores
88 the problems of input lines longer than the screen width.
90 update_line and the code that calls it makes a multiple line,
91 automatically wrapping line update. Careful attention needs
92 to be paid to the vertical position variables. */
94 /* Keep two buffers; one which reflects the current contents of the
95 screen, and the other to draw what we think the new contents should
96 be. Then compare the buffers, and make whatever changes to the
97 screen itself that we should. Finally, make the buffer that we
98 just drew into be the one which reflects the current contents of the
99 screen, and place the cursor where it belongs.
101 Commands that want to can fix the display themselves, and then let
102 this function know that the display has been fixed by setting the
103 RL_DISPLAY_FIXED variable. This is good for efficiency. */
105 /* Application-specific redisplay function. */
106 rl_voidfunc_t
*rl_redisplay_function
= rl_redisplay
;
108 /* Global variables declared here. */
109 /* What YOU turn on when you have handled all redisplay yourself. */
110 int rl_display_fixed
= 0;
112 int _rl_suppress_redisplay
= 0;
114 /* The stuff that gets printed out before the actual text of the line.
115 This is usually pointing to rl_prompt. */
116 char *rl_display_prompt
= (char *)NULL
;
118 /* Pseudo-global variables declared here. */
119 /* The visible cursor position. If you print some text, adjust this. */
120 int _rl_last_c_pos
= 0;
121 int _rl_last_v_pos
= 0;
123 /* Number of lines currently on screen minus 1. */
124 int _rl_vis_botlin
= 0;
126 /* Variables used only in this file. */
127 /* The last left edge of text that was displayed. This is used when
128 doing horizontal scrolling. It shifts in thirds of a screenwidth. */
129 static int last_lmargin
;
131 /* The line display buffers. One is the line currently displayed on
132 the screen. The other is the line about to be displayed. */
133 static char *visible_line
= (char *)NULL
;
134 static char *invisible_line
= (char *)NULL
;
136 /* A buffer for `modeline' messages. */
137 static char msg_buf
[128];
139 /* Non-zero forces the redisplay even if we thought it was unnecessary. */
140 static int forced_display
;
142 /* Default and initial buffer size. Can grow. */
143 static int line_size
= 1024;
145 /* Variables to keep track of the expanded prompt string, which may
146 include invisible characters. */
148 static char *local_prompt
, *local_prompt_prefix
;
149 static int prompt_visible_length
, prompt_prefix_length
;
151 /* The number of invisible characters in the line currently being
152 displayed on the screen. */
153 static int visible_wrap_offset
;
155 /* The number of invisible characters in the prompt string. Static so it
156 can be shared between rl_redisplay and update_line */
157 static int wrap_offset
;
159 /* The index of the last invisible character in the prompt string. */
160 static int prompt_last_invisible
;
162 /* The length (buffer offset) of the first line of the last (possibly
163 multi-line) buffer displayed on the screen. */
164 static int visible_first_line_len
;
166 /* Number of invisible characters on the first physical line of the prompt.
167 Only valid when the number of physical characters in the prompt exceeds
168 (or is equal to) _rl_screenwidth. */
169 static int prompt_invis_chars_first_line
;
171 static int prompt_last_screen_line
;
173 /* Expand the prompt string S and return the number of visible
174 characters in *LP, if LP is not null. This is currently more-or-less
175 a placeholder for expansion. LIP, if non-null is a place to store the
176 index of the last invisible character in the returned string. NIFLP,
177 if non-zero, is a place to store the number of invisible characters in
178 the first prompt line. */
180 /* Current implementation:
181 \001 (^A) start non-visible characters
182 \002 (^B) end non-visible characters
183 all characters except \001 and \002 (following a \001) are copied to
184 the returned string; all characters except those between \001 and
185 \002 are assumed to be `visible'. */
188 expand_prompt (pmt
, lp
, lip
, niflp
)
190 int *lp
, *lip
, *niflp
;
193 int l
, rl
, last
, ignoring
, ninvis
, invfl
;
195 /* Short-circuit if we can. */
196 if (strchr (pmt
, RL_PROMPT_START_IGNORE
) == 0)
198 r
= savestring (pmt
);
205 r
= ret
= xmalloc (l
+ 1);
207 invfl
= 0; /* invisible chars in first line of prompt */
209 for (rl
= ignoring
= last
= ninvis
= 0, p
= pmt
; p
&& *p
; p
++)
211 /* This code strips the invisible character string markers
212 RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE */
213 if (*p
== RL_PROMPT_START_IGNORE
)
218 else if (ignoring
&& *p
== RL_PROMPT_END_IGNORE
)
231 if (rl
== _rl_screenwidth
)
236 if (rl
< _rl_screenwidth
)
249 /* Just strip out RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE from
250 PMT and return the rest of PMT. */
252 _rl_strip_prompt (pmt
)
257 ret
= expand_prompt (pmt
, (int *)NULL
, (int *)NULL
, (int *)NULL
);
262 * Expand the prompt string into the various display components, if
265 * local_prompt = expanded last line of string in rl_display_prompt
266 * (portion after the final newline)
267 * local_prompt_prefix = portion before last newline of rl_display_prompt,
268 * expanded via expand_prompt
269 * prompt_visible_length = number of visible characters in local_prompt
270 * prompt_prefix_length = number of visible characters in local_prompt_prefix
272 * This function is called once per call to readline(). It may also be
273 * called arbitrarily to expand the primary prompt.
275 * The return value is the number of visible characters on the last line
276 * of the (possibly multi-line) prompt.
279 rl_expand_prompt (prompt
)
285 /* Clear out any saved values. */
287 FREE (local_prompt_prefix
);
289 local_prompt
= local_prompt_prefix
= (char *)0;
290 prompt_last_invisible
= prompt_visible_length
= 0;
292 if (prompt
== 0 || *prompt
== 0)
295 p
= strrchr (prompt
, '\n');
298 /* The prompt is only one logical line, though it might wrap. */
299 local_prompt
= expand_prompt (prompt
, &prompt_visible_length
,
300 &prompt_last_invisible
,
301 &prompt_invis_chars_first_line
);
302 local_prompt_prefix
= (char *)0;
303 return (prompt_visible_length
);
307 /* The prompt spans multiple lines. */
309 local_prompt
= expand_prompt (p
, &prompt_visible_length
,
310 &prompt_last_invisible
,
311 &prompt_invis_chars_first_line
);
313 /* The portion of the prompt string up to and including the
314 final newline is now null-terminated. */
315 local_prompt_prefix
= expand_prompt (prompt
, &prompt_prefix_length
,
317 &prompt_invis_chars_first_line
);
319 return (prompt_prefix_length
);
323 /* Initialize the VISIBLE_LINE and INVISIBLE_LINE arrays, and their associated
324 arrays of line break markers. MINSIZE is the minimum size of VISIBLE_LINE
325 and INVISIBLE_LINE; if it is greater than LINE_SIZE, LINE_SIZE is
326 increased. If the lines have already been allocated, this ensures that
327 they can hold at least MINSIZE characters. */
329 init_line_structures (minsize
)
334 if (invisible_line
== 0) /* initialize it */
336 if (line_size
< minsize
)
338 visible_line
= xmalloc (line_size
);
339 invisible_line
= xmalloc (line_size
);
341 else if (line_size
< minsize
) /* ensure it can hold MINSIZE chars */
344 if (line_size
< minsize
)
346 visible_line
= xrealloc (visible_line
, line_size
);
347 invisible_line
= xrealloc (invisible_line
, line_size
);
350 for (n
= minsize
; n
< line_size
; n
++)
353 invisible_line
[n
] = 1;
356 if (vis_lbreaks
== 0)
358 /* should be enough. */
359 inv_lbsize
= vis_lbsize
= 256;
360 inv_lbreaks
= (int *)xmalloc (inv_lbsize
* sizeof (int));
361 vis_lbreaks
= (int *)xmalloc (vis_lbsize
* sizeof (int));
362 inv_lbreaks
[0] = vis_lbreaks
[0] = 0;
366 /* Basic redisplay algorithm. */
370 register int in
, out
, c
, linenum
, cursor_linenum
;
372 int c_pos
, inv_botlin
, lb_botlin
, lb_linenum
;
373 int newlines
, lpos
, temp
;
374 char *prompt_this_line
;
376 if (!readline_echoing_p
)
379 if (!rl_display_prompt
)
380 rl_display_prompt
= "";
382 if (invisible_line
== 0)
384 init_line_structures (0);
388 /* Draw the line into the buffer. */
391 line
= invisible_line
;
392 out
= inv_botlin
= 0;
394 /* Mark the line as modified or not. We only do this for history
396 if (_rl_mark_modified_lines
&& current_history () && rl_undo_list
)
402 /* If someone thought that the redisplay was handled, but the currently
403 visible line has a different modification state than the one about
404 to become visible, then correct the caller's misconception. */
405 if (visible_line
[0] != invisible_line
[0])
406 rl_display_fixed
= 0;
408 /* If the prompt to be displayed is the `primary' readline prompt (the
409 one passed to readline()), use the values we have already expanded.
410 If not, use what's already in rl_display_prompt. WRAP_OFFSET is the
411 number of non-visible characters in the prompt string. */
412 if (rl_display_prompt
== rl_prompt
|| local_prompt
)
414 int local_len
= local_prompt
? strlen (local_prompt
) : 0;
415 if (local_prompt_prefix
&& forced_display
)
416 _rl_output_some_chars (local_prompt_prefix
, strlen (local_prompt_prefix
));
420 temp
= local_len
+ out
+ 2;
421 if (temp
>= line_size
)
423 line_size
= (temp
+ 1024) - (temp
% 1024);
424 visible_line
= xrealloc (visible_line
, line_size
);
425 line
= invisible_line
= xrealloc (invisible_line
, line_size
);
427 strncpy (line
+ out
, local_prompt
, local_len
);
431 wrap_offset
= local_len
- prompt_visible_length
;
436 prompt_this_line
= strrchr (rl_display_prompt
, '\n');
437 if (!prompt_this_line
)
438 prompt_this_line
= rl_display_prompt
;
442 pmtlen
= prompt_this_line
- rl_display_prompt
; /* temp var */
445 _rl_output_some_chars (rl_display_prompt
, pmtlen
);
446 /* Make sure we are at column zero even after a newline,
447 regardless of the state of terminal output processing. */
448 if (pmtlen
< 2 || prompt_this_line
[-2] != '\r')
453 pmtlen
= strlen (prompt_this_line
);
454 temp
= pmtlen
+ out
+ 2;
455 if (temp
>= line_size
)
457 line_size
= (temp
+ 1024) - (temp
% 1024);
458 visible_line
= xrealloc (visible_line
, line_size
);
459 line
= invisible_line
= xrealloc (invisible_line
, line_size
);
461 strncpy (line
+ out
, prompt_this_line
, pmtlen
);
464 wrap_offset
= prompt_invis_chars_first_line
= 0;
467 #define CHECK_INV_LBREAKS() \
469 if (newlines >= (inv_lbsize - 2)) \
472 inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \
476 #define CHECK_LPOS() \
479 if (lpos >= _rl_screenwidth) \
481 if (newlines >= (inv_lbsize - 2)) \
484 inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \
486 inv_lbreaks[++newlines] = out; \
491 /* inv_lbreaks[i] is where line i starts in the buffer. */
492 inv_lbreaks
[newlines
= 0] = 0;
493 lpos
= out
- wrap_offset
;
495 /* prompt_invis_chars_first_line is the number of invisible characters in
496 the first physical line of the prompt.
497 wrap_offset - prompt_invis_chars_first_line is the number of invis
498 chars on the second line. */
500 /* what if lpos is already >= _rl_screenwidth before we start drawing the
501 contents of the command line? */
502 while (lpos
>= _rl_screenwidth
)
504 /* fix from Darin Johnson <darin@acuson.com> for prompt string with
505 invisible characters that is longer than the screen width. The
506 prompt_invis_chars_first_line variable could be made into an array
507 saying how many invisible characters there are per line, but that's
508 probably too much work for the benefit gained. How many people have
509 prompts that exceed two physical lines? */
510 temp
= ((newlines
+ 1) * _rl_screenwidth
) +
511 ((newlines
== 0) ? prompt_invis_chars_first_line
: 0) +
512 ((newlines
== 1) ? wrap_offset
: 0);
514 inv_lbreaks
[++newlines
] = temp
;
515 lpos
-= _rl_screenwidth
;
518 prompt_last_screen_line
= newlines
;
520 /* Draw the rest of the line (after the prompt) into invisible_line, keeping
521 track of where the cursor is (c_pos), the number of the line containing
522 the cursor (lb_linenum), the last line number (lb_botlin and inv_botlin).
523 It maintains an array of line breaks for display (inv_lbreaks).
524 This handles expanding tabs for display and displaying meta characters. */
526 for (in
= 0; in
< rl_end
; in
++)
528 c
= (unsigned char)rl_line_buffer
[in
];
530 if (out
+ 8 >= line_size
) /* XXX - 8 for \t */
533 visible_line
= xrealloc (visible_line
, line_size
);
534 invisible_line
= xrealloc (invisible_line
, line_size
);
535 line
= invisible_line
;
541 lb_linenum
= newlines
;
546 if (_rl_output_meta_chars
== 0)
548 sprintf (line
+ out
, "\\%o", c
);
550 if (lpos
+ 4 >= _rl_screenwidth
)
552 temp
= _rl_screenwidth
- lpos
;
553 CHECK_INV_LBREAKS ();
554 inv_lbreaks
[++newlines
] = out
+ temp
;
568 #if defined (DISPLAY_TABS)
574 newout
= (out
| (int)7) + 1;
576 newout
= out
+ 8 - lpos
% 8;
579 if (lpos
+ temp
>= _rl_screenwidth
)
582 temp2
= _rl_screenwidth
- lpos
;
583 CHECK_INV_LBREAKS ();
584 inv_lbreaks
[++newlines
] = out
+ temp2
;
597 else if (c
== '\n' && _rl_horizontal_scroll_mode
== 0 && _rl_term_up
&& *_rl_term_up
)
599 line
[out
++] = '\0'; /* XXX - sentinel */
600 CHECK_INV_LBREAKS ();
601 inv_lbreaks
[++newlines
] = out
;
604 else if (CTRL_CHAR (c
) || c
== RUBOUT
)
608 line
[out
++] = CTRL_CHAR (c
) ? UNCTRL (c
) : '?';
621 lb_linenum
= newlines
;
624 inv_botlin
= lb_botlin
= newlines
;
625 CHECK_INV_LBREAKS ();
626 inv_lbreaks
[newlines
+1] = out
;
627 cursor_linenum
= lb_linenum
;
629 /* C_POS == position in buffer where cursor should be placed.
630 CURSOR_LINENUM == line number where the cursor should be placed. */
632 /* PWP: now is when things get a bit hairy. The visible and invisible
633 line buffers are really multiple lines, which would wrap every
634 (screenwidth - 1) characters. Go through each in turn, finding
635 the changed region and updating it. The line order is top to bottom. */
637 /* If we can move the cursor up and down, then use multiple lines,
638 otherwise, let long lines display in a single terminal line, and
639 horizontally scroll it. */
641 if (_rl_horizontal_scroll_mode
== 0 && _rl_term_up
&& *_rl_term_up
)
643 int nleft
, pos
, changed_screen_line
;
645 if (!rl_display_fixed
|| forced_display
)
649 /* If we have more than a screenful of material to display, then
650 only display a screenful. We should display the last screen,
652 if (out
>= _rl_screenchars
)
653 out
= _rl_screenchars
- 1;
655 /* The first line is at character position 0 in the buffer. The
656 second and subsequent lines start at inv_lbreaks[N], offset by
657 OFFSET (which has already been calculated above). */
659 #define W_OFFSET(line, offset) ((line) == 0 ? offset : 0)
660 #define VIS_LLEN(l) ((l) > _rl_vis_botlin ? 0 : (vis_lbreaks[l+1] - vis_lbreaks[l]))
661 #define INV_LLEN(l) (inv_lbreaks[l+1] - inv_lbreaks[l])
662 #define VIS_CHARS(line) (visible_line + vis_lbreaks[line])
663 #define VIS_LINE(line) ((line) > _rl_vis_botlin) ? "" : VIS_CHARS(line)
664 #define INV_LINE(line) (invisible_line + inv_lbreaks[line])
666 /* For each line in the buffer, do the updating display. */
667 for (linenum
= 0; linenum
<= inv_botlin
; linenum
++)
669 update_line (VIS_LINE(linenum
), INV_LINE(linenum
), linenum
,
670 VIS_LLEN(linenum
), INV_LLEN(linenum
), inv_botlin
);
672 /* If this is the line with the prompt, we might need to
673 compensate for invisible characters in the new line. Do
674 this only if there is not more than one new line (which
675 implies that we completely overwrite the old visible line)
676 and the new line is shorter than the old. Make sure we are
677 at the end of the new line before clearing. */
679 inv_botlin
== 0 && _rl_last_c_pos
== out
&&
680 (wrap_offset
> visible_wrap_offset
) &&
681 (_rl_last_c_pos
< visible_first_line_len
))
683 nleft
= _rl_screenwidth
+ wrap_offset
- _rl_last_c_pos
;
685 _rl_clear_to_eol (nleft
);
688 /* Since the new first line is now visible, save its length. */
690 visible_first_line_len
= (inv_botlin
> 0) ? inv_lbreaks
[1] : out
- wrap_offset
;
693 /* We may have deleted some lines. If so, clear the left over
694 blank ones at the bottom out. */
695 if (_rl_vis_botlin
> inv_botlin
)
698 for (; linenum
<= _rl_vis_botlin
; linenum
++)
700 tt
= VIS_CHARS (linenum
);
701 _rl_move_vert (linenum
);
702 _rl_move_cursor_relative (0, tt
);
704 ((linenum
== _rl_vis_botlin
) ? strlen (tt
) : _rl_screenwidth
);
707 _rl_vis_botlin
= inv_botlin
;
709 /* CHANGED_SCREEN_LINE is set to 1 if we have moved to a
710 different screen line during this redisplay. */
711 changed_screen_line
= _rl_last_v_pos
!= cursor_linenum
;
712 if (changed_screen_line
)
714 _rl_move_vert (cursor_linenum
);
715 /* If we moved up to the line with the prompt using _rl_term_up,
716 the physical cursor position on the screen stays the same,
717 but the buffer position needs to be adjusted to account
718 for invisible characters. */
719 if (cursor_linenum
== 0 && wrap_offset
)
720 _rl_last_c_pos
+= wrap_offset
;
723 /* We have to reprint the prompt if it contains invisible
724 characters, since it's not generally OK to just reprint
725 the characters from the current cursor position. But we
726 only need to reprint it if the cursor is before the last
727 invisible character in the prompt string. */
728 nleft
= prompt_visible_length
+ wrap_offset
;
729 if (cursor_linenum
== 0 && wrap_offset
> 0 && _rl_last_c_pos
> 0 &&
730 _rl_last_c_pos
<= prompt_last_invisible
&& local_prompt
)
732 #if defined (__MSDOS__)
733 putc ('\r', rl_outstream
);
736 tputs (_rl_term_cr
, 1, _rl_output_character_function
);
738 _rl_output_some_chars (local_prompt
, nleft
);
739 _rl_last_c_pos
= nleft
;
742 /* Where on that line? And where does that line start
744 pos
= inv_lbreaks
[cursor_linenum
];
745 /* nleft == number of characters in the line buffer between the
746 start of the line and the cursor position. */
749 /* Since _rl_backspace() doesn't know about invisible characters in the
750 prompt, and there's no good way to tell it, we compensate for
751 those characters here and call _rl_backspace() directly. */
752 if (wrap_offset
&& cursor_linenum
== 0 && nleft
< _rl_last_c_pos
)
754 _rl_backspace (_rl_last_c_pos
- nleft
);
755 _rl_last_c_pos
= nleft
;
758 if (nleft
!= _rl_last_c_pos
)
759 _rl_move_cursor_relative (nleft
, &invisible_line
[pos
]);
762 else /* Do horizontal scrolling. */
764 #define M_OFFSET(margin, offset) ((margin) == 0 ? offset : 0)
765 int lmargin
, ndisp
, nleft
, phys_c_pos
, t
;
767 /* Always at top line. */
770 /* Compute where in the buffer the displayed line should start. This
773 /* The number of characters that will be displayed before the cursor. */
774 ndisp
= c_pos
- wrap_offset
;
775 nleft
= prompt_visible_length
+ wrap_offset
;
776 /* Where the new cursor position will be on the screen. This can be
777 longer than SCREENWIDTH; if it is, lmargin will be adjusted. */
778 phys_c_pos
= c_pos
- (last_lmargin
? last_lmargin
: wrap_offset
);
779 t
= _rl_screenwidth
/ 3;
781 /* If the number of characters had already exceeded the screenwidth,
782 last_lmargin will be > 0. */
784 /* If the number of characters to be displayed is more than the screen
785 width, compute the starting offset so that the cursor is about
786 two-thirds of the way across the screen. */
787 if (phys_c_pos
> _rl_screenwidth
- 2)
789 lmargin
= c_pos
- (2 * t
);
792 /* If the left margin would be in the middle of a prompt with
793 invisible characters, don't display the prompt at all. */
794 if (wrap_offset
&& lmargin
> 0 && lmargin
< nleft
)
797 else if (ndisp
< _rl_screenwidth
- 2) /* XXX - was -1 */
799 else if (phys_c_pos
< 1)
801 /* If we are moving back towards the beginning of the line and
802 the last margin is no longer correct, compute a new one. */
803 lmargin
= ((c_pos
- 1) / t
) * t
; /* XXX */
804 if (wrap_offset
&& lmargin
> 0 && lmargin
< nleft
)
808 lmargin
= last_lmargin
;
810 /* If the first character on the screen isn't the first character
811 in the display line, indicate this with a special character. */
815 /* If SCREENWIDTH characters starting at LMARGIN do not encompass
816 the whole line, indicate that with a special character at the
817 right edge of the screen. If LMARGIN is 0, we need to take the
818 wrap offset into account. */
819 t
= lmargin
+ M_OFFSET (lmargin
, wrap_offset
) + _rl_screenwidth
;
823 if (!rl_display_fixed
|| forced_display
|| lmargin
!= last_lmargin
)
826 update_line (&visible_line
[last_lmargin
],
827 &invisible_line
[lmargin
],
829 _rl_screenwidth
+ visible_wrap_offset
,
830 _rl_screenwidth
+ (lmargin
? 0 : wrap_offset
),
833 /* If the visible new line is shorter than the old, but the number
834 of invisible characters is greater, and we are at the end of
835 the new line, we need to clear to eol. */
836 t
= _rl_last_c_pos
- M_OFFSET (lmargin
, wrap_offset
);
837 if ((M_OFFSET (lmargin
, wrap_offset
) > visible_wrap_offset
) &&
838 (_rl_last_c_pos
== out
) &&
839 t
< visible_first_line_len
)
841 nleft
= _rl_screenwidth
- t
;
842 _rl_clear_to_eol (nleft
);
844 visible_first_line_len
= out
- lmargin
- M_OFFSET (lmargin
, wrap_offset
);
845 if (visible_first_line_len
> _rl_screenwidth
)
846 visible_first_line_len
= _rl_screenwidth
;
848 _rl_move_cursor_relative (c_pos
- lmargin
, &invisible_line
[lmargin
]);
849 last_lmargin
= lmargin
;
852 fflush (rl_outstream
);
854 /* Swap visible and non-visible lines. */
856 char *vtemp
= visible_line
;
857 int *itemp
= vis_lbreaks
, ntemp
= vis_lbsize
;
859 visible_line
= invisible_line
;
860 invisible_line
= vtemp
;
862 vis_lbreaks
= inv_lbreaks
;
865 vis_lbsize
= inv_lbsize
;
868 rl_display_fixed
= 0;
869 /* If we are displaying on a single line, and last_lmargin is > 0, we
870 are not displaying any invisible characters, so set visible_wrap_offset
872 if (_rl_horizontal_scroll_mode
&& last_lmargin
)
873 visible_wrap_offset
= 0;
875 visible_wrap_offset
= wrap_offset
;
879 /* PWP: update_line() is based on finding the middle difference of each
880 line on the screen; vis:
882 /old first difference
883 /beginning of line | /old last same /old EOL
885 old: eddie> Oh, my little gruntle-buggy is to me, as lurgid as
886 new: eddie> Oh, my little buggy says to me, as lurgid as
888 \beginning of line | \new last same \new end of line
889 \new first difference
891 All are character pointers for the sake of speed. Special cases for
892 no differences, as well as for end of line additions must be handled.
894 Could be made even smarter, but this works well enough */
896 update_line (old
, new, current_line
, omax
, nmax
, inv_botlin
)
897 register char *old
, *new;
898 int current_line
, omax
, nmax
, inv_botlin
;
900 register char *ofd
, *ols
, *oe
, *nfd
, *nls
, *ne
;
901 int temp
, lendiff
, wsatend
, od
, nd
;
902 int current_invis_chars
;
904 /* If we're at the right edge of a terminal that supports xn, we're
905 ready to wrap around, so do so. This fixes problems with knowing
906 the exact cursor position and cut-and-paste with certain terminal
907 emulators. In this calculation, TEMP is the physical screen
908 position of the cursor. */
909 temp
= _rl_last_c_pos
- W_OFFSET(_rl_last_v_pos
, visible_wrap_offset
);
910 if (temp
== _rl_screenwidth
&& _rl_term_autowrap
&& !_rl_horizontal_scroll_mode
911 && _rl_last_v_pos
== current_line
- 1)
914 putc (new[0], rl_outstream
);
916 putc (' ', rl_outstream
);
917 _rl_last_c_pos
= 1; /* XXX */
919 if (old
[0] && new[0])
923 /* Find first difference. */
924 for (ofd
= old
, nfd
= new;
925 (ofd
- old
< omax
) && *ofd
&& (*ofd
== *nfd
);
929 /* Move to the end of the screen line. ND and OD are used to keep track
930 of the distance between ne and new and oe and old, respectively, to
931 move a subtraction out of each loop. */
932 for (od
= ofd
- old
, oe
= ofd
; od
< omax
&& *oe
; oe
++, od
++);
933 for (nd
= nfd
- new, ne
= nfd
; nd
< nmax
&& *ne
; ne
++, nd
++);
935 /* If no difference, continue to next line. */
936 if (ofd
== oe
&& nfd
== ne
)
939 wsatend
= 1; /* flag for trailing whitespace */
940 ols
= oe
- 1; /* find last same */
942 while ((ols
> ofd
) && (nls
> nfd
) && (*ols
== *nls
))
955 else if (*ols
!= *nls
)
957 if (*ols
) /* don't step past the NUL */
963 /* count of invisible characters in the current invisible line. */
964 current_invis_chars
= W_OFFSET (current_line
, wrap_offset
);
965 if (_rl_last_v_pos
!= current_line
)
967 _rl_move_vert (current_line
);
968 if (current_line
== 0 && visible_wrap_offset
)
969 _rl_last_c_pos
+= visible_wrap_offset
;
972 /* If this is the first line and there are invisible characters in the
973 prompt string, and the prompt string has not changed, and the current
974 cursor position is before the last invisible character in the prompt,
975 and the index of the character to move to is past the end of the prompt
976 string, then redraw the entire prompt string. We can only do this
977 reliably if the terminal supports a `cr' capability.
979 This is not an efficiency hack -- there is a problem with redrawing
980 portions of the prompt string if they contain terminal escape
981 sequences (like drawing the `unbold' sequence without a corresponding
982 `bold') that manifests itself on certain terminals. */
984 lendiff
= local_prompt
? strlen (local_prompt
) : 0;
985 od
= ofd
- old
; /* index of first difference in visible line */
986 if (current_line
== 0 && !_rl_horizontal_scroll_mode
&&
987 _rl_term_cr
&& lendiff
> prompt_visible_length
&& _rl_last_c_pos
> 0 &&
988 od
>= lendiff
&& _rl_last_c_pos
<= prompt_last_invisible
)
990 #if defined (__MSDOS__)
991 putc ('\r', rl_outstream
);
993 tputs (_rl_term_cr
, 1, _rl_output_character_function
);
995 _rl_output_some_chars (local_prompt
, lendiff
);
996 _rl_last_c_pos
= lendiff
;
999 _rl_move_cursor_relative (od
, old
);
1001 /* if (len (new) > len (old)) */
1002 lendiff
= (nls
- nfd
) - (ols
- ofd
);
1004 /* If we are changing the number of invisible characters in a line, and
1005 the spot of first difference is before the end of the invisible chars,
1006 lendiff needs to be adjusted. */
1007 if (current_line
== 0 && !_rl_horizontal_scroll_mode
&&
1008 current_invis_chars
!= visible_wrap_offset
)
1009 lendiff
+= visible_wrap_offset
- current_invis_chars
;
1011 /* Insert (diff (len (old), len (new)) ch. */
1015 /* Non-zero if we're increasing the number of lines. */
1016 int gl
= current_line
>= _rl_vis_botlin
&& inv_botlin
> _rl_vis_botlin
;
1017 /* Sometimes it is cheaper to print the characters rather than
1018 use the terminal's capabilities. If we're growing the number
1019 of lines, make sure we actually cause the new line to wrap
1020 around on auto-wrapping terminals. */
1021 if (_rl_terminal_can_insert
&& ((2 * temp
) >= lendiff
|| _rl_term_IC
) && (!_rl_term_autowrap
|| !gl
))
1023 /* If lendiff > prompt_visible_length and _rl_last_c_pos == 0 and
1024 _rl_horizontal_scroll_mode == 1, inserting the characters with
1025 _rl_term_IC or _rl_term_ic will screw up the screen because of the
1026 invisible characters. We need to just draw them. */
1027 if (*ols
&& (!_rl_horizontal_scroll_mode
|| _rl_last_c_pos
> 0 ||
1028 lendiff
<= prompt_visible_length
|| !current_invis_chars
))
1030 insert_some_chars (nfd
, lendiff
);
1031 _rl_last_c_pos
+= lendiff
;
1035 /* At the end of a line the characters do not have to
1036 be "inserted". They can just be placed on the screen. */
1037 /* However, this screws up the rest of this block, which
1038 assumes you've done the insert because you can. */
1039 _rl_output_some_chars (nfd
, lendiff
);
1040 _rl_last_c_pos
+= lendiff
;
1044 /* We have horizontal scrolling and we are not inserting at
1045 the end. We have invisible characters in this line. This
1046 is a dumb update. */
1047 _rl_output_some_chars (nfd
, temp
);
1048 _rl_last_c_pos
+= temp
;
1051 /* Copy (new) chars to screen from first diff to last match. */
1053 if ((temp
- lendiff
) > 0)
1055 _rl_output_some_chars (nfd
+ lendiff
, temp
- lendiff
);
1056 _rl_last_c_pos
+= temp
- lendiff
;
1061 /* cannot insert chars, write to EOL */
1062 _rl_output_some_chars (nfd
, temp
);
1063 _rl_last_c_pos
+= temp
;
1066 else /* Delete characters from line. */
1068 /* If possible and inexpensive to use terminal deletion, then do so. */
1069 if (_rl_term_dc
&& (2 * temp
) >= -lendiff
)
1071 /* If all we're doing is erasing the invisible characters in the
1072 prompt string, don't bother. It screws up the assumptions
1073 about what's on the screen. */
1074 if (_rl_horizontal_scroll_mode
&& _rl_last_c_pos
== 0 &&
1075 -lendiff
== visible_wrap_offset
)
1079 delete_chars (-lendiff
); /* delete (diff) characters */
1081 /* Copy (new) chars to screen from first diff to last match */
1085 _rl_output_some_chars (nfd
, temp
);
1086 _rl_last_c_pos
+= temp
;
1089 /* Otherwise, print over the existing material. */
1094 _rl_output_some_chars (nfd
, temp
);
1095 _rl_last_c_pos
+= temp
;
1097 lendiff
= (oe
- old
) - (ne
- new);
1100 if (_rl_term_autowrap
&& current_line
< inv_botlin
)
1101 space_to_eol (lendiff
);
1103 _rl_clear_to_eol (lendiff
);
1109 /* Tell the update routines that we have moved onto a new (empty) line. */
1114 visible_line
[0] = '\0';
1116 _rl_last_c_pos
= _rl_last_v_pos
= 0;
1117 _rl_vis_botlin
= last_lmargin
= 0;
1119 vis_lbreaks
[0] = vis_lbreaks
[1] = 0;
1120 visible_wrap_offset
= 0;
1124 /* Tell the update routines that we have moved onto a new line with the
1125 prompt already displayed. Code originally from the version of readline
1126 distributed with CLISP. */
1128 rl_on_new_line_with_prompt ()
1130 int prompt_size
, i
, l
, real_screenwidth
, newlines
;
1131 char *prompt_last_line
;
1133 /* Initialize visible_line and invisible_line to ensure that they can hold
1134 the already-displayed prompt. */
1135 prompt_size
= strlen (rl_prompt
) + 1;
1136 init_line_structures (prompt_size
);
1138 /* Make sure the line structures hold the already-displayed prompt for
1140 strcpy (visible_line
, rl_prompt
);
1141 strcpy (invisible_line
, rl_prompt
);
1143 /* If the prompt contains newlines, take the last tail. */
1144 prompt_last_line
= strrchr (rl_prompt
, '\n');
1145 if (!prompt_last_line
)
1146 prompt_last_line
= rl_prompt
;
1148 l
= strlen (prompt_last_line
);
1151 /* Dissect prompt_last_line into screen lines. Note that here we have
1152 to use the real screenwidth. Readline's notion of screenwidth might be
1153 one less, see terminal.c. */
1154 real_screenwidth
= _rl_screenwidth
+ (_rl_term_autowrap
? 0 : 1);
1155 _rl_last_v_pos
= l
/ real_screenwidth
;
1156 /* If the prompt length is a multiple of real_screenwidth, we don't know
1157 whether the cursor is at the end of the last line, or already at the
1158 beginning of the next line. Output a newline just to be safe. */
1159 if (l
> 0 && (l
% real_screenwidth
) == 0)
1160 _rl_output_some_chars ("\n", 1);
1163 newlines
= 0; i
= 0;
1166 _rl_vis_botlin
= newlines
;
1167 vis_lbreaks
[newlines
++] = i
;
1168 i
+= real_screenwidth
;
1170 vis_lbreaks
[newlines
] = l
;
1171 visible_wrap_offset
= 0;
1176 /* Actually update the display, period. */
1178 rl_forced_update_display ()
1182 register char *temp
= visible_line
;
1189 (*rl_redisplay_function
) ();
1193 /* Move the cursor from _rl_last_c_pos to NEW, which are buffer indices.
1194 DATA is the contents of the screen line of interest; i.e., where
1195 the movement is being done. */
1197 _rl_move_cursor_relative (new, data
)
1203 /* If we don't have to do anything, then return. */
1204 if (_rl_last_c_pos
== new) return;
1206 /* It may be faster to output a CR, and then move forwards instead
1207 of moving backwards. */
1208 /* i == current physical cursor position. */
1209 i
= _rl_last_c_pos
- W_OFFSET(_rl_last_v_pos
, visible_wrap_offset
);
1210 if (new == 0 || CR_FASTER (new, _rl_last_c_pos
) ||
1211 (_rl_term_autowrap
&& i
== _rl_screenwidth
))
1213 #if defined (__MSDOS__)
1214 putc ('\r', rl_outstream
);
1216 tputs (_rl_term_cr
, 1, _rl_output_character_function
);
1217 #endif /* !__MSDOS__ */
1221 if (_rl_last_c_pos
< new)
1223 /* Move the cursor forward. We do it by printing the command
1224 to move the cursor forward if there is one, else print that
1225 portion of the output buffer again. Which is cheaper? */
1227 /* The above comment is left here for posterity. It is faster
1228 to print one character (non-control) than to print a control
1229 sequence telling the terminal to move forward one character.
1230 That kind of control is for people who don't know what the
1231 data is underneath the cursor. */
1232 #if defined (HACK_TERMCAP_MOTION)
1233 if (_rl_term_forward_char
)
1234 for (i
= _rl_last_c_pos
; i
< new; i
++)
1235 tputs (_rl_term_forward_char
, 1, _rl_output_character_function
);
1237 for (i
= _rl_last_c_pos
; i
< new; i
++)
1238 putc (data
[i
], rl_outstream
);
1240 for (i
= _rl_last_c_pos
; i
< new; i
++)
1241 putc (data
[i
], rl_outstream
);
1242 #endif /* HACK_TERMCAP_MOTION */
1244 else if (_rl_last_c_pos
> new)
1245 _rl_backspace (_rl_last_c_pos
- new);
1246 _rl_last_c_pos
= new;
1249 /* PWP: move the cursor up or down. */
1254 register int delta
, i
;
1256 if (_rl_last_v_pos
== to
|| to
> _rl_screenheight
)
1259 if ((delta
= to
- _rl_last_v_pos
) > 0)
1261 for (i
= 0; i
< delta
; i
++)
1262 putc ('\n', rl_outstream
);
1263 #if defined (__MSDOS__)
1264 putc ('\r', rl_outstream
);
1266 tputs (_rl_term_cr
, 1, _rl_output_character_function
);
1272 if (_rl_term_up
&& *_rl_term_up
)
1273 for (i
= 0; i
< -delta
; i
++)
1274 tputs (_rl_term_up
, 1, _rl_output_character_function
);
1277 _rl_last_v_pos
= to
; /* Now TO is here */
1280 /* Physically print C on rl_outstream. This is for functions which know
1281 how to optimize the display. Return the number of characters output. */
1287 if (META_CHAR (c
) && (_rl_output_meta_chars
== 0))
1289 fprintf (rl_outstream
, "M-");
1294 #if defined (DISPLAY_TABS)
1295 if ((CTRL_CHAR (c
) && c
!= '\t') || c
== RUBOUT
)
1297 if (CTRL_CHAR (c
) || c
== RUBOUT
)
1298 #endif /* !DISPLAY_TABS */
1300 fprintf (rl_outstream
, "C-");
1302 c
= CTRL_CHAR (c
) ? UNCTRL (c
) : '?';
1305 putc (c
, rl_outstream
);
1306 fflush (rl_outstream
);
1311 rl_character_len (c
, pos
)
1312 register int c
, pos
;
1316 uc
= (unsigned char)c
;
1319 return ((_rl_output_meta_chars
== 0) ? 4 : 1);
1323 #if defined (DISPLAY_TABS)
1324 return (((pos
| 7) + 1) - pos
);
1327 #endif /* !DISPLAY_TABS */
1330 if (CTRL_CHAR (c
) || c
== RUBOUT
)
1333 return ((isprint (uc
)) ? 1 : 2);
1336 /* How to print things in the "echo-area". The prompt is treated as a
1339 #if defined (USE_VARARGS)
1341 #if defined (PREFER_STDARG)
1342 rl_message (const char *format
, ...)
1344 rl_message (va_alist
)
1349 #if defined (PREFER_VARARGS)
1353 #if defined (PREFER_STDARG)
1354 va_start (args
, format
);
1357 format
= va_arg (args
, char *);
1360 vsprintf (msg_buf
, format
, args
);
1363 rl_display_prompt
= msg_buf
;
1364 (*rl_redisplay_function
) ();
1367 #else /* !USE_VARARGS */
1369 rl_message (format
, arg1
, arg2
)
1372 sprintf (msg_buf
, format
, arg1
, arg2
);
1373 rl_display_prompt
= msg_buf
;
1374 (*rl_redisplay_function
) ();
1377 #endif /* !USE_VARARGS */
1379 /* How to clear things from the "echo-area". */
1383 rl_display_prompt
= rl_prompt
;
1384 (*rl_redisplay_function
) ();
1389 rl_reset_line_state ()
1393 rl_display_prompt
= rl_prompt
? rl_prompt
: "";
1398 static char *saved_local_prompt
;
1399 static char *saved_local_prefix
;
1400 static int saved_last_invisible
;
1401 static int saved_visible_length
;
1406 saved_local_prompt
= local_prompt
;
1407 saved_local_prefix
= local_prompt_prefix
;
1408 saved_last_invisible
= prompt_last_invisible
;
1409 saved_visible_length
= prompt_visible_length
;
1411 local_prompt
= local_prompt_prefix
= (char *)0;
1412 prompt_last_invisible
= prompt_visible_length
= 0;
1416 rl_restore_prompt ()
1418 FREE (local_prompt
);
1419 FREE (local_prompt_prefix
);
1421 local_prompt
= saved_local_prompt
;
1422 local_prompt_prefix
= saved_local_prefix
;
1423 prompt_last_invisible
= saved_last_invisible
;
1424 prompt_visible_length
= saved_visible_length
;
1428 _rl_make_prompt_for_search (pchar
)
1436 if (saved_local_prompt
== 0)
1438 len
= (rl_prompt
&& *rl_prompt
) ? strlen (rl_prompt
) : 0;
1439 pmt
= xmalloc (len
+ 2);
1441 strcpy (pmt
, rl_prompt
);
1447 len
= *saved_local_prompt
? strlen (saved_local_prompt
) : 0;
1448 pmt
= xmalloc (len
+ 2);
1450 strcpy (pmt
, saved_local_prompt
);
1453 local_prompt
= savestring (pmt
);
1454 prompt_last_invisible
= saved_last_invisible
;
1455 prompt_visible_length
= saved_visible_length
+ 1;
1460 /* Quick redisplay hack when erasing characters at the end of the line. */
1462 _rl_erase_at_end_of_line (l
)
1468 for (i
= 0; i
< l
; i
++)
1469 putc (' ', rl_outstream
);
1471 for (i
= 0; i
< l
; i
++)
1472 visible_line
[--_rl_last_c_pos
] = '\0';
1476 /* Clear to the end of the line. COUNT is the minimum
1477 number of character spaces to clear, */
1479 _rl_clear_to_eol (count
)
1482 if (_rl_term_clreol
)
1483 tputs (_rl_term_clreol
, 1, _rl_output_character_function
);
1485 space_to_eol (count
);
1488 /* Clear to the end of the line using spaces. COUNT is the minimum
1489 number of character spaces to clear, */
1491 space_to_eol (count
)
1496 for (i
= 0; i
< count
; i
++)
1497 putc (' ', rl_outstream
);
1499 _rl_last_c_pos
+= count
;
1505 if (_rl_term_clrpag
)
1506 tputs (_rl_term_clrpag
, 1, _rl_output_character_function
);
1511 /* Insert COUNT characters from STRING to the output stream. */
1513 insert_some_chars (string
, count
)
1517 /* If IC is defined, then we do not have to "enter" insert mode. */
1521 buffer
= tgoto (_rl_term_IC
, 0, count
);
1522 tputs (buffer
, 1, _rl_output_character_function
);
1523 _rl_output_some_chars (string
, count
);
1529 /* If we have to turn on insert-mode, then do so. */
1530 if (_rl_term_im
&& *_rl_term_im
)
1531 tputs (_rl_term_im
, 1, _rl_output_character_function
);
1533 /* If there is a special command for inserting characters, then
1534 use that first to open up the space. */
1535 if (_rl_term_ic
&& *_rl_term_ic
)
1537 for (i
= count
; i
--; )
1538 tputs (_rl_term_ic
, 1, _rl_output_character_function
);
1541 /* Print the text. */
1542 _rl_output_some_chars (string
, count
);
1544 /* If there is a string to turn off insert mode, we had best use
1546 if (_rl_term_ei
&& *_rl_term_ei
)
1547 tputs (_rl_term_ei
, 1, _rl_output_character_function
);
1551 /* Delete COUNT characters from the display line. */
1553 delete_chars (count
)
1556 if (count
> _rl_screenwidth
) /* XXX */
1559 if (_rl_term_DC
&& *_rl_term_DC
)
1562 buffer
= tgoto (_rl_term_DC
, count
, count
);
1563 tputs (buffer
, count
, _rl_output_character_function
);
1567 if (_rl_term_dc
&& *_rl_term_dc
)
1569 tputs (_rl_term_dc
, 1, _rl_output_character_function
);
1579 /* If the cursor is the only thing on an otherwise-blank last line,
1580 compensate so we don't print an extra CRLF. */
1581 if (_rl_vis_botlin
&& _rl_last_c_pos
== 0 &&
1582 visible_line
[vis_lbreaks
[_rl_vis_botlin
]] == 0)
1587 _rl_move_vert (_rl_vis_botlin
);
1588 /* If we've wrapped lines, remove the final xterm line-wrap flag. */
1589 if (full_lines
&& _rl_term_autowrap
&& (VIS_LLEN(_rl_vis_botlin
) == _rl_screenwidth
))
1593 last_line
= &visible_line
[inv_lbreaks
[_rl_vis_botlin
]];
1595 last_line
= &visible_line
[vis_lbreaks
[_rl_vis_botlin
]];
1597 _rl_move_cursor_relative (_rl_screenwidth
- 1, last_line
);
1598 _rl_clear_to_eol (0);
1599 putc (last_line
[_rl_screenwidth
- 1], rl_outstream
);
1603 fflush (rl_outstream
);
1607 /* Move to the start of the current line. */
1613 #if defined (__MSDOS__)
1614 putc ('\r', rl_outstream
);
1616 tputs (_rl_term_cr
, 1, _rl_output_character_function
);
1622 /* Redraw the last line of a multi-line prompt that may possibly contain
1623 terminal escape sequences. Called with the cursor at column 0 of the
1624 line to draw the prompt on. */
1629 char *oldp
, *oldl
, *oldlprefix
;
1630 int oldlen
, oldlast
, oldplen
, oldninvis
;
1632 /* Geez, I should make this a struct. */
1633 oldp
= rl_display_prompt
;
1634 oldl
= local_prompt
;
1635 oldlprefix
= local_prompt_prefix
;
1636 oldlen
= prompt_visible_length
;
1637 oldplen
= prompt_prefix_length
;
1638 oldlast
= prompt_last_invisible
;
1639 oldninvis
= prompt_invis_chars_first_line
;
1641 rl_display_prompt
= t
;
1642 local_prompt
= expand_prompt (t
, &prompt_visible_length
,
1643 &prompt_last_invisible
,
1644 &prompt_invis_chars_first_line
);
1645 local_prompt_prefix
= (char *)NULL
;
1646 rl_forced_update_display ();
1648 rl_display_prompt
= oldp
;
1649 local_prompt
= oldl
;
1650 local_prompt_prefix
= oldlprefix
;
1651 prompt_visible_length
= oldlen
;
1652 prompt_prefix_length
= oldplen
;
1653 prompt_last_invisible
= oldlast
;
1654 prompt_invis_chars_first_line
= oldninvis
;
1657 /* Redisplay the current line after a SIGWINCH is received. */
1659 _rl_redisplay_after_sigwinch ()
1663 /* Clear the current line and put the cursor at column 0. Make sure
1664 the right thing happens if we have wrapped to a new screen line. */
1667 #if defined (__MSDOS__)
1668 putc ('\r', rl_outstream
);
1670 tputs (_rl_term_cr
, 1, _rl_output_character_function
);
1673 #if defined (__MSDOS__)
1674 space_to_eol (_rl_screenwidth
);
1675 putc ('\r', rl_outstream
);
1677 if (_rl_term_clreol
)
1678 tputs (_rl_term_clreol
, 1, _rl_output_character_function
);
1681 space_to_eol (_rl_screenwidth
);
1682 tputs (_rl_term_cr
, 1, _rl_output_character_function
);
1685 if (_rl_last_v_pos
> 0)
1691 /* Redraw only the last line of a multi-line prompt. */
1692 t
= strrchr (rl_display_prompt
, '\n');
1694 redraw_prompt (++t
);
1696 rl_forced_update_display ();
1700 _rl_clean_up_for_exit ()
1702 if (readline_echoing_p
)
1704 _rl_move_vert (_rl_vis_botlin
);
1706 fflush (rl_outstream
);
1707 rl_restart_output (1, 0);
1712 _rl_erase_entire_line ()
1715 _rl_clear_to_eol (0);
1717 fflush (rl_outstream
);
1720 /* return the `current display line' of the cursor -- the number of lines to
1721 move up to get to the first screen line of the current readline line. */
1723 _rl_current_display_line ()
1727 /* Find out whether or not there might be invisible characters in the
1729 if (rl_display_prompt
== rl_prompt
)
1730 nleft
= _rl_last_c_pos
- _rl_screenwidth
- rl_visible_prompt_length
;
1732 nleft
= _rl_last_c_pos
- _rl_screenwidth
;
1735 ret
= 1 + nleft
/ _rl_screenwidth
;