Re: subshell prompt fix



Hello Pavel,

On Mon, 2004-11-22 at 21:42 +0200, Pavel Tsekov wrote:
> > On Wed, 2004-11-03 at 11:29, Pavel Shirshov (pchel) wrote:
> > >     But. I see another:
> > >     1) run mc
> > >     2) C-o
> > >     3) C-o again
> > >     4) C-o
> > >
> > >     2) you see: genie#
> > >     4) you see:
> > >     ^^^^^^^^^^^ I can't see promt.
> >
> > Weird, I'm unable to reproduce your case, which terminal do you use?
> > It's smoothly reproducible with gnome-terminal and xterm, I haven't
> > tried rxvt. Do you chdir in steps 2) and 4) ?
> 
> I've just tried the above on a FreeBSD machine account provided by Pavel
> Shirshov. I run FC3 with GNOME desktop so I use gnome-terminal. When I
> ssh into the remote machine (FreeBSD) I have the TERM variable set to
> 'xterm' - in this case everything is fine. Now, I've tried changing the
> value of TERM to 'vt220'... surprise, surprise - the subshell prompt is
> missing just as Pavel says. So I've started a fresh gnome-terminal
> on my machine (FC3) and set TERM to 'vt220' - again no prompt. I've tried
> also with konsole with the same result.
> 
> Soooo... what does this mean ? :)

Please see the top of the thread:
http://mail.gnome.org/archives/mc-devel/2004-November/msg00031.html

Since you're running FC3 with GNOME desktop and gnome-terminal with
TERM=xterm, you should smoothly reproduce the original bug I've been
trying to fix since I found this bug exactly with the same
configuration.

To fix the both cases of the bug we should probably get TERM variable
from the environment and do a specific fix related to its contents.

The attached patch does the following:

1st hunk:
the removed part caused to cut out the beginning of the prompt so we
get:

<truncated dir name>]$
instead of:
[jnovy obelix <shortened dir name>]$

this part of code just prints the whole prompt without shortening to
subshell_prompt to let the prompt be displayed correctly via load_prompt
().

2nd hunk:
fix of the prompt drawing in subshell. It should display correct prompt
if it's size is less than COLS and redraw only the part of line where
was a previous prompt. If the prompt is larger that COLS, it'll draw the
prompt at a new line. Some additional work for this should be done since
we can use escape sequences to improve it a bit. And maybe we should cap
the value of COLS, etc.

3rd hunk:
Displays shrinked prompt in the panel (not subshell) mode with using
name_trunc(). This part is needed to let the prompt be displayed as
noted in the comment to 1st hunk.

Any comments are welcome.

greetings,
Jindrich

-- 
Jindrich Novy <jnovy redhat com>, http://people.redhat.com/jnovy/
--- mc-4.6.1-20041124/src/subshell.c.promptfix	2004-11-03 20:43:17.000000000 +0100
+++ mc-4.6.1-20041124/src/subshell.c	2004-11-24 10:24:49.760461024 +0100
@@ -596,19 +596,15 @@
 	bytes = read (subshell_pty, pty_buffer, pty_buffer_size);
 
 	/* Extract the prompt from the shell output */
-
-	for (i = 0; i < bytes; ++i)
-	    if (pty_buffer[i] == '\n' || pty_buffer[i] == '\r') {
-		prompt_pos = 0;
-	    } else {
-		if (!pty_buffer[i])
-		    continue;
-
-		subshell_prompt[prompt_pos++] = pty_buffer[i];
-		if (prompt_pos == prompt_size)
-		    subshell_prompt =
-			g_realloc (subshell_prompt, prompt_size *= 2);
-	    }
+	for (i = 0; i < bytes; ++i) {
+            if (pty_buffer[i] == '\n' || pty_buffer[i] == '\r' ||
+                !pty_buffer[i])  continue;
+
+            subshell_prompt[prompt_pos++] = pty_buffer[i];
+            if (prompt_pos == prompt_size)
+                subshell_prompt =
+                    g_realloc (subshell_prompt, prompt_size *= 2);
+        }
 
 	subshell_prompt[prompt_pos] = '\0';
     }
--- mc-4.6.1-20041124/src/main.c.promptfix	2004-10-22 07:47:25.000000000 +0200
+++ mc-4.6.1-20041124/src/main.c	2004-11-24 10:28:29.172105384 +0100
@@ -433,8 +433,14 @@
 void
 do_update_prompt (void)
 {
+    static int prompt_size = 0;
+
     if (update_prompt) {
-	printf ("%s", subshell_prompt);
+      if ( !prompt_size || prompt_size > COLS ) {
+            printf (!prompt_size ? "\r%*c\r%s" : "\n\r%*c\r%s", COLS, ' ',
+                    subshell_prompt);
+        } else
+            printf ("\r%*c\r%s", prompt_size, ' ', subshell_prompt);
 	fflush (stdout);
 	update_prompt = 0;
     }
@@ -699,15 +705,11 @@
 	prompt = strip_ctrl_codes (subshell_prompt);
 	prompt_len = strlen (prompt);
 
-	/* Check for prompts too big */
-	if (COLS > 8 && prompt_len > COLS - 8) {
-	    prompt[COLS - 8] = 0;
-	    prompt_len = COLS - 8;
-	}
-	label_set_text (the_prompt, prompt);
-	winput_set_origin ((WInput *) cmdline, prompt_len,
-			   COLS - prompt_len);
-
+	/* Shrink the prompt if it's too big */
+	label_set_text (the_prompt, name_trunc (prompt, COLS - 8));
+        prompt_len = prompt_len <= COLS - 8 ? prompt_len : COLS - 8;
+        winput_set_origin ((WInput *) cmdline, prompt_len,
+                           COLS - prompt_len);
 	/* since the prompt has changed, and we are called from one of the 
 	 * get_event channels, the prompt updating does not take place
 	 * automatically: force a cursor update and a screen refresh


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