Re: Internal editor brokeness with ncurses



Hello,

On Sun, 2 May 2004, [ISO-8859-1] Frédéric L. W. Meunier wrote:

> See the thread starting at
> http://sources.redhat.com/ml/cygwin/2004-05/msg00015.html

Attached is a patch + testcase.

The internal editor sometimes outputs more than one char on the screen for
a given byte of input:

0x09          -> 8 characters
0x00 .. 0x1F  -> 2 characters
0x7F          -> 2 characters

In these cases several columns on the screen refer to a single byte of
input. Now, when the user scrolls the screen to the right it may happen
that the first column that should be displayed is in the middle of a
group of columns representing a single char:

0 .................. 11 .... 15

 TAB1-+          TAB2-+
      |               |
/-----+-------\ /-----+-------\
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
                      ^
First col after       |
scrolling by 11 ------+

In this case output is generated starting at the input byte containing
the column i.e. TAB2. Obviously there are 3 columns that should be ignored
and MC's editor doest this by using the routine `move ()'  giving it
a negative index for the 'X' axis. This apparently does work for S-Lang,
but does not for ncurses. So with ncurses the characters are actually not
ignored and are drawn to the screen. Then the following happens:

[ quote from cur_addch(3X) ]

"If  the  advance is at the right margin, the cursor automatically wraps
to the beginning of the next line."

This is not immediately seen though. One should update the screen in some
way i.e. pressing Ctrl + L turns to do the work without messing the
screen too much.

I've attached a simple patch (mc-edit-print-eol-mark.patch) which helps
to understand the issue. Patch edit/editdraw.c with it and you'll see
an '&' character at the place where the newline should be. It can be used
with the attached testcase file (tab.txt) like this:

1. mcedit tab.txt

2. go to line longer than you screen and press End

3. press Ctrl + L

4. watch the next line

Now about the patch. It doesn't use the screen library's routine
move () to eat the excessive output, but rather doesn't generate
output at all for those columns. I tested MC compiled wiht both S-Lang
and ncurses on Cygwin and Linux.
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
	blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
		blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
			blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
				blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
					blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
						blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
							blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
								blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
									blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
										blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
									blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
								blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
							blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
						blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
					blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
				blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
			blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
		blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
	blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
Index: editdraw.c
===================================================================
RCS file: /cvsroot/mc/mc/edit/editdraw.c,v
retrieving revision 1.34
diff -u -p -r1.34 editdraw.c
--- editdraw.c	23 Oct 2004 13:14:14 -0000	1.34
+++ editdraw.c	29 Oct 2004 09:30:27 -0000
@@ -282,7 +282,7 @@ edit_draw_this_line (WEdit *edit, long b
 		switch (c) {
 		case '\n':
 		    col = end_col - edit->start_col + 1;	/* quit */
-		    *(p++) |= ' ';
+		    *(p++) |= '&';
 		    break;
 		case '\t':
 		    i = TAB_SIZE - ((int) col % TAB_SIZE);
Index: editdraw.c
===================================================================
RCS file: /cvsroot/mc/mc/edit/editdraw.c,v
retrieving revision 1.34
diff -u -p -r1.34 editdraw.c
--- editdraw.c	23 Oct 2004 13:14:14 -0000	1.34
+++ editdraw.c	29 Oct 2004 09:35:18 -0000
@@ -21,6 +21,7 @@
 */
 
 #include <config.h>
+#include <stdlib.h>
 #include "edit.h"
 #include "edit-widget.h"
 
@@ -191,18 +192,29 @@ print_to_widget (WEdit *edit, long row, 
     int x = start_col_real + EDIT_TEXT_HORIZONTAL_OFFSET;
     int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET;
     int y = row + EDIT_TEXT_VERTICAL_OFFSET;
+    int cols_to_skip = abs (x);
 
     set_color (EDITOR_NORMAL_COLOR);
     edit_move (x1, y);
     hline (' ', end_col + 1 - EDIT_TEXT_HORIZONTAL_OFFSET - x1);
 
-    edit_move (x + FONT_OFFSET_X, y + FONT_OFFSET_Y);
+    edit_move (x1 + FONT_OFFSET_X, y + FONT_OFFSET_Y);
     p = line;
 
     while (*p) {
-	int style = *p & 0xFF00;
-	int textchar = *p & 0xFF;
-	int color = *p >> 16;
+	int style;
+	int textchar;
+	int color;
+
+	if (cols_to_skip) {
+	    p++;
+	    cols_to_skip--;
+	    continue;
+	}
+
+	style = *p & 0xFF00;
+	textchar = *p & 0xFF;
+	color = *p >> 16;
 
 	if (style & MOD_ABNORMAL) {
 	    /* Non-printable - use black background */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]