Deleted Added
sdiff udiff text old ( 47563 ) new ( 58314 )
full compact
1/* display.c -- readline redisplay facility. */
2
3/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
4
5 This file is part of the GNU Readline Library, a library for
6 reading lines of text with interactive input and history editing.
7
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 1, or
11 (at your option) any later version.
12
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.
17
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 675 Mass Ave, Cambridge, MA 02139, USA. */
22#define READLINE_LIBRARY
23
24#if defined (HAVE_CONFIG_H)
25# include <config.h>
26#endif
27
28#include <sys/types.h>
29

--- 6 unchanged lines hidden (view full) ---

36#if defined (HAVE_STDLIB_H)
37# include <stdlib.h>
38#else
39# include "ansi_stdlib.h"
40#endif /* HAVE_STDLIB_H */
41
42#include <stdio.h>
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. */
50#include "rldefs.h"
51
52/* Termcap library stuff. */
53#include "tcap.h"
54
55/* Some standard library routines. */
56#include "readline.h"
57#include "history.h"
58
59#if !defined (strchr) && !defined (__STDC__)
60extern char *strchr (), *strrchr ();
61#endif /* !strchr && !__STDC__ */
62
63/* Global and pseudo-global variables and functions
64 imported from readline.c. */
65extern char *rl_prompt;
66extern int readline_echoing_p;
67
68extern int _rl_output_meta_chars;
69extern int _rl_horizontal_scroll_mode;
70extern int _rl_mark_modified_lines;
71extern int _rl_prefer_visible_bell;
72
73/* Variables and functions imported from terminal.c */
74extern void _rl_output_some_chars ();
75#ifdef _MINIX
76extern void _rl_output_character_function ();
77#else
78extern int _rl_output_character_function ();
79#endif
80extern int _rl_backspace ();
81
82extern char *term_clreol, *term_clrpag;
83extern char *term_im, *term_ic, *term_ei, *term_DC;
84extern char *term_up, *term_dc, *term_cr, *term_IC;
85extern int screenheight, screenwidth, screenchars;
86extern int terminal_can_insert, _rl_term_autowrap;
87
88/* Pseudo-global functions (local to the readline library) exported
89 by this file. */
90void _rl_move_cursor_relative (), _rl_output_some_chars ();
91void _rl_move_vert ();
92void _rl_clear_to_eol (), _rl_clear_screen ();
93
94static void update_line (), space_to_eol ();
95static void delete_chars (), insert_some_chars ();
96static void cr ();
97
98static int *inv_lbreaks, *vis_lbreaks;
99
100extern char *xmalloc (), *xrealloc ();
101
102/* Heuristic used to decide whether it is faster to move from CUR to NEW
103 by backing up or outputting a carriage return and moving forward. */
104#define CR_FASTER(new, cur) (((new) + 1) < ((cur) - (new)))
105
106/* **************************************************************** */
107/* */
108/* Display stuff */
109/* */

--- 75 unchanged lines hidden (view full) ---

185
186/* The length (buffer offset) of the first line of the last (possibly
187 multi-line) buffer displayed on the screen. */
188static int visible_first_line_len;
189
190/* Expand the prompt string S and return the number of visible
191 characters in *LP, if LP is not null. This is currently more-or-less
192 a placeholder for expansion. LIP, if non-null is a place to store the
193 index of the last invisible character in ther eturned string. */
194
195/* Current implementation:
196 \001 (^A) start non-visible characters
197 \002 (^B) end non-visible characters
198 all characters except \001 and \002 (following a \001) are copied to
199 the returned string; all characters except those between \001 and
200 \002 are assumed to be `visible'. */
201

--- 43 unchanged lines hidden (view full) ---

245 *r = '\0';
246 if (lp)
247 *lp = rl;
248 if (lip)
249 *lip = last;
250 return ret;
251}
252
253/*
254 * Expand the prompt string into the various display components, if
255 * necessary.
256 *
257 * local_prompt = expanded last line of string in rl_display_prompt
258 * (portion after the final newline)
259 * local_prompt_prefix = portion before last newline of rl_display_prompt,
260 * expanded via expand_prompt

--- 41 unchanged lines hidden (view full) ---

302 /* The portion of the prompt string up to and including the
303 final newline is now null-terminated. */
304 local_prompt_prefix = expand_prompt (prompt, &prefix_length, (int *)NULL);
305 *t = c;
306 return (prefix_length);
307 }
308}
309
310/* Basic redisplay algorithm. */
311void
312rl_redisplay ()
313{
314 register int in, out, c, linenum, cursor_linenum;
315 register char *line;
316 int c_pos, inv_botlin, lb_botlin, lb_linenum;
317 int newlines, lpos, temp;
318 char *prompt_this_line;
319
320 if (!readline_echoing_p)
321 return;
322
323 if (!rl_display_prompt)
324 rl_display_prompt = "";
325
326 if (invisible_line == 0)
327 {
328 visible_line = xmalloc (line_size);
329 invisible_line = xmalloc (line_size);
330 for (in = 0; in < line_size; in++)
331 {
332 visible_line[in] = 0;
333 invisible_line[in] = 1;
334 }
335
336 /* should be enough, but then again, this is just for testing. */
337 inv_lbreaks = (int *)malloc (256 * sizeof (int));
338 vis_lbreaks = (int *)malloc (256 * sizeof (int));
339 inv_lbreaks[0] = vis_lbreaks[0] = 0;
340
341 rl_on_new_line ();
342 }
343
344 /* Draw the line into the buffer. */
345 c_pos = -1;
346
347 line = invisible_line;
348 out = inv_botlin = 0;

--- 41 unchanged lines hidden (view full) ---

390 {
391 int pmtlen;
392 prompt_this_line = strrchr (rl_display_prompt, '\n');
393 if (!prompt_this_line)
394 prompt_this_line = rl_display_prompt;
395 else
396 {
397 prompt_this_line++;
398 if (forced_display)
399 {
400 _rl_output_some_chars (rl_display_prompt, prompt_this_line - rl_display_prompt);
401 /* Make sure we are at column zero even after a newline,
402 regardless of the state of terminal output processing. */
403 if (prompt_this_line[-2] != '\r')
404 cr ();
405 }
406 }
407
408 pmtlen = strlen (prompt_this_line);
409 temp = pmtlen + out + 2;
410 if (temp >= line_size)
411 {
412 line_size = (temp + 1024) - (temp % 1024);
413 visible_line = xrealloc (visible_line, line_size);
414 line = invisible_line = xrealloc (invisible_line, line_size);
415 }
416 strncpy (line + out, prompt_this_line, pmtlen);
417 out += pmtlen;
418 line[out] = '\0';
419 wrap_offset = 0;
420 }
421
422#define CHECK_LPOS() \
423 do { \
424 lpos++; \
425 if (lpos >= screenwidth) \
426 { \
427 inv_lbreaks[++newlines] = out; \
428 lpos = 0; \
429 } \
430 } while (0)
431
432 /* inv_lbreaks[i] is where line i starts in the buffer. */
433 inv_lbreaks[newlines = 0] = 0;
434 lpos = out - wrap_offset;
435
436 /* XXX - what if lpos is already >= screenwidth before we start drawing the
437 contents of the command line? */
438 while (lpos >= screenwidth)
439 {
440#if 0
441 temp = ((newlines + 1) * screenwidth) - ((newlines == 0) ? wrap_offset : 0);
442#else
443 /* XXX - possible fix from Darin Johnson <darin@acuson.com> for prompt
444 string with invisible characters that is longer than the screen
445 width. */
446 temp = ((newlines + 1) * screenwidth) + ((newlines == 0) ? wrap_offset : 0);
447#endif
448 inv_lbreaks[++newlines] = temp;
449 lpos -= screenwidth;
450 }
451
452 lb_linenum = 0;
453 for (in = 0; in < rl_end; in++)
454 {
455 c = (unsigned char)rl_line_buffer[in];

--- 16 unchanged lines hidden (view full) ---

472 {
473 if (_rl_output_meta_chars == 0)
474 {
475 sprintf (line + out, "\\%o", c);
476
477 if (lpos + 4 >= screenwidth)
478 {
479 temp = screenwidth - lpos;
480 inv_lbreaks[++newlines] = out + temp;
481 lpos = 4 - temp;
482 }
483 else
484 lpos += 4;
485
486 out += 4;
487 }

--- 13 unchanged lines hidden (view full) ---

501#else
502 newout = out + 8 - lpos % 8;
503#endif
504 temp = newout - out;
505 if (lpos + temp >= screenwidth)
506 {
507 register int temp2;
508 temp2 = screenwidth - lpos;
509 inv_lbreaks[++newlines] = out + temp2;
510 lpos = temp - temp2;
511 while (out < newout)
512 line[out++] = ' ';
513 }
514 else
515 {
516 while (out < newout)
517 line[out++] = ' ';
518 lpos += temp;
519 }
520 }
521#endif
522 else if (c == '\n' && _rl_horizontal_scroll_mode == 0 && term_up && *term_up)
523 {
524 line[out++] = '\0'; /* XXX - sentinel */
525 inv_lbreaks[++newlines] = out;
526 lpos = 0;
527 }
528 else if (CTRL_CHAR (c) || c == RUBOUT)
529 {
530 line[out++] = '^';
531 CHECK_LPOS();
532 line[out++] = CTRL_CHAR (c) ? UNCTRL (c) : '?';

--- 8 unchanged lines hidden (view full) ---

541 line[out] = '\0';
542 if (c_pos < 0)
543 {
544 c_pos = out;
545 lb_linenum = newlines;
546 }
547
548 inv_botlin = lb_botlin = newlines;
549 inv_lbreaks[newlines+1] = out;
550 cursor_linenum = lb_linenum;
551
552 /* C_POS == position in buffer where cursor should be placed. */
553
554 /* PWP: now is when things get a bit hairy. The visible and invisible
555 line buffers are really multiple lines, which would wrap every
556 (screenwidth - 1) characters. Go through each in turn, finding

--- 89 unchanged lines hidden (view full) ---

646 characters, since it's not generally OK to just reprint
647 the characters from the current cursor position. But we
648 only need to reprint it if the cursor is before the last
649 invisible character in the prompt string. */
650 nleft = visible_length + wrap_offset;
651 if (cursor_linenum == 0 && wrap_offset > 0 && _rl_last_c_pos > 0 &&
652 _rl_last_c_pos <= last_invisible && local_prompt)
653 {
654 if (term_cr)
655 tputs (term_cr, 1, _rl_output_character_function);
656 _rl_output_some_chars (local_prompt, nleft);
657 _rl_last_c_pos = nleft;
658 }
659
660 /* Where on that line? And where does that line start
661 in the buffer? */
662 pos = inv_lbreaks[cursor_linenum];
663 /* nleft == number of characters in the line buffer between the

--- 103 unchanged lines hidden (view full) ---

767 last_lmargin = lmargin;
768 }
769 }
770 fflush (rl_outstream);
771
772 /* Swap visible and non-visible lines. */
773 {
774 char *temp = visible_line;
775 int *itemp = vis_lbreaks;
776 visible_line = invisible_line;
777 invisible_line = temp;
778 vis_lbreaks = inv_lbreaks;
779 inv_lbreaks = itemp;
780 rl_display_fixed = 0;
781 /* If we are displaying on a single line, and last_lmargin is > 0, we
782 are not displaying any invisible characters, so set visible_wrap_offset
783 to 0. */
784 if (_rl_horizontal_scroll_mode && last_lmargin)
785 visible_wrap_offset = 0;
786 else
787 visible_wrap_offset = wrap_offset;

--- 106 unchanged lines hidden (view full) ---

894 `bold') that manifests itself on certain terminals. */
895
896 lendiff = local_prompt ? strlen (local_prompt) : 0;
897 od = ofd - old; /* index of first difference in visible line */
898 if (current_line == 0 && !_rl_horizontal_scroll_mode &&
899 term_cr && lendiff > visible_length && _rl_last_c_pos > 0 &&
900 od > lendiff && _rl_last_c_pos < last_invisible)
901 {
902 tputs (term_cr, 1, _rl_output_character_function);
903 _rl_output_some_chars (local_prompt, lendiff);
904 _rl_last_c_pos = lendiff;
905 }
906
907 _rl_move_cursor_relative (od, old);
908
909 /* if (len (new) > len (old)) */
910 lendiff = (nls - nfd) - (ols - ofd);

--- 113 unchanged lines hidden (view full) ---

1024 _rl_last_c_pos = _rl_last_v_pos = 0;
1025 _rl_vis_botlin = last_lmargin = 0;
1026 if (vis_lbreaks)
1027 vis_lbreaks[0] = vis_lbreaks[1] = 0;
1028 visible_wrap_offset = 0;
1029 return 0;
1030}
1031
1032/* Actually update the display, period. */
1033int
1034rl_forced_update_display ()
1035{
1036 if (visible_line)
1037 {
1038 register char *temp = visible_line;
1039

--- 41 unchanged lines hidden (view full) ---

1081 portion of the output buffer again. Which is cheaper? */
1082
1083 /* The above comment is left here for posterity. It is faster
1084 to print one character (non-control) than to print a control
1085 sequence telling the terminal to move forward one character.
1086 That kind of control is for people who don't know what the
1087 data is underneath the cursor. */
1088#if defined (HACK_TERMCAP_MOTION)
1089 extern char *term_forward_char;
1090
1091 if (term_forward_char)
1092 for (i = _rl_last_c_pos; i < new; i++)
1093 tputs (term_forward_char, 1, _rl_output_character_function);
1094 else
1095 for (i = _rl_last_c_pos; i < new; i++)
1096 putc (data[i], rl_outstream);
1097#else
1098 for (i = _rl_last_c_pos; i < new; i++)

--- 10 unchanged lines hidden (view full) ---

1109_rl_move_vert (to)
1110 int to;
1111{
1112 register int delta, i;
1113
1114 if (_rl_last_v_pos == to || to > screenheight)
1115 return;
1116
1117#if defined (__GO32__)
1118 {
1119 int row, col;
1120
1121 ScreenGetCursor (&row, &col);
1122 ScreenSetCursor ((row + to - _rl_last_v_pos), col);
1123 }
1124#else /* !__GO32__ */
1125
1126 if ((delta = to - _rl_last_v_pos) > 0)
1127 {
1128 for (i = 0; i < delta; i++)
1129 putc ('\n', rl_outstream);
1130 tputs (term_cr, 1, _rl_output_character_function);
1131 _rl_last_c_pos = 0;
1132 }
1133 else
1134 { /* delta < 0 */
1135 if (term_up && *term_up)
1136 for (i = 0; i < -delta; i++)
1137 tputs (term_up, 1, _rl_output_character_function);
1138 }
1139#endif /* !__GO32__ */
1140 _rl_last_v_pos = to; /* Now TO is here */
1141}
1142
1143/* Physically print C on rl_outstream. This is for functions which know
1144 how to optimize the display. Return the number of characters output. */
1145int
1146rl_show_char (c)
1147 int c;

--- 191 unchanged lines hidden (view full) ---

1339}
1340
1341/* Clear to the end of the line. COUNT is the minimum
1342 number of character spaces to clear, */
1343void
1344_rl_clear_to_eol (count)
1345 int count;
1346{
1347#if !defined (__GO32__)
1348 if (term_clreol)
1349 tputs (term_clreol, 1, _rl_output_character_function);
1350 else if (count)
1351#endif /* !__GO32__ */
1352 space_to_eol (count);
1353}
1354
1355/* Clear to the end of the line using spaces. COUNT is the minimum
1356 number of character spaces to clear, */
1357static void
1358space_to_eol (count)
1359 int count;

--- 4 unchanged lines hidden (view full) ---

1364 putc (' ', rl_outstream);
1365
1366 _rl_last_c_pos += count;
1367}
1368
1369void
1370_rl_clear_screen ()
1371{
1372#if !defined (__GO32__)
1373 if (term_clrpag)
1374 tputs (term_clrpag, 1, _rl_output_character_function);
1375 else
1376#endif /* !__GO32__ */
1377 crlf ();
1378}
1379
1380/* Insert COUNT characters from STRING to the output stream. */
1381static void
1382insert_some_chars (string, count)
1383 char *string;
1384 int count;
1385{
1386#if defined (__GO32__)
1387 int row, col, width;
1388 char *row_start;
1389
1390 ScreenGetCursor (&row, &col);
1391 width = ScreenCols ();
1392 row_start = ScreenPrimary + (row * width);
1393
1394 memcpy (row_start + col + count, row_start + col, width - col - count);
1395
1396 /* Place the text on the screen. */
1397 _rl_output_some_chars (string, count);
1398#else /* !_GO32 */
1399
1400 /* If IC is defined, then we do not have to "enter" insert mode. */
1401 if (term_IC)
1402 {
1403 char *buffer;
1404 buffer = tgoto (term_IC, 0, count);
1405 tputs (buffer, 1, _rl_output_character_function);
1406 _rl_output_some_chars (string, count);
1407 }

--- 16 unchanged lines hidden (view full) ---

1424 /* Print the text. */
1425 _rl_output_some_chars (string, count);
1426
1427 /* If there is a string to turn off insert mode, we had best use
1428 it now. */
1429 if (term_ei && *term_ei)
1430 tputs (term_ei, 1, _rl_output_character_function);
1431 }
1432#endif /* !__GO32__ */
1433}
1434
1435/* Delete COUNT characters from the display line. */
1436static void
1437delete_chars (count)
1438 int count;
1439{
1440#if defined (__GO32__)
1441 int row, col, width;
1442 char *row_start;
1443
1444 ScreenGetCursor (&row, &col);
1445 width = ScreenCols ();
1446 row_start = ScreenPrimary + (row * width);
1447
1448 memcpy (row_start + col, row_start + col + count, width - col - count);
1449 memset (row_start + width - count, 0, count * 2);
1450#else /* !_GO32 */
1451
1452 if (count > screenwidth) /* XXX */
1453 return;
1454
1455 if (term_DC && *term_DC)
1456 {
1457 char *buffer;
1458 buffer = tgoto (term_DC, count, count);
1459 tputs (buffer, count, _rl_output_character_function);
1460 }
1461 else
1462 {
1463 if (term_dc && *term_dc)
1464 while (count--)
1465 tputs (term_dc, 1, _rl_output_character_function);
1466 }
1467#endif /* !__GO32__ */
1468}
1469
1470void
1471_rl_update_final ()
1472{
1473 int full_lines;
1474
1475 full_lines = 0;

--- 5 unchanged lines hidden (view full) ---

1481 _rl_vis_botlin--;
1482 full_lines = 1;
1483 }
1484 _rl_move_vert (_rl_vis_botlin);
1485 /* If we've wrapped lines, remove the final xterm line-wrap flag. */
1486 if (full_lines && _rl_term_autowrap && (VIS_LLEN(_rl_vis_botlin) == screenwidth))
1487 {
1488 char *last_line;
1489 last_line = &visible_line[inv_lbreaks[_rl_vis_botlin]];
1490 _rl_move_cursor_relative (screenwidth - 1, last_line);
1491 _rl_clear_to_eol (0);
1492 putc (last_line[screenwidth - 1], rl_outstream);
1493 }
1494 _rl_vis_botlin = 0;
1495 crlf ();
1496 fflush (rl_outstream);
1497 rl_display_fixed++;
1498}
1499
1500/* Move to the start of the current line. */
1501static void
1502cr ()
1503{
1504 if (term_cr)
1505 {
1506 tputs (term_cr, 1, _rl_output_character_function);
1507 _rl_last_c_pos = 0;
1508 }
1509}
1510
1511/* Redisplay the current line after a SIGWINCH is received. */
1512void
1513_rl_redisplay_after_sigwinch ()
1514{
1515 char *t, *oldp, *oldl, *oldlprefix;
1516
1517 /* Clear the current line and put the cursor at column 0. Make sure
1518 the right thing happens if we have wrapped to a new screen line. */
1519 if (term_cr)
1520 {
1521 tputs (term_cr, 1, _rl_output_character_function);
1522 _rl_last_c_pos = 0;
1523 if (term_clreol)
1524 tputs (term_clreol, 1, _rl_output_character_function);
1525 else
1526 {
1527 space_to_eol (screenwidth);
1528 tputs (term_cr, 1, _rl_output_character_function);
1529 }
1530 if (_rl_last_v_pos > 0)
1531 _rl_move_vert (0);
1532 }
1533 else
1534 crlf ();
1535
1536 /* Redraw only the last line of a multi-line prompt. */
1537 t = strrchr (rl_display_prompt, '\n');
1538 if (t)
1539 {
1540 oldp = rl_display_prompt;
1541 oldl = local_prompt;
1542 oldlprefix = local_prompt_prefix;
1543 rl_display_prompt = ++t;
1544 local_prompt = local_prompt_prefix = (char *)NULL;
1545 rl_forced_update_display ();
1546 rl_display_prompt = oldp;
1547 local_prompt = oldl;
1548 local_prompt_prefix = oldlprefix;
1549 }
1550 else
1551 rl_forced_update_display ();
1552}
1553
1554void
1555_rl_clean_up_for_exit ()
1556{
1557 if (readline_echoing_p)

--- 8 unchanged lines hidden (view full) ---

1566void
1567_rl_erase_entire_line ()
1568{
1569 cr ();
1570 _rl_clear_to_eol (0);
1571 cr ();
1572 fflush (rl_outstream);
1573}