Blob Blame History Raw
diff -up mc-4.6.99/src/execute.c.prompt mc-4.6.99/src/execute.c
--- mc-4.6.99/src/execute.c.prompt	2009-07-31 14:57:10.000000000 +0200
+++ mc-4.6.99/src/execute.c	2009-07-31 14:58:21.000000000 +0200
@@ -146,6 +146,8 @@ do_execute (const char *shell, const cha
 	    printf ("\r\n");
 	    fflush (stdout);
 	}
+	update_prompt = TRUE;
+	do_update_prompt ();
 	if (console_flag) {
 	    if (output_lines && keybar_visible) {
 		putchar ('\n');
diff -up mc-4.6.99/src/main.c.prompt mc-4.6.99/src/main.c
--- mc-4.6.99/src/main.c.prompt	2009-07-31 14:57:10.000000000 +0200
+++ mc-4.6.99/src/main.c	2009-07-31 14:58:21.000000000 +0200
@@ -459,7 +459,7 @@ void
 do_update_prompt (void)
 {
     if (update_prompt) {
-	printf ("%s", subshell_prompt);
+	printf ("\r\n%s", original_subshell_prompt);
 	fflush (stdout);
 	update_prompt = 0;
     }
diff -up mc-4.6.99/src/subshell.c.prompt mc-4.6.99/src/subshell.c
--- mc-4.6.99/src/subshell.c.prompt	2009-07-31 14:57:11.000000000 +0200
+++ mc-4.6.99/src/subshell.c	2009-07-31 15:02:35.000000000 +0200
@@ -114,6 +114,9 @@ enum subshell_state_enum subshell_state;
 /* Holds the latest prompt captured from the subshell */
 char *subshell_prompt = NULL;
 
+/* Holds the latest prompt captured from the subshell with terminal codes */
+char *original_subshell_prompt = NULL;
+
 /* Initial length of the buffer for the subshell's prompt */
 #define INITIAL_PROMPT_SIZE 10
 
@@ -160,6 +163,7 @@ static struct termios raw_mode;
 /* This counter indicates how many characters of prompt we have read */
 /* FIXME: try to figure out why this had to become global */
 static int prompt_pos;
+static int original_prompt_pos;
 
 
 /*
@@ -598,6 +602,7 @@ int invoke_subshell (const char *command
 	init_subshell ();
 
     prompt_pos = 0;
+    original_prompt_pos = 0;
 
     return quit;
 }
@@ -607,6 +612,7 @@ int
 read_subshell_prompt (void)
 {
     static int prompt_size = INITIAL_PROMPT_SIZE;
+    static int original_prompt_size = INITIAL_PROMPT_SIZE;
     int bytes = 0, i, rc = 0;
     struct timeval timeleft = { 0, 0 };
 
@@ -617,7 +623,10 @@ read_subshell_prompt (void)
     if (subshell_prompt == NULL) {	/* First time through */
 	subshell_prompt = g_malloc (prompt_size);
 	*subshell_prompt = '\0';
+	original_subshell_prompt = g_malloc (original_prompt_size);
+	*original_subshell_prompt = '\0';
 	prompt_pos = 0;
+	original_prompt_pos = 0;
     }
 
     while (subshell_alive
@@ -638,20 +647,27 @@ read_subshell_prompt (void)
 
 	/* Extract the prompt from the shell output */
 
-	for (i = 0; i < bytes; ++i)
+	for (i = 0; i < bytes; ++i) {
+	    if (!pty_buffer[i])
+		continue;
+
+	    original_subshell_prompt[original_prompt_pos++] = pty_buffer[i];
+	    if (original_prompt_pos == original_prompt_size)
+		original_subshell_prompt =
+		    g_realloc (original_subshell_prompt, original_prompt_size *= 2);
+
 	    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);
 	    }
+	}
 
 	subshell_prompt[prompt_pos] = '\0';
+	original_subshell_prompt[original_prompt_pos] = '\0';
     }
     if (rc == 0 && bytes == 0)
 	return FALSE;
@@ -792,6 +808,7 @@ do_subshell_chdir (const char *directory
     char *pcwd;
     char *temp;
     char *translate;
+    static char *old_subshell_prompt = NULL;
     
     pcwd = vfs_translate_path_n (current_panel->cwd);
     
@@ -802,8 +819,14 @@ do_subshell_chdir (const char *directory
 	 * the main program.  Please note that in the code after this
 	 * if, the cd command that is sent will make the subshell
 	 * repaint the prompt, so we don't have to paint it. */
-	if (do_update)
-	    do_update_prompt ();
+	if (do_update) {
+	    if (old_subshell_prompt == NULL
+		|| strcmp (old_subshell_prompt, original_subshell_prompt)) {
+		    g_free (old_subshell_prompt);
+		    old_subshell_prompt = g_strdup (original_subshell_prompt);
+		    do_update_prompt ();
+	    }
+	}
         g_free (pcwd);
 	return;
     }
@@ -861,8 +884,10 @@ do_subshell_chdir (const char *directory
 	}
     }
 
-    if (reset_prompt)
+    if (reset_prompt) {
 	prompt_pos = 0;
+	original_prompt_pos = 0;
+    }
     update_prompt = FALSE;
     
     g_free (pcwd);
diff -up mc-4.6.99/src/subshell.h.prompt mc-4.6.99/src/subshell.h
--- mc-4.6.99/src/subshell.h.prompt	2009-07-31 14:57:10.000000000 +0200
+++ mc-4.6.99/src/subshell.h	2009-07-31 14:58:21.000000000 +0200
@@ -25,6 +25,9 @@ extern enum subshell_state_enum subshell
 /* Holds the latest prompt captured from the subshell */
 extern char *subshell_prompt;
 
+/* Holds the latest prompt captured from the subshell with terminal codes */
+extern char *original_subshell_prompt;
+
 /* For the `how' argument to various functions */
 enum {QUIETLY, VISIBLY};