- fix displaying of prompt in subshell (#244025)

This commit is contained in:
Jindrich Novy 2007-06-20 14:39:18 +00:00
parent 78bc1349aa
commit c148d92eee
2 changed files with 148 additions and 15 deletions

View File

@ -1,21 +1,151 @@
--- mc-2007-06-04-22/src/main.c.prompt 2007-06-12 15:23:25.000000000 +0200 --- mc-2007-06-04-22/src/execute.c.prompt 2005-09-28 23:28:06.000000000 +0200
+++ mc-2007-06-04-22/src/main.c 2007-06-12 15:45:08.000000000 +0200 +++ mc-2007-06-04-22/src/execute.c 2007-06-20 14:07:17.000000000 +0200
@@ -453,9 +453,16 @@ do_possible_cd (const char *new_dir) @@ -140,6 +140,8 @@ do_execute (const char *shell, const cha
void printf ("\r\n");
fflush (stdout);
}
+ update_prompt = TRUE;
+ do_update_prompt ();
if (console_flag) {
if (output_lines && keybar_visible) {
putchar ('\n');
--- mc-2007-06-04-22/src/main.c.prompt 2007-06-20 14:07:17.000000000 +0200
+++ mc-2007-06-04-22/src/main.c 2007-06-20 14:07:17.000000000 +0200
@@ -454,7 +454,7 @@ void
do_update_prompt (void) do_update_prompt (void)
{
if (update_prompt) {
- printf ("%s", subshell_prompt);
+ printf ("\r\n%s", original_subshell_prompt);
fflush (stdout);
update_prompt = 0;
}
--- mc-2007-06-04-22/src/subshell.h.prompt 2004-12-03 20:17:47.000000000 +0100
+++ mc-2007-06-04-22/src/subshell.h 2007-06-20 14:07:17.000000000 +0200
@@ -20,6 +20,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};
--- mc-2007-06-04-22/src/subshell.c.prompt 2007-06-20 14:07:17.000000000 +0200
+++ mc-2007-06-04-22/src/subshell.c 2007-06-20 14:24:14.000000000 +0200
@@ -107,6 +107,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
@@ -148,6 +151,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;
/*
@@ -567,6 +571,7 @@ int invoke_subshell (const char *command
init_subshell ();
prompt_pos = 0;
+ original_prompt_pos = 0;
return quit;
}
@@ -576,6 +581,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 };
@@ -586,7 +592,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
@@ -607,20 +616,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;
@@ -743,6 +759,8 @@ subshell_name_quote (const char *s)
void
do_subshell_chdir (const char *directory, int do_update, int reset_prompt)
{ {
+ static char *old_subshell_prompt = NULL; + static char *old_subshell_prompt = NULL;
+ +
if (update_prompt) { if (!
- printf ("%s", subshell_prompt); (subshell_state == INACTIVE
- fflush (stdout); && strcmp (subshell_cwd, current_panel->cwd))) {
@@ -750,8 +768,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 + if (old_subshell_prompt == NULL
+ || strcmp (old_subshell_prompt, subshell_prompt)) { + || strcmp (old_subshell_prompt, original_subshell_prompt)) {
+ g_free (old_subshell_prompt); + g_free (old_subshell_prompt);
+ old_subshell_prompt = g_strdup (subshell_prompt); + old_subshell_prompt = g_strdup (original_subshell_prompt);
+ printf ("\r\n%s", subshell_prompt); + do_update_prompt ();
+ fflush (stdout);
+ } + }
update_prompt = 0; + }
return;
}
@@ -802,8 +826,10 @@ do_subshell_chdir (const char *directory
} }
} }
- if (reset_prompt)
+ if (reset_prompt) {
prompt_pos = 0;
+ original_prompt_pos = 0;
+ }
update_prompt = FALSE;
/* Make sure that MC never stores the CWD in a silly format */
/* like /usr////lib/../bin, or the strcmp() above will fail */

View File

@ -3,7 +3,7 @@
Summary: User-friendly text console file manager and visual shell Summary: User-friendly text console file manager and visual shell
Name: mc Name: mc
Version: 4.6.1a Version: 4.6.1a
Release: 47.20070604cvs%{?dist} Release: 48.20070604cvs%{?dist}
Epoch: 1 Epoch: 1
License: GPL License: GPL
Group: System Environment/Shells Group: System Environment/Shells
@ -196,6 +196,9 @@ rm -rf $RPM_BUILD_ROOT
%dir %{_libexecdir}/mc %dir %{_libexecdir}/mc
%changelog %changelog
* Wed Jun 20 2007 Jindrich Novy <jnovy@redhat.com> 4.6.1a-48
- fix displaying of prompt in subshell (#244025)
* Tue Jun 19 2007 Jindrich Novy <jnovy@redhat.com> 4.6.1a-47 * Tue Jun 19 2007 Jindrich Novy <jnovy@redhat.com> 4.6.1a-47
- refresh contents of terminal when resized during time - refresh contents of terminal when resized during time
expensive I/O operations (#236502) expensive I/O operations (#236502)