Mercurial > hg > octave-lyh
comparison readline/display.c @ 3779:3001e15555e9
[project @ 2001-02-07 04:47:51 by jwe]
author | jwe |
---|---|
date | Wed, 07 Feb 2001 04:48:01 +0000 |
parents | f7e4a95916f2 |
children |
comparison
equal
deleted
inserted
replaced
3778:594ead754542 | 3779:3001e15555e9 |
---|---|
5 This file is part of the GNU Readline Library, a library for | 5 This file is part of the GNU Readline Library, a library for |
6 reading lines of text with interactive input and history editing. | 6 reading lines of text with interactive input and history editing. |
7 | 7 |
8 The GNU Readline Library is free software; you can redistribute it | 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 | 9 and/or modify it under the terms of the GNU General Public License |
10 as published by the Free Software Foundation; either version 1, or | 10 as published by the Free Software Foundation; either version 2, or |
11 (at your option) any later version. | 11 (at your option) any later version. |
12 | 12 |
13 The GNU Readline Library is distributed in the hope that it will be | 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 | 14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
15 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
39 # include "ansi_stdlib.h" | 39 # include "ansi_stdlib.h" |
40 #endif /* HAVE_STDLIB_H */ | 40 #endif /* HAVE_STDLIB_H */ |
41 | 41 |
42 #include <stdio.h> | 42 #include <stdio.h> |
43 | 43 |
44 #if defined (__GO32__) | |
45 # include <go32.h> | |
46 # include <pc.h> | |
47 #endif /* __GO32__ */ | |
48 | |
49 /* System-specific feature definitions and include files. */ | 44 /* System-specific feature definitions and include files. */ |
50 #include "rldefs.h" | 45 #include "rldefs.h" |
51 | 46 |
52 /* Termcap library stuff. */ | 47 /* Termcap library stuff. */ |
53 #include "tcap.h" | 48 #include "tcap.h" |
54 | 49 |
55 /* Some standard library routines. */ | 50 /* Some standard library routines. */ |
56 #include "readline.h" | 51 #include "readline.h" |
57 #include "history.h" | 52 #include "history.h" |
58 | 53 |
54 #include "rlprivate.h" | |
55 #include "xmalloc.h" | |
56 | |
59 #if !defined (strchr) && !defined (__STDC__) | 57 #if !defined (strchr) && !defined (__STDC__) |
60 extern char *strchr (), *strrchr (); | 58 extern char *strchr (), *strrchr (); |
61 #endif /* !strchr && !__STDC__ */ | 59 #endif /* !strchr && !__STDC__ */ |
62 | 60 |
63 /* Global and pseudo-global variables and functions | 61 #if defined (HACK_TERMCAP_MOTION) |
64 imported from readline.c. */ | 62 extern char *_rl_term_forward_char; |
65 extern char *rl_prompt; | 63 #endif |
66 extern int readline_echoing_p; | 64 |
67 | 65 static void update_line __P((char *, char *, int, int, int, int)); |
68 extern int _rl_output_meta_chars; | 66 static void space_to_eol __P((int)); |
69 extern int _rl_horizontal_scroll_mode; | 67 static void delete_chars __P((int)); |
70 extern int _rl_mark_modified_lines; | 68 static void insert_some_chars __P((char *, int)); |
71 extern int _rl_prefer_visible_bell; | 69 static void cr __P((void)); |
72 | |
73 /* Variables and functions imported from terminal.c */ | |
74 extern void _rl_output_some_chars (); | |
75 extern int _rl_output_character_function (); | |
76 extern int _rl_backspace (); | |
77 | |
78 extern char *term_clreol, *term_clrpag; | |
79 extern char *term_im, *term_ic, *term_ei, *term_DC; | |
80 extern char *term_up, *term_dc, *term_cr, *term_IC; | |
81 extern int screenheight, screenwidth, screenchars; | |
82 extern int terminal_can_insert, _rl_term_autowrap; | |
83 | |
84 /* Pseudo-global functions (local to the readline library) exported | |
85 by this file. */ | |
86 void _rl_move_cursor_relative (), _rl_output_some_chars (); | |
87 void _rl_move_vert (); | |
88 void _rl_clear_to_eol (), _rl_clear_screen (); | |
89 | |
90 static void update_line (), space_to_eol (); | |
91 static void delete_chars (), insert_some_chars (); | |
92 static void cr (); | |
93 | 70 |
94 static int *inv_lbreaks, *vis_lbreaks; | 71 static int *inv_lbreaks, *vis_lbreaks; |
95 | 72 static int inv_lbsize, vis_lbsize; |
96 extern char *xmalloc (), *xrealloc (); | |
97 | 73 |
98 /* Heuristic used to decide whether it is faster to move from CUR to NEW | 74 /* Heuristic used to decide whether it is faster to move from CUR to NEW |
99 by backing up or outputting a carriage return and moving forward. */ | 75 by backing up or outputting a carriage return and moving forward. */ |
100 #define CR_FASTER(new, cur) (((new) + 1) < ((cur) - (new))) | 76 #define CR_FASTER(new, cur) (((new) + 1) < ((cur) - (new))) |
101 | 77 |
125 Commands that want to can fix the display themselves, and then let | 101 Commands that want to can fix the display themselves, and then let |
126 this function know that the display has been fixed by setting the | 102 this function know that the display has been fixed by setting the |
127 RL_DISPLAY_FIXED variable. This is good for efficiency. */ | 103 RL_DISPLAY_FIXED variable. This is good for efficiency. */ |
128 | 104 |
129 /* Application-specific redisplay function. */ | 105 /* Application-specific redisplay function. */ |
130 VFunction *rl_redisplay_function = rl_redisplay; | 106 rl_voidfunc_t *rl_redisplay_function = rl_redisplay; |
131 | 107 |
132 /* Global variables declared here. */ | 108 /* Global variables declared here. */ |
133 /* What YOU turn on when you have handled all redisplay yourself. */ | 109 /* What YOU turn on when you have handled all redisplay yourself. */ |
134 int rl_display_fixed = 0; | 110 int rl_display_fixed = 0; |
135 | 111 |
164 static int forced_display; | 140 static int forced_display; |
165 | 141 |
166 /* Default and initial buffer size. Can grow. */ | 142 /* Default and initial buffer size. Can grow. */ |
167 static int line_size = 1024; | 143 static int line_size = 1024; |
168 | 144 |
145 /* Variables to keep track of the expanded prompt string, which may | |
146 include invisible characters. */ | |
147 | |
169 static char *local_prompt, *local_prompt_prefix; | 148 static char *local_prompt, *local_prompt_prefix; |
170 static int visible_length, prefix_length; | 149 static int prompt_visible_length, prompt_prefix_length; |
171 | 150 |
172 /* The number of invisible characters in the line currently being | 151 /* The number of invisible characters in the line currently being |
173 displayed on the screen. */ | 152 displayed on the screen. */ |
174 static int visible_wrap_offset; | 153 static int visible_wrap_offset; |
175 | 154 |
176 /* static so it can be shared between rl_redisplay and update_line */ | 155 /* The number of invisible characters in the prompt string. Static so it |
156 can be shared between rl_redisplay and update_line */ | |
177 static int wrap_offset; | 157 static int wrap_offset; |
178 | 158 |
179 /* The index of the last invisible_character in the prompt string. */ | 159 /* The index of the last invisible character in the prompt string. */ |
180 static int last_invisible; | 160 static int prompt_last_invisible; |
181 | 161 |
182 /* The length (buffer offset) of the first line of the last (possibly | 162 /* The length (buffer offset) of the first line of the last (possibly |
183 multi-line) buffer displayed on the screen. */ | 163 multi-line) buffer displayed on the screen. */ |
184 static int visible_first_line_len; | 164 static int visible_first_line_len; |
185 | 165 |
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; | |
170 | |
171 static int prompt_last_screen_line; | |
172 | |
186 /* Expand the prompt string S and return the number of visible | 173 /* Expand the prompt string S and return the number of visible |
187 characters in *LP, if LP is not null. This is currently more-or-less | 174 characters in *LP, if LP is not null. This is currently more-or-less |
188 a placeholder for expansion. LIP, if non-null is a place to store the | 175 a placeholder for expansion. LIP, if non-null is a place to store the |
189 index of the last invisible character in ther eturned string. */ | 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. */ | |
190 | 179 |
191 /* Current implementation: | 180 /* Current implementation: |
192 \001 (^A) start non-visible characters | 181 \001 (^A) start non-visible characters |
193 \002 (^B) end non-visible characters | 182 \002 (^B) end non-visible characters |
194 all characters except \001 and \002 (following a \001) are copied to | 183 all characters except \001 and \002 (following a \001) are copied to |
195 the returned string; all characters except those between \001 and | 184 the returned string; all characters except those between \001 and |
196 \002 are assumed to be `visible'. */ | 185 \002 are assumed to be `visible'. */ |
197 | 186 |
198 static char * | 187 static char * |
199 expand_prompt (pmt, lp, lip) | 188 expand_prompt (pmt, lp, lip, niflp) |
200 char *pmt; | 189 char *pmt; |
201 int *lp, *lip; | 190 int *lp, *lip, *niflp; |
202 { | 191 { |
203 char *r, *ret, *p; | 192 char *r, *ret, *p; |
204 int l, rl, last, ignoring; | 193 int l, rl, last, ignoring, ninvis, invfl; |
205 | 194 |
206 /* Short-circuit if we can. */ | 195 /* Short-circuit if we can. */ |
207 if (strchr (pmt, RL_PROMPT_START_IGNORE) == 0) | 196 if (strchr (pmt, RL_PROMPT_START_IGNORE) == 0) |
208 { | 197 { |
209 r = savestring (pmt); | 198 r = savestring (pmt); |
212 return r; | 201 return r; |
213 } | 202 } |
214 | 203 |
215 l = strlen (pmt); | 204 l = strlen (pmt); |
216 r = ret = xmalloc (l + 1); | 205 r = ret = xmalloc (l + 1); |
217 | 206 |
218 for (rl = ignoring = last = 0, p = pmt; p && *p; p++) | 207 invfl = 0; /* invisible chars in first line of prompt */ |
208 | |
209 for (rl = ignoring = last = ninvis = 0, p = pmt; p && *p; p++) | |
219 { | 210 { |
220 /* This code strips the invisible character string markers | 211 /* This code strips the invisible character string markers |
221 RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE */ | 212 RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE */ |
222 if (*p == RL_PROMPT_START_IGNORE) | 213 if (*p == RL_PROMPT_START_IGNORE) |
223 { | 214 { |
233 else | 224 else |
234 { | 225 { |
235 *r++ = *p; | 226 *r++ = *p; |
236 if (!ignoring) | 227 if (!ignoring) |
237 rl++; | 228 rl++; |
238 } | 229 else |
239 } | 230 ninvis++; |
231 if (rl == _rl_screenwidth) | |
232 invfl = ninvis; | |
233 } | |
234 } | |
235 | |
236 if (rl < _rl_screenwidth) | |
237 invfl = ninvis; | |
240 | 238 |
241 *r = '\0'; | 239 *r = '\0'; |
242 if (lp) | 240 if (lp) |
243 *lp = rl; | 241 *lp = rl; |
244 if (lip) | 242 if (lip) |
245 *lip = last; | 243 *lip = last; |
244 if (niflp) | |
245 *niflp = invfl; | |
246 return ret; | |
247 } | |
248 | |
249 /* Just strip out RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE from | |
250 PMT and return the rest of PMT. */ | |
251 char * | |
252 _rl_strip_prompt (pmt) | |
253 char *pmt; | |
254 { | |
255 char *ret; | |
256 | |
257 ret = expand_prompt (pmt, (int *)NULL, (int *)NULL, (int *)NULL); | |
246 return ret; | 258 return ret; |
247 } | 259 } |
248 | 260 |
249 /* | 261 /* |
250 * Expand the prompt string into the various display components, if | 262 * Expand the prompt string into the various display components, if |
252 * | 264 * |
253 * local_prompt = expanded last line of string in rl_display_prompt | 265 * local_prompt = expanded last line of string in rl_display_prompt |
254 * (portion after the final newline) | 266 * (portion after the final newline) |
255 * local_prompt_prefix = portion before last newline of rl_display_prompt, | 267 * local_prompt_prefix = portion before last newline of rl_display_prompt, |
256 * expanded via expand_prompt | 268 * expanded via expand_prompt |
257 * visible_length = number of visible characters in local_prompt | 269 * prompt_visible_length = number of visible characters in local_prompt |
258 * prefix_length = number of visible characters in local_prompt_prefix | 270 * prompt_prefix_length = number of visible characters in local_prompt_prefix |
259 * | 271 * |
260 * This function is called once per call to readline(). It may also be | 272 * This function is called once per call to readline(). It may also be |
261 * called arbitrarily to expand the primary prompt. | 273 * called arbitrarily to expand the primary prompt. |
262 * | 274 * |
263 * The return value is the number of visible characters on the last line | 275 * The return value is the number of visible characters on the last line |
269 { | 281 { |
270 char *p, *t; | 282 char *p, *t; |
271 int c; | 283 int c; |
272 | 284 |
273 /* Clear out any saved values. */ | 285 /* Clear out any saved values. */ |
274 if (local_prompt) | 286 FREE (local_prompt); |
275 free (local_prompt); | 287 FREE (local_prompt_prefix); |
276 if (local_prompt_prefix) | 288 |
277 free (local_prompt_prefix); | |
278 local_prompt = local_prompt_prefix = (char *)0; | 289 local_prompt = local_prompt_prefix = (char *)0; |
279 last_invisible = 0; | 290 prompt_last_invisible = prompt_visible_length = 0; |
280 | 291 |
281 if (prompt == 0 || *prompt == 0) | 292 if (prompt == 0 || *prompt == 0) |
282 return (0); | 293 return (0); |
283 | 294 |
284 p = strrchr (prompt, '\n'); | 295 p = strrchr (prompt, '\n'); |
285 if (!p) | 296 if (!p) |
286 { | 297 { |
287 /* The prompt is only one line. */ | 298 /* The prompt is only one logical line, though it might wrap. */ |
288 local_prompt = expand_prompt (prompt, &visible_length, &last_invisible); | 299 local_prompt = expand_prompt (prompt, &prompt_visible_length, |
300 &prompt_last_invisible, | |
301 &prompt_invis_chars_first_line); | |
289 local_prompt_prefix = (char *)0; | 302 local_prompt_prefix = (char *)0; |
290 return (visible_length); | 303 return (prompt_visible_length); |
291 } | 304 } |
292 else | 305 else |
293 { | 306 { |
294 /* The prompt spans multiple lines. */ | 307 /* The prompt spans multiple lines. */ |
295 t = ++p; | 308 t = ++p; |
296 local_prompt = expand_prompt (p, &visible_length, &last_invisible); | 309 local_prompt = expand_prompt (p, &prompt_visible_length, |
310 &prompt_last_invisible, | |
311 &prompt_invis_chars_first_line); | |
297 c = *t; *t = '\0'; | 312 c = *t; *t = '\0'; |
298 /* The portion of the prompt string up to and including the | 313 /* The portion of the prompt string up to and including the |
299 final newline is now null-terminated. */ | 314 final newline is now null-terminated. */ |
300 local_prompt_prefix = expand_prompt (prompt, &prefix_length, (int *)NULL); | 315 local_prompt_prefix = expand_prompt (prompt, &prompt_prefix_length, |
316 (int *)NULL, | |
317 &prompt_invis_chars_first_line); | |
301 *t = c; | 318 *t = c; |
302 return (prefix_length); | 319 return (prompt_prefix_length); |
303 } | 320 } |
304 } | 321 } |
305 | 322 |
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. */ | |
328 static void | |
329 init_line_structures (minsize) | |
330 int minsize; | |
331 { | |
332 register int n; | |
333 | |
334 if (invisible_line == 0) /* initialize it */ | |
335 { | |
336 if (line_size < minsize) | |
337 line_size = minsize; | |
338 visible_line = xmalloc (line_size); | |
339 invisible_line = xmalloc (line_size); | |
340 } | |
341 else if (line_size < minsize) /* ensure it can hold MINSIZE chars */ | |
342 { | |
343 line_size *= 2; | |
344 if (line_size < minsize) | |
345 line_size = minsize; | |
346 visible_line = xrealloc (visible_line, line_size); | |
347 invisible_line = xrealloc (invisible_line, line_size); | |
348 } | |
349 | |
350 for (n = minsize; n < line_size; n++) | |
351 { | |
352 visible_line[n] = 0; | |
353 invisible_line[n] = 1; | |
354 } | |
355 | |
356 if (vis_lbreaks == 0) | |
357 { | |
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; | |
363 } | |
364 } | |
365 | |
306 /* Basic redisplay algorithm. */ | 366 /* Basic redisplay algorithm. */ |
307 void | 367 void |
308 rl_redisplay () | 368 rl_redisplay () |
309 { | 369 { |
310 register int in, out, c, linenum, cursor_linenum; | 370 register int in, out, c, linenum, cursor_linenum; |
319 if (!rl_display_prompt) | 379 if (!rl_display_prompt) |
320 rl_display_prompt = ""; | 380 rl_display_prompt = ""; |
321 | 381 |
322 if (invisible_line == 0) | 382 if (invisible_line == 0) |
323 { | 383 { |
324 visible_line = xmalloc (line_size); | 384 init_line_structures (0); |
325 invisible_line = xmalloc (line_size); | |
326 for (in = 0; in < line_size; in++) | |
327 { | |
328 visible_line[in] = 0; | |
329 invisible_line[in] = 1; | |
330 } | |
331 | |
332 /* should be enough, but then again, this is just for testing. */ | |
333 inv_lbreaks = (int *)malloc (256 * sizeof (int)); | |
334 vis_lbreaks = (int *)malloc (256 * sizeof (int)); | |
335 inv_lbreaks[0] = vis_lbreaks[0] = 0; | |
336 | |
337 rl_on_new_line (); | 385 rl_on_new_line (); |
338 } | 386 } |
339 | 387 |
340 /* Draw the line into the buffer. */ | 388 /* Draw the line into the buffer. */ |
341 c_pos = -1; | 389 c_pos = -1; |
367 if (local_prompt_prefix && forced_display) | 415 if (local_prompt_prefix && forced_display) |
368 _rl_output_some_chars (local_prompt_prefix, strlen (local_prompt_prefix)); | 416 _rl_output_some_chars (local_prompt_prefix, strlen (local_prompt_prefix)); |
369 | 417 |
370 if (local_len > 0) | 418 if (local_len > 0) |
371 { | 419 { |
420 temp = local_len + out + 2; | |
421 if (temp >= line_size) | |
422 { | |
423 line_size = (temp + 1024) - (temp % 1024); | |
424 visible_line = xrealloc (visible_line, line_size); | |
425 line = invisible_line = xrealloc (invisible_line, line_size); | |
426 } | |
372 strncpy (line + out, local_prompt, local_len); | 427 strncpy (line + out, local_prompt, local_len); |
373 out += local_len; | 428 out += local_len; |
374 } | 429 } |
375 line[out] = '\0'; | 430 line[out] = '\0'; |
376 wrap_offset = local_len - visible_length; | 431 wrap_offset = local_len - prompt_visible_length; |
377 } | 432 } |
378 else | 433 else |
379 { | 434 { |
380 int pmtlen; | 435 int pmtlen; |
381 prompt_this_line = strrchr (rl_display_prompt, '\n'); | 436 prompt_this_line = strrchr (rl_display_prompt, '\n'); |
382 if (!prompt_this_line) | 437 if (!prompt_this_line) |
383 prompt_this_line = rl_display_prompt; | 438 prompt_this_line = rl_display_prompt; |
384 else | 439 else |
385 { | 440 { |
386 prompt_this_line++; | 441 prompt_this_line++; |
442 pmtlen = prompt_this_line - rl_display_prompt; /* temp var */ | |
387 if (forced_display) | 443 if (forced_display) |
388 { | 444 { |
389 _rl_output_some_chars (rl_display_prompt, prompt_this_line - rl_display_prompt); | 445 _rl_output_some_chars (rl_display_prompt, pmtlen); |
390 /* Make sure we are at column zero even after a newline, | 446 /* Make sure we are at column zero even after a newline, |
391 regardless of the state of terminal output processing. */ | 447 regardless of the state of terminal output processing. */ |
392 if (prompt_this_line[-2] != '\r') | 448 if (pmtlen < 2 || prompt_this_line[-2] != '\r') |
393 cr (); | 449 cr (); |
394 } | 450 } |
395 } | 451 } |
396 | 452 |
397 pmtlen = strlen (prompt_this_line); | 453 pmtlen = strlen (prompt_this_line); |
454 temp = pmtlen + out + 2; | |
455 if (temp >= line_size) | |
456 { | |
457 line_size = (temp + 1024) - (temp % 1024); | |
458 visible_line = xrealloc (visible_line, line_size); | |
459 line = invisible_line = xrealloc (invisible_line, line_size); | |
460 } | |
398 strncpy (line + out, prompt_this_line, pmtlen); | 461 strncpy (line + out, prompt_this_line, pmtlen); |
399 out += pmtlen; | 462 out += pmtlen; |
400 line[out] = '\0'; | 463 line[out] = '\0'; |
401 wrap_offset = 0; | 464 wrap_offset = prompt_invis_chars_first_line = 0; |
402 } | 465 } |
403 | 466 |
467 #define CHECK_INV_LBREAKS() \ | |
468 do { \ | |
469 if (newlines >= (inv_lbsize - 2)) \ | |
470 { \ | |
471 inv_lbsize *= 2; \ | |
472 inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \ | |
473 } \ | |
474 } while (0) | |
475 | |
404 #define CHECK_LPOS() \ | 476 #define CHECK_LPOS() \ |
405 do { \ | 477 do { \ |
406 lpos++; \ | 478 lpos++; \ |
407 if (lpos >= screenwidth) \ | 479 if (lpos >= _rl_screenwidth) \ |
408 { \ | 480 { \ |
409 inv_lbreaks[++newlines] = out; \ | 481 if (newlines >= (inv_lbsize - 2)) \ |
410 lpos = 0; \ | 482 { \ |
411 } \ | 483 inv_lbsize *= 2; \ |
484 inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \ | |
485 } \ | |
486 inv_lbreaks[++newlines] = out; \ | |
487 lpos = 0; \ | |
488 } \ | |
412 } while (0) | 489 } while (0) |
413 | 490 |
414 /* inv_lbreaks[i] is where line i starts in the buffer. */ | 491 /* inv_lbreaks[i] is where line i starts in the buffer. */ |
415 inv_lbreaks[newlines = 0] = 0; | 492 inv_lbreaks[newlines = 0] = 0; |
416 lpos = out - wrap_offset; | 493 lpos = out - wrap_offset; |
417 | 494 |
418 /* XXX - what if lpos is already >= screenwidth before we start drawing the | 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. */ | |
499 | |
500 /* what if lpos is already >= _rl_screenwidth before we start drawing the | |
419 contents of the command line? */ | 501 contents of the command line? */ |
420 while (lpos >= screenwidth) | 502 while (lpos >= _rl_screenwidth) |
421 { | 503 { |
422 temp = ((newlines + 1) * screenwidth) - ((newlines == 0) ? wrap_offset : 0); | 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); | |
513 | |
423 inv_lbreaks[++newlines] = temp; | 514 inv_lbreaks[++newlines] = temp; |
424 lpos -= screenwidth; | 515 lpos -= _rl_screenwidth; |
425 } | 516 } |
426 | 517 |
518 prompt_last_screen_line = newlines; | |
519 | |
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. */ | |
427 lb_linenum = 0; | 525 lb_linenum = 0; |
428 for (in = 0; in < rl_end; in++) | 526 for (in = 0; in < rl_end; in++) |
429 { | 527 { |
430 c = (unsigned char)rl_line_buffer[in]; | 528 c = (unsigned char)rl_line_buffer[in]; |
431 | 529 |
447 { | 545 { |
448 if (_rl_output_meta_chars == 0) | 546 if (_rl_output_meta_chars == 0) |
449 { | 547 { |
450 sprintf (line + out, "\\%o", c); | 548 sprintf (line + out, "\\%o", c); |
451 | 549 |
452 if (lpos + 4 >= screenwidth) | 550 if (lpos + 4 >= _rl_screenwidth) |
453 { | 551 { |
454 temp = screenwidth - lpos; | 552 temp = _rl_screenwidth - lpos; |
553 CHECK_INV_LBREAKS (); | |
455 inv_lbreaks[++newlines] = out + temp; | 554 inv_lbreaks[++newlines] = out + temp; |
456 lpos = 4 - temp; | 555 lpos = 4 - temp; |
457 } | 556 } |
458 else | 557 else |
459 lpos += 4; | 558 lpos += 4; |
467 } | 566 } |
468 } | 567 } |
469 #if defined (DISPLAY_TABS) | 568 #if defined (DISPLAY_TABS) |
470 else if (c == '\t') | 569 else if (c == '\t') |
471 { | 570 { |
472 register int temp, newout; | 571 register int newout; |
572 | |
573 #if 0 | |
473 newout = (out | (int)7) + 1; | 574 newout = (out | (int)7) + 1; |
575 #else | |
576 newout = out + 8 - lpos % 8; | |
577 #endif | |
474 temp = newout - out; | 578 temp = newout - out; |
475 if (lpos + temp >= screenwidth) | 579 if (lpos + temp >= _rl_screenwidth) |
476 { | 580 { |
477 register int temp2; | 581 register int temp2; |
478 temp2 = screenwidth - lpos; | 582 temp2 = _rl_screenwidth - lpos; |
583 CHECK_INV_LBREAKS (); | |
479 inv_lbreaks[++newlines] = out + temp2; | 584 inv_lbreaks[++newlines] = out + temp2; |
480 lpos = temp - temp2; | 585 lpos = temp - temp2; |
481 while (out < newout) | 586 while (out < newout) |
482 line[out++] = ' '; | 587 line[out++] = ' '; |
483 } | 588 } |
487 line[out++] = ' '; | 592 line[out++] = ' '; |
488 lpos += temp; | 593 lpos += temp; |
489 } | 594 } |
490 } | 595 } |
491 #endif | 596 #endif |
492 else if (c == '\n' && _rl_horizontal_scroll_mode == 0 && term_up && *term_up) | 597 else if (c == '\n' && _rl_horizontal_scroll_mode == 0 && _rl_term_up && *_rl_term_up) |
493 { | 598 { |
494 line[out++] = '\0'; /* XXX - sentinel */ | 599 line[out++] = '\0'; /* XXX - sentinel */ |
495 inv_lbreaks[++newlines] = out; | 600 CHECK_INV_LBREAKS (); |
496 lpos = 0; | 601 inv_lbreaks[++newlines] = out; |
497 } | 602 lpos = 0; |
603 } | |
498 else if (CTRL_CHAR (c) || c == RUBOUT) | 604 else if (CTRL_CHAR (c) || c == RUBOUT) |
499 { | 605 { |
500 line[out++] = '^'; | 606 line[out++] = '^'; |
501 CHECK_LPOS(); | 607 CHECK_LPOS(); |
502 line[out++] = CTRL_CHAR (c) ? UNCTRL (c) : '?'; | 608 line[out++] = CTRL_CHAR (c) ? UNCTRL (c) : '?'; |
514 c_pos = out; | 620 c_pos = out; |
515 lb_linenum = newlines; | 621 lb_linenum = newlines; |
516 } | 622 } |
517 | 623 |
518 inv_botlin = lb_botlin = newlines; | 624 inv_botlin = lb_botlin = newlines; |
625 CHECK_INV_LBREAKS (); | |
519 inv_lbreaks[newlines+1] = out; | 626 inv_lbreaks[newlines+1] = out; |
520 cursor_linenum = lb_linenum; | 627 cursor_linenum = lb_linenum; |
521 | 628 |
522 /* C_POS == position in buffer where cursor should be placed. */ | 629 /* C_POS == position in buffer where cursor should be placed. |
630 CURSOR_LINENUM == line number where the cursor should be placed. */ | |
523 | 631 |
524 /* PWP: now is when things get a bit hairy. The visible and invisible | 632 /* PWP: now is when things get a bit hairy. The visible and invisible |
525 line buffers are really multiple lines, which would wrap every | 633 line buffers are really multiple lines, which would wrap every |
526 (screenwidth - 1) characters. Go through each in turn, finding | 634 (screenwidth - 1) characters. Go through each in turn, finding |
527 the changed region and updating it. The line order is top to bottom. */ | 635 the changed region and updating it. The line order is top to bottom. */ |
528 | 636 |
529 /* If we can move the cursor up and down, then use multiple lines, | 637 /* If we can move the cursor up and down, then use multiple lines, |
530 otherwise, let long lines display in a single terminal line, and | 638 otherwise, let long lines display in a single terminal line, and |
531 horizontally scroll it. */ | 639 horizontally scroll it. */ |
532 | 640 |
533 if (_rl_horizontal_scroll_mode == 0 && term_up && *term_up) | 641 if (_rl_horizontal_scroll_mode == 0 && _rl_term_up && *_rl_term_up) |
534 { | 642 { |
535 int nleft, pos, changed_screen_line; | 643 int nleft, pos, changed_screen_line; |
536 | 644 |
537 if (!rl_display_fixed || forced_display) | 645 if (!rl_display_fixed || forced_display) |
538 { | 646 { |
539 forced_display = 0; | 647 forced_display = 0; |
540 | 648 |
541 /* If we have more than a screenful of material to display, then | 649 /* If we have more than a screenful of material to display, then |
542 only display a screenful. We should display the last screen, | 650 only display a screenful. We should display the last screen, |
543 not the first. */ | 651 not the first. */ |
544 if (out >= screenchars) | 652 if (out >= _rl_screenchars) |
545 out = screenchars - 1; | 653 out = _rl_screenchars - 1; |
546 | 654 |
547 /* The first line is at character position 0 in the buffer. The | 655 /* The first line is at character position 0 in the buffer. The |
548 second and subsequent lines start at inv_lbreaks[N], offset by | 656 second and subsequent lines start at inv_lbreaks[N], offset by |
549 OFFSET (which has already been calculated above). */ | 657 OFFSET (which has already been calculated above). */ |
550 | 658 |
570 if (linenum == 0 && | 678 if (linenum == 0 && |
571 inv_botlin == 0 && _rl_last_c_pos == out && | 679 inv_botlin == 0 && _rl_last_c_pos == out && |
572 (wrap_offset > visible_wrap_offset) && | 680 (wrap_offset > visible_wrap_offset) && |
573 (_rl_last_c_pos < visible_first_line_len)) | 681 (_rl_last_c_pos < visible_first_line_len)) |
574 { | 682 { |
575 nleft = screenwidth + wrap_offset - _rl_last_c_pos; | 683 nleft = _rl_screenwidth + wrap_offset - _rl_last_c_pos; |
576 if (nleft) | 684 if (nleft) |
577 _rl_clear_to_eol (nleft); | 685 _rl_clear_to_eol (nleft); |
578 } | 686 } |
579 | 687 |
580 /* Since the new first line is now visible, save its length. */ | 688 /* Since the new first line is now visible, save its length. */ |
591 { | 699 { |
592 tt = VIS_CHARS (linenum); | 700 tt = VIS_CHARS (linenum); |
593 _rl_move_vert (linenum); | 701 _rl_move_vert (linenum); |
594 _rl_move_cursor_relative (0, tt); | 702 _rl_move_cursor_relative (0, tt); |
595 _rl_clear_to_eol | 703 _rl_clear_to_eol |
596 ((linenum == _rl_vis_botlin) ? strlen (tt) : screenwidth); | 704 ((linenum == _rl_vis_botlin) ? strlen (tt) : _rl_screenwidth); |
597 } | 705 } |
598 } | 706 } |
599 _rl_vis_botlin = inv_botlin; | 707 _rl_vis_botlin = inv_botlin; |
600 | 708 |
601 /* CHANGED_SCREEN_LINE is set to 1 if we have moved to a | 709 /* CHANGED_SCREEN_LINE is set to 1 if we have moved to a |
602 different screen line during this redisplay. */ | 710 different screen line during this redisplay. */ |
603 changed_screen_line = _rl_last_v_pos != cursor_linenum; | 711 changed_screen_line = _rl_last_v_pos != cursor_linenum; |
604 if (changed_screen_line) | 712 if (changed_screen_line) |
605 { | 713 { |
606 _rl_move_vert (cursor_linenum); | 714 _rl_move_vert (cursor_linenum); |
607 /* If we moved up to the line with the prompt using term_up, | 715 /* If we moved up to the line with the prompt using _rl_term_up, |
608 the physical cursor position on the screen stays the same, | 716 the physical cursor position on the screen stays the same, |
609 but the buffer position needs to be adjusted to account | 717 but the buffer position needs to be adjusted to account |
610 for invisible characters. */ | 718 for invisible characters. */ |
611 if (cursor_linenum == 0 && wrap_offset) | 719 if (cursor_linenum == 0 && wrap_offset) |
612 _rl_last_c_pos += wrap_offset; | 720 _rl_last_c_pos += wrap_offset; |
613 } | 721 } |
614 | 722 |
615 /* We have to reprint the prompt if it contains invisible | 723 /* We have to reprint the prompt if it contains invisible |
616 characters, since it's not generally OK to just reprint | 724 characters, since it's not generally OK to just reprint |
617 the characters from the current cursor position. But we | 725 the characters from the current cursor position. But we |
618 only need to reprint it if the cursor is before the last | 726 only need to reprint it if the cursor is before the last |
619 invisible character in the prompt string. */ | 727 invisible character in the prompt string. */ |
620 nleft = visible_length + wrap_offset; | 728 nleft = prompt_visible_length + wrap_offset; |
621 if (cursor_linenum == 0 && wrap_offset > 0 && _rl_last_c_pos > 0 && | 729 if (cursor_linenum == 0 && wrap_offset > 0 && _rl_last_c_pos > 0 && |
622 _rl_last_c_pos <= last_invisible && local_prompt) | 730 _rl_last_c_pos <= prompt_last_invisible && local_prompt) |
623 { | 731 { |
624 if (term_cr) | 732 #if defined (__MSDOS__) |
625 tputs (term_cr, 1, _rl_output_character_function); | 733 putc ('\r', rl_outstream); |
734 #else | |
735 if (_rl_term_cr) | |
736 tputs (_rl_term_cr, 1, _rl_output_character_function); | |
737 #endif | |
626 _rl_output_some_chars (local_prompt, nleft); | 738 _rl_output_some_chars (local_prompt, nleft); |
627 _rl_last_c_pos = nleft; | 739 _rl_last_c_pos = nleft; |
628 } | 740 } |
629 | 741 |
630 /* Where on that line? And where does that line start | 742 /* Where on that line? And where does that line start |
658 /* Compute where in the buffer the displayed line should start. This | 770 /* Compute where in the buffer the displayed line should start. This |
659 will be LMARGIN. */ | 771 will be LMARGIN. */ |
660 | 772 |
661 /* The number of characters that will be displayed before the cursor. */ | 773 /* The number of characters that will be displayed before the cursor. */ |
662 ndisp = c_pos - wrap_offset; | 774 ndisp = c_pos - wrap_offset; |
663 nleft = visible_length + wrap_offset; | 775 nleft = prompt_visible_length + wrap_offset; |
664 /* Where the new cursor position will be on the screen. This can be | 776 /* Where the new cursor position will be on the screen. This can be |
665 longer than SCREENWIDTH; if it is, lmargin will be adjusted. */ | 777 longer than SCREENWIDTH; if it is, lmargin will be adjusted. */ |
666 phys_c_pos = c_pos - (last_lmargin ? last_lmargin : wrap_offset); | 778 phys_c_pos = c_pos - (last_lmargin ? last_lmargin : wrap_offset); |
667 t = screenwidth / 3; | 779 t = _rl_screenwidth / 3; |
668 | 780 |
669 /* If the number of characters had already exceeded the screenwidth, | 781 /* If the number of characters had already exceeded the screenwidth, |
670 last_lmargin will be > 0. */ | 782 last_lmargin will be > 0. */ |
671 | 783 |
672 /* If the number of characters to be displayed is more than the screen | 784 /* If the number of characters to be displayed is more than the screen |
673 width, compute the starting offset so that the cursor is about | 785 width, compute the starting offset so that the cursor is about |
674 two-thirds of the way across the screen. */ | 786 two-thirds of the way across the screen. */ |
675 if (phys_c_pos > screenwidth - 2) | 787 if (phys_c_pos > _rl_screenwidth - 2) |
676 { | 788 { |
677 lmargin = c_pos - (2 * t); | 789 lmargin = c_pos - (2 * t); |
678 if (lmargin < 0) | 790 if (lmargin < 0) |
679 lmargin = 0; | 791 lmargin = 0; |
680 /* If the left margin would be in the middle of a prompt with | 792 /* If the left margin would be in the middle of a prompt with |
681 invisible characters, don't display the prompt at all. */ | 793 invisible characters, don't display the prompt at all. */ |
682 if (wrap_offset && lmargin > 0 && lmargin < nleft) | 794 if (wrap_offset && lmargin > 0 && lmargin < nleft) |
683 lmargin = nleft; | 795 lmargin = nleft; |
684 } | 796 } |
685 else if (ndisp < screenwidth - 2) /* XXX - was -1 */ | 797 else if (ndisp < _rl_screenwidth - 2) /* XXX - was -1 */ |
686 lmargin = 0; | 798 lmargin = 0; |
687 else if (phys_c_pos < 1) | 799 else if (phys_c_pos < 1) |
688 { | 800 { |
689 /* If we are moving back towards the beginning of the line and | 801 /* If we are moving back towards the beginning of the line and |
690 the last margin is no longer correct, compute a new one. */ | 802 the last margin is no longer correct, compute a new one. */ |
691 lmargin = ((c_pos - 1) / t) * t; /* XXX */ | 803 lmargin = ((c_pos - 1) / t) * t; /* XXX */ |
692 if (wrap_offset && lmargin > 0 && lmargin < nleft) | 804 if (wrap_offset && lmargin > 0 && lmargin < nleft) |
693 lmargin = nleft; | 805 lmargin = nleft; |
694 } | 806 } |
695 else | 807 else |
696 lmargin = last_lmargin; | 808 lmargin = last_lmargin; |
697 | 809 |
698 /* If the first character on the screen isn't the first character | 810 /* If the first character on the screen isn't the first character |
699 in the display line, indicate this with a special character. */ | 811 in the display line, indicate this with a special character. */ |
700 if (lmargin > 0) | 812 if (lmargin > 0) |
701 line[lmargin] = '<'; | 813 line[lmargin] = '<'; |
702 | 814 |
703 /* If SCREENWIDTH characters starting at LMARGIN do not encompass | 815 /* If SCREENWIDTH characters starting at LMARGIN do not encompass |
704 the whole line, indicate that with a special characters at the | 816 the whole line, indicate that with a special character at the |
705 right edge of the screen. If LMARGIN is 0, we need to take the | 817 right edge of the screen. If LMARGIN is 0, we need to take the |
706 wrap offset into account. */ | 818 wrap offset into account. */ |
707 t = lmargin + M_OFFSET (lmargin, wrap_offset) + screenwidth; | 819 t = lmargin + M_OFFSET (lmargin, wrap_offset) + _rl_screenwidth; |
708 if (t < out) | 820 if (t < out) |
709 line[t - 1] = '>'; | 821 line[t - 1] = '>'; |
710 | 822 |
711 if (!rl_display_fixed || forced_display || lmargin != last_lmargin) | 823 if (!rl_display_fixed || forced_display || lmargin != last_lmargin) |
712 { | 824 { |
713 forced_display = 0; | 825 forced_display = 0; |
714 update_line (&visible_line[last_lmargin], | 826 update_line (&visible_line[last_lmargin], |
715 &invisible_line[lmargin], | 827 &invisible_line[lmargin], |
716 0, | 828 0, |
717 screenwidth + visible_wrap_offset, | 829 _rl_screenwidth + visible_wrap_offset, |
718 screenwidth + (lmargin ? 0 : wrap_offset), | 830 _rl_screenwidth + (lmargin ? 0 : wrap_offset), |
719 0); | 831 0); |
720 | 832 |
721 /* If the visible new line is shorter than the old, but the number | 833 /* If the visible new line is shorter than the old, but the number |
722 of invisible characters is greater, and we are at the end of | 834 of invisible characters is greater, and we are at the end of |
723 the new line, we need to clear to eol. */ | 835 the new line, we need to clear to eol. */ |
724 t = _rl_last_c_pos - M_OFFSET (lmargin, wrap_offset); | 836 t = _rl_last_c_pos - M_OFFSET (lmargin, wrap_offset); |
725 if ((M_OFFSET (lmargin, wrap_offset) > visible_wrap_offset) && | 837 if ((M_OFFSET (lmargin, wrap_offset) > visible_wrap_offset) && |
726 (_rl_last_c_pos == out) && | 838 (_rl_last_c_pos == out) && |
727 t < visible_first_line_len) | 839 t < visible_first_line_len) |
728 { | 840 { |
729 nleft = screenwidth - t; | 841 nleft = _rl_screenwidth - t; |
730 _rl_clear_to_eol (nleft); | 842 _rl_clear_to_eol (nleft); |
731 } | 843 } |
732 visible_first_line_len = out - lmargin - M_OFFSET (lmargin, wrap_offset); | 844 visible_first_line_len = out - lmargin - M_OFFSET (lmargin, wrap_offset); |
733 if (visible_first_line_len > screenwidth) | 845 if (visible_first_line_len > _rl_screenwidth) |
734 visible_first_line_len = screenwidth; | 846 visible_first_line_len = _rl_screenwidth; |
735 | 847 |
736 _rl_move_cursor_relative (c_pos - lmargin, &invisible_line[lmargin]); | 848 _rl_move_cursor_relative (c_pos - lmargin, &invisible_line[lmargin]); |
737 last_lmargin = lmargin; | 849 last_lmargin = lmargin; |
738 } | 850 } |
739 } | 851 } |
740 fflush (rl_outstream); | 852 fflush (rl_outstream); |
741 | 853 |
742 /* Swap visible and non-visible lines. */ | 854 /* Swap visible and non-visible lines. */ |
743 { | 855 { |
744 char *temp = visible_line; | 856 char *vtemp = visible_line; |
745 int *itemp = vis_lbreaks; | 857 int *itemp = vis_lbreaks, ntemp = vis_lbsize; |
858 | |
746 visible_line = invisible_line; | 859 visible_line = invisible_line; |
747 invisible_line = temp; | 860 invisible_line = vtemp; |
861 | |
748 vis_lbreaks = inv_lbreaks; | 862 vis_lbreaks = inv_lbreaks; |
749 inv_lbreaks = itemp; | 863 inv_lbreaks = itemp; |
864 | |
865 vis_lbsize = inv_lbsize; | |
866 inv_lbsize = ntemp; | |
867 | |
750 rl_display_fixed = 0; | 868 rl_display_fixed = 0; |
751 /* If we are displaying on a single line, and last_lmargin is > 0, we | 869 /* If we are displaying on a single line, and last_lmargin is > 0, we |
752 are not displaying any invisible characters, so set visible_wrap_offset | 870 are not displaying any invisible characters, so set visible_wrap_offset |
753 to 0. */ | 871 to 0. */ |
754 if (_rl_horizontal_scroll_mode && last_lmargin) | 872 if (_rl_horizontal_scroll_mode && last_lmargin) |
769 ^ ^ ^ ^ | 887 ^ ^ ^ ^ |
770 \beginning of line | \new last same \new end of line | 888 \beginning of line | \new last same \new end of line |
771 \new first difference | 889 \new first difference |
772 | 890 |
773 All are character pointers for the sake of speed. Special cases for | 891 All are character pointers for the sake of speed. Special cases for |
774 no differences, as well as for end of line additions must be handeled. | 892 no differences, as well as for end of line additions must be handled. |
775 | 893 |
776 Could be made even smarter, but this works well enough */ | 894 Could be made even smarter, but this works well enough */ |
777 static void | 895 static void |
778 update_line (old, new, current_line, omax, nmax, inv_botlin) | 896 update_line (old, new, current_line, omax, nmax, inv_botlin) |
779 register char *old, *new; | 897 register char *old, *new; |
787 ready to wrap around, so do so. This fixes problems with knowing | 905 ready to wrap around, so do so. This fixes problems with knowing |
788 the exact cursor position and cut-and-paste with certain terminal | 906 the exact cursor position and cut-and-paste with certain terminal |
789 emulators. In this calculation, TEMP is the physical screen | 907 emulators. In this calculation, TEMP is the physical screen |
790 position of the cursor. */ | 908 position of the cursor. */ |
791 temp = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset); | 909 temp = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset); |
792 if (temp == screenwidth && _rl_term_autowrap && !_rl_horizontal_scroll_mode | 910 if (temp == _rl_screenwidth && _rl_term_autowrap && !_rl_horizontal_scroll_mode |
793 && _rl_last_v_pos == current_line - 1) | 911 && _rl_last_v_pos == current_line - 1) |
794 { | 912 { |
795 if (new[0]) | 913 if (new[0]) |
796 putc (new[0], rl_outstream); | 914 putc (new[0], rl_outstream); |
797 else | 915 else |
798 putc (' ', rl_outstream); | 916 putc (' ', rl_outstream); |
799 _rl_last_c_pos = 1; /* XXX */ | 917 _rl_last_c_pos = 1; /* XXX */ |
800 _rl_last_v_pos++; | 918 _rl_last_v_pos++; |
801 if (old[0] && new[0]) | 919 if (old[0] && new[0]) |
802 old[0] = new[0]; | 920 old[0] = new[0]; |
803 } | 921 } |
804 | 922 |
805 /* Find first difference. */ | 923 /* Find first difference. */ |
806 for (ofd = old, nfd = new; | 924 for (ofd = old, nfd = new; |
807 (ofd - old < omax) && *ofd && (*ofd == *nfd); | 925 (ofd - old < omax) && *ofd && (*ofd == *nfd); |
864 `bold') that manifests itself on certain terminals. */ | 982 `bold') that manifests itself on certain terminals. */ |
865 | 983 |
866 lendiff = local_prompt ? strlen (local_prompt) : 0; | 984 lendiff = local_prompt ? strlen (local_prompt) : 0; |
867 od = ofd - old; /* index of first difference in visible line */ | 985 od = ofd - old; /* index of first difference in visible line */ |
868 if (current_line == 0 && !_rl_horizontal_scroll_mode && | 986 if (current_line == 0 && !_rl_horizontal_scroll_mode && |
869 term_cr && lendiff > visible_length && _rl_last_c_pos > 0 && | 987 _rl_term_cr && lendiff > prompt_visible_length && _rl_last_c_pos > 0 && |
870 od > lendiff && _rl_last_c_pos < last_invisible) | 988 od >= lendiff && _rl_last_c_pos <= prompt_last_invisible) |
871 { | 989 { |
872 tputs (term_cr, 1, _rl_output_character_function); | 990 #if defined (__MSDOS__) |
991 putc ('\r', rl_outstream); | |
992 #else | |
993 tputs (_rl_term_cr, 1, _rl_output_character_function); | |
994 #endif | |
873 _rl_output_some_chars (local_prompt, lendiff); | 995 _rl_output_some_chars (local_prompt, lendiff); |
874 _rl_last_c_pos = lendiff; | 996 _rl_last_c_pos = lendiff; |
875 } | 997 } |
876 | 998 |
877 _rl_move_cursor_relative (od, old); | 999 _rl_move_cursor_relative (od, old); |
882 /* If we are changing the number of invisible characters in a line, and | 1004 /* If we are changing the number of invisible characters in a line, and |
883 the spot of first difference is before the end of the invisible chars, | 1005 the spot of first difference is before the end of the invisible chars, |
884 lendiff needs to be adjusted. */ | 1006 lendiff needs to be adjusted. */ |
885 if (current_line == 0 && !_rl_horizontal_scroll_mode && | 1007 if (current_line == 0 && !_rl_horizontal_scroll_mode && |
886 current_invis_chars != visible_wrap_offset) | 1008 current_invis_chars != visible_wrap_offset) |
887 { | 1009 lendiff += visible_wrap_offset - current_invis_chars; |
888 temp = visible_wrap_offset - current_invis_chars; | |
889 lendiff += temp; | |
890 } | |
891 | 1010 |
892 /* Insert (diff (len (old), len (new)) ch. */ | 1011 /* Insert (diff (len (old), len (new)) ch. */ |
893 temp = ne - nfd; | 1012 temp = ne - nfd; |
894 if (lendiff > 0) | 1013 if (lendiff > 0) |
895 { | 1014 { |
897 int gl = current_line >= _rl_vis_botlin && inv_botlin > _rl_vis_botlin; | 1016 int gl = current_line >= _rl_vis_botlin && inv_botlin > _rl_vis_botlin; |
898 /* Sometimes it is cheaper to print the characters rather than | 1017 /* Sometimes it is cheaper to print the characters rather than |
899 use the terminal's capabilities. If we're growing the number | 1018 use the terminal's capabilities. If we're growing the number |
900 of lines, make sure we actually cause the new line to wrap | 1019 of lines, make sure we actually cause the new line to wrap |
901 around on auto-wrapping terminals. */ | 1020 around on auto-wrapping terminals. */ |
902 if (terminal_can_insert && ((2 * temp) >= lendiff || term_IC) && (!_rl_term_autowrap || !gl)) | 1021 if (_rl_terminal_can_insert && ((2 * temp) >= lendiff || _rl_term_IC) && (!_rl_term_autowrap || !gl)) |
903 { | 1022 { |
904 /* If lendiff > visible_length and _rl_last_c_pos == 0 and | 1023 /* If lendiff > prompt_visible_length and _rl_last_c_pos == 0 and |
905 _rl_horizontal_scroll_mode == 1, inserting the characters with | 1024 _rl_horizontal_scroll_mode == 1, inserting the characters with |
906 term_IC or term_ic will screw up the screen because of the | 1025 _rl_term_IC or _rl_term_ic will screw up the screen because of the |
907 invisible characters. We need to just draw them. */ | 1026 invisible characters. We need to just draw them. */ |
908 if (*ols && (!_rl_horizontal_scroll_mode || _rl_last_c_pos > 0 || | 1027 if (*ols && (!_rl_horizontal_scroll_mode || _rl_last_c_pos > 0 || |
909 lendiff <= visible_length || !current_invis_chars)) | 1028 lendiff <= prompt_visible_length || !current_invis_chars)) |
910 { | 1029 { |
911 insert_some_chars (nfd, lendiff); | 1030 insert_some_chars (nfd, lendiff); |
912 _rl_last_c_pos += lendiff; | 1031 _rl_last_c_pos += lendiff; |
913 } | 1032 } |
914 else if (*ols == 0) | 1033 else if (*ols == 0) |
915 { | 1034 { |
916 /* At the end of a line the characters do not have to | 1035 /* At the end of a line the characters do not have to |
917 be "inserted". They can just be placed on the screen. */ | 1036 be "inserted". They can just be placed on the screen. */ |
918 /* However, this screws up the rest of this block, which | 1037 /* However, this screws up the rest of this block, which |
919 assumes you've done the insert because you can. */ | 1038 assumes you've done the insert because you can. */ |
920 _rl_output_some_chars (nfd, lendiff); | 1039 _rl_output_some_chars (nfd, lendiff); |
921 _rl_last_c_pos += lendiff; | 1040 _rl_last_c_pos += lendiff; |
922 } | 1041 } |
923 else | 1042 else |
924 { | 1043 { |
945 } | 1064 } |
946 } | 1065 } |
947 else /* Delete characters from line. */ | 1066 else /* Delete characters from line. */ |
948 { | 1067 { |
949 /* If possible and inexpensive to use terminal deletion, then do so. */ | 1068 /* If possible and inexpensive to use terminal deletion, then do so. */ |
950 if (term_dc && (2 * temp) >= -lendiff) | 1069 if (_rl_term_dc && (2 * temp) >= -lendiff) |
951 { | 1070 { |
952 /* If all we're doing is erasing the invisible characters in the | 1071 /* If all we're doing is erasing the invisible characters in the |
953 prompt string, don't bother. It screws up the assumptions | 1072 prompt string, don't bother. It screws up the assumptions |
954 about what's on the screen. */ | 1073 about what's on the screen. */ |
955 if (_rl_horizontal_scroll_mode && _rl_last_c_pos == 0 && | 1074 if (_rl_horizontal_scroll_mode && _rl_last_c_pos == 0 && |
974 { | 1093 { |
975 _rl_output_some_chars (nfd, temp); | 1094 _rl_output_some_chars (nfd, temp); |
976 _rl_last_c_pos += temp; | 1095 _rl_last_c_pos += temp; |
977 } | 1096 } |
978 lendiff = (oe - old) - (ne - new); | 1097 lendiff = (oe - old) - (ne - new); |
979 if (_rl_term_autowrap && current_line < inv_botlin) | 1098 if (lendiff) |
980 space_to_eol (lendiff); | 1099 { |
981 else | 1100 if (_rl_term_autowrap && current_line < inv_botlin) |
982 _rl_clear_to_eol (lendiff); | 1101 space_to_eol (lendiff); |
1102 else | |
1103 _rl_clear_to_eol (lendiff); | |
1104 } | |
983 } | 1105 } |
984 } | 1106 } |
985 } | 1107 } |
986 | 1108 |
987 /* Tell the update routines that we have moved onto a new (empty) line. */ | 1109 /* Tell the update routines that we have moved onto a new (empty) line. */ |
997 vis_lbreaks[0] = vis_lbreaks[1] = 0; | 1119 vis_lbreaks[0] = vis_lbreaks[1] = 0; |
998 visible_wrap_offset = 0; | 1120 visible_wrap_offset = 0; |
999 return 0; | 1121 return 0; |
1000 } | 1122 } |
1001 | 1123 |
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. */ | |
1127 int | |
1128 rl_on_new_line_with_prompt () | |
1129 { | |
1130 int prompt_size, i, l, real_screenwidth, newlines; | |
1131 char *prompt_last_line; | |
1132 | |
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); | |
1137 | |
1138 /* Make sure the line structures hold the already-displayed prompt for | |
1139 redisplay. */ | |
1140 strcpy (visible_line, rl_prompt); | |
1141 strcpy (invisible_line, rl_prompt); | |
1142 | |
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; | |
1147 | |
1148 l = strlen (prompt_last_line); | |
1149 _rl_last_c_pos = l; | |
1150 | |
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); | |
1161 last_lmargin = 0; | |
1162 | |
1163 newlines = 0; i = 0; | |
1164 while (i <= l) | |
1165 { | |
1166 _rl_vis_botlin = newlines; | |
1167 vis_lbreaks[newlines++] = i; | |
1168 i += real_screenwidth; | |
1169 } | |
1170 vis_lbreaks[newlines] = l; | |
1171 visible_wrap_offset = 0; | |
1172 | |
1173 return 0; | |
1174 } | |
1175 | |
1002 /* Actually update the display, period. */ | 1176 /* Actually update the display, period. */ |
1003 int | 1177 int |
1004 rl_forced_update_display () | 1178 rl_forced_update_display () |
1005 { | 1179 { |
1006 if (visible_line) | 1180 if (visible_line) |
1007 { | 1181 { |
1008 register char *temp = visible_line; | 1182 register char *temp = visible_line; |
1009 | 1183 |
1010 while (*temp) | 1184 while (*temp) |
1011 *temp++ = '\0'; | 1185 *temp++ = '\0'; |
1012 } | 1186 } |
1013 rl_on_new_line (); | 1187 rl_on_new_line (); |
1014 forced_display++; | 1188 forced_display++; |
1015 (*rl_redisplay_function) (); | 1189 (*rl_redisplay_function) (); |
1016 return 0; | 1190 return 0; |
1020 DATA is the contents of the screen line of interest; i.e., where | 1194 DATA is the contents of the screen line of interest; i.e., where |
1021 the movement is being done. */ | 1195 the movement is being done. */ |
1022 void | 1196 void |
1023 _rl_move_cursor_relative (new, data) | 1197 _rl_move_cursor_relative (new, data) |
1024 int new; | 1198 int new; |
1025 char *data; | 1199 const char *data; |
1026 { | 1200 { |
1027 register int i; | 1201 register int i; |
1028 | 1202 |
1029 /* If we don't have to do anything, then return. */ | 1203 /* If we don't have to do anything, then return. */ |
1030 if (_rl_last_c_pos == new) return; | 1204 if (_rl_last_c_pos == new) return; |
1032 /* It may be faster to output a CR, and then move forwards instead | 1206 /* It may be faster to output a CR, and then move forwards instead |
1033 of moving backwards. */ | 1207 of moving backwards. */ |
1034 /* i == current physical cursor position. */ | 1208 /* i == current physical cursor position. */ |
1035 i = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset); | 1209 i = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset); |
1036 if (new == 0 || CR_FASTER (new, _rl_last_c_pos) || | 1210 if (new == 0 || CR_FASTER (new, _rl_last_c_pos) || |
1037 (_rl_term_autowrap && i == screenwidth)) | 1211 (_rl_term_autowrap && i == _rl_screenwidth)) |
1038 { | 1212 { |
1039 #if defined (__MSDOS__) | 1213 #if defined (__MSDOS__) |
1040 putc ('\r', rl_outstream); | 1214 putc ('\r', rl_outstream); |
1041 #else | 1215 #else |
1042 tputs (term_cr, 1, _rl_output_character_function); | 1216 tputs (_rl_term_cr, 1, _rl_output_character_function); |
1043 #endif /* !__MSDOS__ */ | 1217 #endif /* !__MSDOS__ */ |
1044 _rl_last_c_pos = 0; | 1218 _rl_last_c_pos = 0; |
1045 } | 1219 } |
1046 | 1220 |
1047 if (_rl_last_c_pos < new) | 1221 if (_rl_last_c_pos < new) |
1054 to print one character (non-control) than to print a control | 1228 to print one character (non-control) than to print a control |
1055 sequence telling the terminal to move forward one character. | 1229 sequence telling the terminal to move forward one character. |
1056 That kind of control is for people who don't know what the | 1230 That kind of control is for people who don't know what the |
1057 data is underneath the cursor. */ | 1231 data is underneath the cursor. */ |
1058 #if defined (HACK_TERMCAP_MOTION) | 1232 #if defined (HACK_TERMCAP_MOTION) |
1059 extern char *term_forward_char; | 1233 if (_rl_term_forward_char) |
1060 | |
1061 if (term_forward_char) | |
1062 for (i = _rl_last_c_pos; i < new; i++) | 1234 for (i = _rl_last_c_pos; i < new; i++) |
1063 tputs (term_forward_char, 1, _rl_output_character_function); | 1235 tputs (_rl_term_forward_char, 1, _rl_output_character_function); |
1064 else | 1236 else |
1065 for (i = _rl_last_c_pos; i < new; i++) | 1237 for (i = _rl_last_c_pos; i < new; i++) |
1066 putc (data[i], rl_outstream); | 1238 putc (data[i], rl_outstream); |
1067 #else | 1239 #else |
1068 for (i = _rl_last_c_pos; i < new; i++) | 1240 for (i = _rl_last_c_pos; i < new; i++) |
1069 putc (data[i], rl_outstream); | 1241 putc (data[i], rl_outstream); |
1070 #endif /* HACK_TERMCAP_MOTION */ | 1242 #endif /* HACK_TERMCAP_MOTION */ |
1071 } | 1243 } |
1072 else if (_rl_last_c_pos != new) | 1244 else if (_rl_last_c_pos > new) |
1073 _rl_backspace (_rl_last_c_pos - new); | 1245 _rl_backspace (_rl_last_c_pos - new); |
1074 _rl_last_c_pos = new; | 1246 _rl_last_c_pos = new; |
1075 } | 1247 } |
1076 | 1248 |
1077 /* PWP: move the cursor up or down. */ | 1249 /* PWP: move the cursor up or down. */ |
1079 _rl_move_vert (to) | 1251 _rl_move_vert (to) |
1080 int to; | 1252 int to; |
1081 { | 1253 { |
1082 register int delta, i; | 1254 register int delta, i; |
1083 | 1255 |
1084 if (_rl_last_v_pos == to || to > screenheight) | 1256 if (_rl_last_v_pos == to || to > _rl_screenheight) |
1085 return; | 1257 return; |
1086 | |
1087 #if defined (__GO32__) | |
1088 { | |
1089 int row, col; | |
1090 | |
1091 ScreenGetCursor (&row, &col); | |
1092 ScreenSetCursor ((row + to - _rl_last_v_pos), col); | |
1093 } | |
1094 #else /* !__GO32__ */ | |
1095 | 1258 |
1096 if ((delta = to - _rl_last_v_pos) > 0) | 1259 if ((delta = to - _rl_last_v_pos) > 0) |
1097 { | 1260 { |
1098 for (i = 0; i < delta; i++) | 1261 for (i = 0; i < delta; i++) |
1099 putc ('\n', rl_outstream); | 1262 putc ('\n', rl_outstream); |
1100 tputs (term_cr, 1, _rl_output_character_function); | 1263 #if defined (__MSDOS__) |
1264 putc ('\r', rl_outstream); | |
1265 #else | |
1266 tputs (_rl_term_cr, 1, _rl_output_character_function); | |
1267 #endif | |
1101 _rl_last_c_pos = 0; | 1268 _rl_last_c_pos = 0; |
1102 } | 1269 } |
1103 else | 1270 else |
1104 { /* delta < 0 */ | 1271 { /* delta < 0 */ |
1105 if (term_up && *term_up) | 1272 if (_rl_term_up && *_rl_term_up) |
1106 for (i = 0; i < -delta; i++) | 1273 for (i = 0; i < -delta; i++) |
1107 tputs (term_up, 1, _rl_output_character_function); | 1274 tputs (_rl_term_up, 1, _rl_output_character_function); |
1108 } | 1275 } |
1109 #endif /* !__GO32__ */ | 1276 |
1110 _rl_last_v_pos = to; /* Now TO is here */ | 1277 _rl_last_v_pos = to; /* Now TO is here */ |
1111 } | 1278 } |
1112 | 1279 |
1113 /* Physically print C on rl_outstream. This is for functions which know | 1280 /* Physically print C on rl_outstream. This is for functions which know |
1114 how to optimize the display. Return the number of characters output. */ | 1281 how to optimize the display. Return the number of characters output. */ |
1232 static char *saved_local_prefix; | 1399 static char *saved_local_prefix; |
1233 static int saved_last_invisible; | 1400 static int saved_last_invisible; |
1234 static int saved_visible_length; | 1401 static int saved_visible_length; |
1235 | 1402 |
1236 void | 1403 void |
1237 _rl_save_prompt () | 1404 rl_save_prompt () |
1238 { | 1405 { |
1239 saved_local_prompt = local_prompt; | 1406 saved_local_prompt = local_prompt; |
1240 saved_local_prefix = local_prompt_prefix; | 1407 saved_local_prefix = local_prompt_prefix; |
1241 saved_last_invisible = last_invisible; | 1408 saved_last_invisible = prompt_last_invisible; |
1242 saved_visible_length = visible_length; | 1409 saved_visible_length = prompt_visible_length; |
1243 | 1410 |
1244 local_prompt = local_prompt_prefix = (char *)0; | 1411 local_prompt = local_prompt_prefix = (char *)0; |
1245 last_invisible = visible_length = 0; | 1412 prompt_last_invisible = prompt_visible_length = 0; |
1246 } | 1413 } |
1247 | 1414 |
1248 void | 1415 void |
1249 _rl_restore_prompt () | 1416 rl_restore_prompt () |
1250 { | 1417 { |
1251 if (local_prompt) | 1418 FREE (local_prompt); |
1252 free (local_prompt); | 1419 FREE (local_prompt_prefix); |
1253 if (local_prompt_prefix) | |
1254 free (local_prompt_prefix); | |
1255 | 1420 |
1256 local_prompt = saved_local_prompt; | 1421 local_prompt = saved_local_prompt; |
1257 local_prompt_prefix = saved_local_prefix; | 1422 local_prompt_prefix = saved_local_prefix; |
1258 last_invisible = saved_last_invisible; | 1423 prompt_last_invisible = saved_last_invisible; |
1259 visible_length = saved_visible_length; | 1424 prompt_visible_length = saved_visible_length; |
1260 } | 1425 } |
1261 | 1426 |
1262 char * | 1427 char * |
1263 _rl_make_prompt_for_search (pchar) | 1428 _rl_make_prompt_for_search (pchar) |
1264 int pchar; | 1429 int pchar; |
1265 { | 1430 { |
1266 int len; | 1431 int len; |
1267 char *pmt; | 1432 char *pmt; |
1268 | 1433 |
1269 _rl_save_prompt (); | 1434 rl_save_prompt (); |
1270 | 1435 |
1271 if (saved_local_prompt == 0) | 1436 if (saved_local_prompt == 0) |
1272 { | 1437 { |
1273 len = (rl_prompt && *rl_prompt) ? strlen (rl_prompt) : 0; | 1438 len = (rl_prompt && *rl_prompt) ? strlen (rl_prompt) : 0; |
1274 pmt = xmalloc (len + 2); | 1439 pmt = xmalloc (len + 2); |
1275 if (len) | 1440 if (len) |
1276 strcpy (pmt, rl_prompt); | 1441 strcpy (pmt, rl_prompt); |
1277 pmt[len] = pchar; | 1442 pmt[len] = pchar; |
1278 pmt[len+1] = '\0'; | 1443 pmt[len+1] = '\0'; |
1279 } | 1444 } |
1280 else | 1445 else |
1281 { | 1446 { |
1282 len = *saved_local_prompt ? strlen (saved_local_prompt) : 0; | 1447 len = *saved_local_prompt ? strlen (saved_local_prompt) : 0; |
1283 pmt = xmalloc (len + 2); | 1448 pmt = xmalloc (len + 2); |
1284 if (len) | 1449 if (len) |
1285 strcpy (pmt, saved_local_prompt); | 1450 strcpy (pmt, saved_local_prompt); |
1286 pmt[len] = pchar; | 1451 pmt[len] = pchar; |
1287 pmt[len+1] = '\0'; | 1452 pmt[len+1] = '\0'; |
1288 local_prompt = savestring (pmt); | 1453 local_prompt = savestring (pmt); |
1289 last_invisible = saved_last_invisible; | 1454 prompt_last_invisible = saved_last_invisible; |
1290 visible_length = saved_visible_length + 1; | 1455 prompt_visible_length = saved_visible_length + 1; |
1291 } | 1456 } |
1292 return pmt; | 1457 return pmt; |
1293 } | 1458 } |
1294 | 1459 |
1295 /* Quick redisplay hack when erasing characters at the end of the line. */ | 1460 /* Quick redisplay hack when erasing characters at the end of the line. */ |
1312 number of character spaces to clear, */ | 1477 number of character spaces to clear, */ |
1313 void | 1478 void |
1314 _rl_clear_to_eol (count) | 1479 _rl_clear_to_eol (count) |
1315 int count; | 1480 int count; |
1316 { | 1481 { |
1317 #if !defined (__GO32__) | 1482 if (_rl_term_clreol) |
1318 if (term_clreol) | 1483 tputs (_rl_term_clreol, 1, _rl_output_character_function); |
1319 tputs (term_clreol, 1, _rl_output_character_function); | |
1320 else if (count) | 1484 else if (count) |
1321 #endif /* !__GO32__ */ | |
1322 space_to_eol (count); | 1485 space_to_eol (count); |
1323 } | 1486 } |
1324 | 1487 |
1325 /* Clear to the end of the line using spaces. COUNT is the minimum | 1488 /* Clear to the end of the line using spaces. COUNT is the minimum |
1326 number of character spaces to clear, */ | 1489 number of character spaces to clear, */ |
1337 } | 1500 } |
1338 | 1501 |
1339 void | 1502 void |
1340 _rl_clear_screen () | 1503 _rl_clear_screen () |
1341 { | 1504 { |
1342 #if !defined (__GO32__) | 1505 if (_rl_term_clrpag) |
1343 if (term_clrpag) | 1506 tputs (_rl_term_clrpag, 1, _rl_output_character_function); |
1344 tputs (term_clrpag, 1, _rl_output_character_function); | |
1345 else | 1507 else |
1346 #endif /* !__GO32__ */ | 1508 rl_crlf (); |
1347 crlf (); | |
1348 } | 1509 } |
1349 | 1510 |
1350 /* Insert COUNT characters from STRING to the output stream. */ | 1511 /* Insert COUNT characters from STRING to the output stream. */ |
1351 static void | 1512 static void |
1352 insert_some_chars (string, count) | 1513 insert_some_chars (string, count) |
1353 char *string; | 1514 char *string; |
1354 int count; | 1515 int count; |
1355 { | 1516 { |
1356 #if defined (__GO32__) | |
1357 int row, col, width; | |
1358 char *row_start; | |
1359 | |
1360 ScreenGetCursor (&row, &col); | |
1361 width = ScreenCols (); | |
1362 row_start = ScreenPrimary + (row * width); | |
1363 | |
1364 memcpy (row_start + col + count, row_start + col, width - col - count); | |
1365 | |
1366 /* Place the text on the screen. */ | |
1367 _rl_output_some_chars (string, count); | |
1368 #else /* !_GO32 */ | |
1369 | |
1370 /* If IC is defined, then we do not have to "enter" insert mode. */ | 1517 /* If IC is defined, then we do not have to "enter" insert mode. */ |
1371 if (term_IC) | 1518 if (_rl_term_IC) |
1372 { | 1519 { |
1373 char *buffer; | 1520 char *buffer; |
1374 buffer = tgoto (term_IC, 0, count); | 1521 buffer = tgoto (_rl_term_IC, 0, count); |
1375 tputs (buffer, 1, _rl_output_character_function); | 1522 tputs (buffer, 1, _rl_output_character_function); |
1376 _rl_output_some_chars (string, count); | 1523 _rl_output_some_chars (string, count); |
1377 } | 1524 } |
1378 else | 1525 else |
1379 { | 1526 { |
1380 register int i; | 1527 register int i; |
1381 | 1528 |
1382 /* If we have to turn on insert-mode, then do so. */ | 1529 /* If we have to turn on insert-mode, then do so. */ |
1383 if (term_im && *term_im) | 1530 if (_rl_term_im && *_rl_term_im) |
1384 tputs (term_im, 1, _rl_output_character_function); | 1531 tputs (_rl_term_im, 1, _rl_output_character_function); |
1385 | 1532 |
1386 /* If there is a special command for inserting characters, then | 1533 /* If there is a special command for inserting characters, then |
1387 use that first to open up the space. */ | 1534 use that first to open up the space. */ |
1388 if (term_ic && *term_ic) | 1535 if (_rl_term_ic && *_rl_term_ic) |
1389 { | 1536 { |
1390 for (i = count; i--; ) | 1537 for (i = count; i--; ) |
1391 tputs (term_ic, 1, _rl_output_character_function); | 1538 tputs (_rl_term_ic, 1, _rl_output_character_function); |
1392 } | 1539 } |
1393 | 1540 |
1394 /* Print the text. */ | 1541 /* Print the text. */ |
1395 _rl_output_some_chars (string, count); | 1542 _rl_output_some_chars (string, count); |
1396 | 1543 |
1397 /* If there is a string to turn off insert mode, we had best use | 1544 /* If there is a string to turn off insert mode, we had best use |
1398 it now. */ | 1545 it now. */ |
1399 if (term_ei && *term_ei) | 1546 if (_rl_term_ei && *_rl_term_ei) |
1400 tputs (term_ei, 1, _rl_output_character_function); | 1547 tputs (_rl_term_ei, 1, _rl_output_character_function); |
1401 } | 1548 } |
1402 #endif /* !__GO32__ */ | |
1403 } | 1549 } |
1404 | 1550 |
1405 /* Delete COUNT characters from the display line. */ | 1551 /* Delete COUNT characters from the display line. */ |
1406 static void | 1552 static void |
1407 delete_chars (count) | 1553 delete_chars (count) |
1408 int count; | 1554 int count; |
1409 { | 1555 { |
1410 #if defined (__GO32__) | 1556 if (count > _rl_screenwidth) /* XXX */ |
1411 int row, col, width; | |
1412 char *row_start; | |
1413 | |
1414 ScreenGetCursor (&row, &col); | |
1415 width = ScreenCols (); | |
1416 row_start = ScreenPrimary + (row * width); | |
1417 | |
1418 memcpy (row_start + col, row_start + col + count, width - col - count); | |
1419 memset (row_start + width - count, 0, count * 2); | |
1420 #else /* !_GO32 */ | |
1421 | |
1422 if (count > screenwidth) /* XXX */ | |
1423 return; | 1557 return; |
1424 | 1558 |
1425 if (term_DC && *term_DC) | 1559 if (_rl_term_DC && *_rl_term_DC) |
1426 { | 1560 { |
1427 char *buffer; | 1561 char *buffer; |
1428 buffer = tgoto (term_DC, count, count); | 1562 buffer = tgoto (_rl_term_DC, count, count); |
1429 tputs (buffer, count, _rl_output_character_function); | 1563 tputs (buffer, count, _rl_output_character_function); |
1430 } | 1564 } |
1431 else | 1565 else |
1432 { | 1566 { |
1433 if (term_dc && *term_dc) | 1567 if (_rl_term_dc && *_rl_term_dc) |
1434 while (count--) | 1568 while (count--) |
1435 tputs (term_dc, 1, _rl_output_character_function); | 1569 tputs (_rl_term_dc, 1, _rl_output_character_function); |
1436 } | 1570 } |
1437 #endif /* !__GO32__ */ | |
1438 } | 1571 } |
1439 | 1572 |
1440 void | 1573 void |
1441 _rl_update_final () | 1574 _rl_update_final () |
1442 { | 1575 { |
1451 _rl_vis_botlin--; | 1584 _rl_vis_botlin--; |
1452 full_lines = 1; | 1585 full_lines = 1; |
1453 } | 1586 } |
1454 _rl_move_vert (_rl_vis_botlin); | 1587 _rl_move_vert (_rl_vis_botlin); |
1455 /* If we've wrapped lines, remove the final xterm line-wrap flag. */ | 1588 /* If we've wrapped lines, remove the final xterm line-wrap flag. */ |
1456 if (full_lines && _rl_term_autowrap && (VIS_LLEN(_rl_vis_botlin) == screenwidth)) | 1589 if (full_lines && _rl_term_autowrap && (VIS_LLEN(_rl_vis_botlin) == _rl_screenwidth)) |
1457 { | 1590 { |
1458 char *last_line; | 1591 char *last_line; |
1592 #if 0 | |
1459 last_line = &visible_line[inv_lbreaks[_rl_vis_botlin]]; | 1593 last_line = &visible_line[inv_lbreaks[_rl_vis_botlin]]; |
1460 _rl_move_cursor_relative (screenwidth - 1, last_line); | 1594 #else |
1595 last_line = &visible_line[vis_lbreaks[_rl_vis_botlin]]; | |
1596 #endif | |
1597 _rl_move_cursor_relative (_rl_screenwidth - 1, last_line); | |
1461 _rl_clear_to_eol (0); | 1598 _rl_clear_to_eol (0); |
1462 putc (last_line[screenwidth - 1], rl_outstream); | 1599 putc (last_line[_rl_screenwidth - 1], rl_outstream); |
1463 } | 1600 } |
1464 _rl_vis_botlin = 0; | 1601 _rl_vis_botlin = 0; |
1465 crlf (); | 1602 rl_crlf (); |
1466 fflush (rl_outstream); | 1603 fflush (rl_outstream); |
1467 rl_display_fixed++; | 1604 rl_display_fixed++; |
1468 } | 1605 } |
1469 | 1606 |
1470 /* Move to the start of the current line. */ | 1607 /* Move to the start of the current line. */ |
1471 static void | 1608 static void |
1472 cr () | 1609 cr () |
1473 { | 1610 { |
1474 if (term_cr) | 1611 if (_rl_term_cr) |
1475 { | 1612 { |
1476 tputs (term_cr, 1, _rl_output_character_function); | 1613 #if defined (__MSDOS__) |
1614 putc ('\r', rl_outstream); | |
1615 #else | |
1616 tputs (_rl_term_cr, 1, _rl_output_character_function); | |
1617 #endif | |
1477 _rl_last_c_pos = 0; | 1618 _rl_last_c_pos = 0; |
1478 } | 1619 } |
1479 } | 1620 } |
1480 | 1621 |
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. */ | |
1625 static void | |
1626 redraw_prompt (t) | |
1627 char *t; | |
1628 { | |
1629 char *oldp, *oldl, *oldlprefix; | |
1630 int oldlen, oldlast, oldplen, oldninvis; | |
1631 | |
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; | |
1640 | |
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 (); | |
1647 | |
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; | |
1655 } | |
1656 | |
1481 /* Redisplay the current line after a SIGWINCH is received. */ | 1657 /* Redisplay the current line after a SIGWINCH is received. */ |
1482 void | 1658 void |
1483 _rl_redisplay_after_sigwinch () | 1659 _rl_redisplay_after_sigwinch () |
1484 { | 1660 { |
1485 char *t, *oldp; | 1661 char *t; |
1486 | 1662 |
1487 /* Clear the current line and put the cursor at column 0. Make sure | 1663 /* Clear the current line and put the cursor at column 0. Make sure |
1488 the right thing happens if we have wrapped to a new screen line. */ | 1664 the right thing happens if we have wrapped to a new screen line. */ |
1489 if (term_cr) | 1665 if (_rl_term_cr) |
1490 { | 1666 { |
1491 tputs (term_cr, 1, _rl_output_character_function); | 1667 #if defined (__MSDOS__) |
1668 putc ('\r', rl_outstream); | |
1669 #else | |
1670 tputs (_rl_term_cr, 1, _rl_output_character_function); | |
1671 #endif | |
1492 _rl_last_c_pos = 0; | 1672 _rl_last_c_pos = 0; |
1493 if (term_clreol) | 1673 #if defined (__MSDOS__) |
1494 tputs (term_clreol, 1, _rl_output_character_function); | 1674 space_to_eol (_rl_screenwidth); |
1675 putc ('\r', rl_outstream); | |
1676 #else | |
1677 if (_rl_term_clreol) | |
1678 tputs (_rl_term_clreol, 1, _rl_output_character_function); | |
1495 else | 1679 else |
1496 { | 1680 { |
1497 space_to_eol (screenwidth); | 1681 space_to_eol (_rl_screenwidth); |
1498 tputs (term_cr, 1, _rl_output_character_function); | 1682 tputs (_rl_term_cr, 1, _rl_output_character_function); |
1499 } | 1683 } |
1684 #endif | |
1500 if (_rl_last_v_pos > 0) | 1685 if (_rl_last_v_pos > 0) |
1501 _rl_move_vert (0); | 1686 _rl_move_vert (0); |
1502 } | 1687 } |
1503 else | 1688 else |
1504 crlf (); | 1689 rl_crlf (); |
1505 | 1690 |
1506 /* Redraw only the last line of a multi-line prompt. */ | 1691 /* Redraw only the last line of a multi-line prompt. */ |
1507 t = strrchr (rl_display_prompt, '\n'); | 1692 t = strrchr (rl_display_prompt, '\n'); |
1508 if (t) | 1693 if (t) |
1509 { | 1694 redraw_prompt (++t); |
1510 oldp = rl_display_prompt; | |
1511 rl_display_prompt = ++t; | |
1512 rl_forced_update_display (); | |
1513 rl_display_prompt = oldp; | |
1514 } | |
1515 else | 1695 else |
1516 rl_forced_update_display (); | 1696 rl_forced_update_display (); |
1517 } | 1697 } |
1518 | 1698 |
1519 void | 1699 void |
1522 if (readline_echoing_p) | 1702 if (readline_echoing_p) |
1523 { | 1703 { |
1524 _rl_move_vert (_rl_vis_botlin); | 1704 _rl_move_vert (_rl_vis_botlin); |
1525 _rl_vis_botlin = 0; | 1705 _rl_vis_botlin = 0; |
1526 fflush (rl_outstream); | 1706 fflush (rl_outstream); |
1527 rl_restart_output (); | 1707 rl_restart_output (1, 0); |
1528 } | 1708 } |
1529 } | 1709 } |
1710 | |
1711 void | |
1712 _rl_erase_entire_line () | |
1713 { | |
1714 cr (); | |
1715 _rl_clear_to_eol (0); | |
1716 cr (); | |
1717 fflush (rl_outstream); | |
1718 } | |
1719 | |
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. */ | |
1722 int | |
1723 _rl_current_display_line () | |
1724 { | |
1725 int ret, nleft; | |
1726 | |
1727 /* Find out whether or not there might be invisible characters in the | |
1728 editing buffer. */ | |
1729 if (rl_display_prompt == rl_prompt) | |
1730 nleft = _rl_last_c_pos - _rl_screenwidth - rl_visible_prompt_length; | |
1731 else | |
1732 nleft = _rl_last_c_pos - _rl_screenwidth; | |
1733 | |
1734 if (nleft > 0) | |
1735 ret = 1 + nleft / _rl_screenwidth; | |
1736 else | |
1737 ret = 0; | |
1738 | |
1739 return ret; | |
1740 } |