c148d92
--- mc-2007-06-04-22/src/execute.c.prompt	2005-09-28 23:28:06.000000000 +0200
c148d92
+++ mc-2007-06-04-22/src/execute.c	2007-06-20 14:07:17.000000000 +0200
c148d92
@@ -140,6 +140,8 @@ do_execute (const char *shell, const cha
c148d92
 	    printf ("\r\n");
c148d92
 	    fflush (stdout);
c148d92
 	}
c148d92
+	update_prompt = TRUE;
c148d92
+	do_update_prompt ();
c148d92
 	if (console_flag) {
c148d92
 	    if (output_lines && keybar_visible) {
c148d92
 		putchar ('\n');
c148d92
--- mc-2007-06-04-22/src/main.c.prompt	2007-06-20 14:07:17.000000000 +0200
c148d92
+++ mc-2007-06-04-22/src/main.c	2007-06-20 14:07:17.000000000 +0200
c148d92
@@ -454,7 +454,7 @@ void
d9f085b
 do_update_prompt (void)
d9f085b
 {
d9f085b
     if (update_prompt) {
d9f085b
-	printf ("%s", subshell_prompt);
c148d92
+	printf ("\r\n%s", original_subshell_prompt);
c148d92
 	fflush (stdout);
d9f085b
 	update_prompt = 0;
d9f085b
     }
c148d92
--- mc-2007-06-04-22/src/subshell.h.prompt	2004-12-03 20:17:47.000000000 +0100
c148d92
+++ mc-2007-06-04-22/src/subshell.h	2007-06-20 14:07:17.000000000 +0200
c148d92
@@ -20,6 +20,9 @@ extern enum subshell_state_enum subshell
c148d92
 /* Holds the latest prompt captured from the subshell */
c148d92
 extern char *subshell_prompt;
c148d92
 
c148d92
+/* Holds the latest prompt captured from the subshell with terminal codes */
c148d92
+extern char *original_subshell_prompt;
c148d92
+
c148d92
 /* For the `how' argument to various functions */
c148d92
 enum {QUIETLY, VISIBLY};
c148d92
 
c148d92
--- mc-2007-06-04-22/src/subshell.c.prompt	2007-06-20 14:07:17.000000000 +0200
c148d92
+++ mc-2007-06-04-22/src/subshell.c	2007-06-20 14:24:14.000000000 +0200
c148d92
@@ -107,6 +107,9 @@ enum subshell_state_enum subshell_state;
c148d92
 /* Holds the latest prompt captured from the subshell */
c148d92
 char *subshell_prompt = NULL;
c148d92
 
c148d92
+/* Holds the latest prompt captured from the subshell with terminal codes */
c148d92
+char *original_subshell_prompt = NULL;
c148d92
+
c148d92
 /* Initial length of the buffer for the subshell's prompt */
c148d92
 #define INITIAL_PROMPT_SIZE 10
c148d92
 
c148d92
@@ -148,6 +151,7 @@ static struct termios raw_mode;
c148d92
 /* This counter indicates how many characters of prompt we have read */
c148d92
 /* FIXME: try to figure out why this had to become global */
c148d92
 static int prompt_pos;
c148d92
+static int original_prompt_pos;
c148d92
 
c148d92
 
c148d92
 /*
c148d92
@@ -567,6 +571,7 @@ int invoke_subshell (const char *command
c148d92
 	init_subshell ();
c148d92
 
c148d92
     prompt_pos = 0;
c148d92
+    original_prompt_pos = 0;
c148d92
 
c148d92
     return quit;
d9f085b
 }
c148d92
@@ -576,6 +581,7 @@ int
c148d92
 read_subshell_prompt (void)
c148d92
 {
c148d92
     static int prompt_size = INITIAL_PROMPT_SIZE;
c148d92
+    static int original_prompt_size = INITIAL_PROMPT_SIZE;
c148d92
     int bytes = 0, i, rc = 0;
c148d92
     struct timeval timeleft = { 0, 0 };
c148d92
 
c148d92
@@ -586,7 +592,10 @@ read_subshell_prompt (void)
c148d92
     if (subshell_prompt == NULL) {	/* First time through */
c148d92
 	subshell_prompt = g_malloc (prompt_size);
c148d92
 	*subshell_prompt = '\0';
c148d92
+	original_subshell_prompt = g_malloc (original_prompt_size);
c148d92
+	*original_subshell_prompt = '\0';
c148d92
 	prompt_pos = 0;
c148d92
+	original_prompt_pos = 0;
c148d92
     }
c148d92
 
c148d92
     while (subshell_alive
c148d92
@@ -607,20 +616,27 @@ read_subshell_prompt (void)
c148d92
 
c148d92
 	/* Extract the prompt from the shell output */
c148d92
 
c148d92
-	for (i = 0; i < bytes; ++i)
c148d92
+	for (i = 0; i < bytes; ++i) {
c148d92
+	    if (!pty_buffer[i])
c148d92
+		continue;
c148d92
+
c148d92
+	    original_subshell_prompt[original_prompt_pos++] = pty_buffer[i];
c148d92
+	    if (original_prompt_pos == original_prompt_size)
c148d92
+		original_subshell_prompt =
c148d92
+		    g_realloc (original_subshell_prompt, original_prompt_size *= 2);
c148d92
+
c148d92
 	    if (pty_buffer[i] == '\n' || pty_buffer[i] == '\r') {
c148d92
 		prompt_pos = 0;
c148d92
 	    } else {
c148d92
-		if (!pty_buffer[i])
c148d92
-		    continue;
c148d92
-
c148d92
 		subshell_prompt[prompt_pos++] = pty_buffer[i];
c148d92
 		if (prompt_pos == prompt_size)
c148d92
 		    subshell_prompt =
c148d92
 			g_realloc (subshell_prompt, prompt_size *= 2);
c148d92
 	    }
c148d92
+	}
c148d92
 
c148d92
 	subshell_prompt[prompt_pos] = '\0';
c148d92
+	original_subshell_prompt[original_prompt_pos] = '\0';
c148d92
     }
c148d92
     if (rc == 0 && bytes == 0)
c148d92
 	return FALSE;
c148d92
@@ -743,6 +759,8 @@ subshell_name_quote (const char *s)
c148d92
 void
c148d92
 do_subshell_chdir (const char *directory, int do_update, int reset_prompt)
c148d92
 {
c148d92
+    static char *old_subshell_prompt = NULL;
c148d92
+
c148d92
     if (!
c148d92
 	(subshell_state == INACTIVE
c148d92
 	 && strcmp (subshell_cwd, current_panel->cwd))) {
c148d92
@@ -750,8 +768,14 @@ do_subshell_chdir (const char *directory
c148d92
 	 * the main program.  Please note that in the code after this
c148d92
 	 * if, the cd command that is sent will make the subshell
c148d92
 	 * repaint the prompt, so we don't have to paint it. */
c148d92
-	if (do_update)
c148d92
-	    do_update_prompt ();
c148d92
+	if (do_update) {
c148d92
+	    if (old_subshell_prompt == NULL
c148d92
+		|| strcmp (old_subshell_prompt, original_subshell_prompt)) {
c148d92
+		g_free (old_subshell_prompt);
c148d92
+		old_subshell_prompt = g_strdup (original_subshell_prompt);
c148d92
+		do_update_prompt ();
c148d92
+	    }
c148d92
+	}
c148d92
 	return;
c148d92
     }
c148d92
 
c148d92
@@ -802,8 +826,10 @@ do_subshell_chdir (const char *directory
c148d92
 	}
c148d92
     }
c148d92
 
c148d92
-    if (reset_prompt)
c148d92
+    if (reset_prompt) {
c148d92
 	prompt_pos = 0;
c148d92
+	original_prompt_pos = 0;
c148d92
+    }
c148d92
     update_prompt = FALSE;
c148d92
     /* Make sure that MC never stores the CWD in a silly format */
c148d92
     /* like /usr////lib/../bin, or the strcmp() above will fail */