From f6684c638d19e22fb6710794148634daccadc888 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 10 Apr 2013 16:30:42 +0400 Subject: [PATCH] Ticket #3001: fix read and update of subshell prompt. The bug was introduced in e35f044ccdd41922f925c99e6d50930ea8c7c47e. Signed-off-by: Andrew Borodin --- src/filemanager/layout.c | 21 +++++++++++++++------ src/subshell.c | 17 ++++++++++++++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c index 4a8d122cc..1d067dd66 100644 --- a/src/filemanager/layout.c +++ b/src/filemanager/layout.c @@ -8,7 +8,7 @@ Written by: Janne Kukonlehto, 1995 Miguel de Icaza, 1995 - Andrew Borodin , 2011, 2012 + Andrew Borodin , 2011, 2012, 2013 Slava Zanko , 2013 This file is part of the Midnight Commander. @@ -813,14 +813,16 @@ setup_cmdline (void) { int prompt_len; int y; - char *tmp_prompt = NULL; + char *tmp_prompt = (char *) mc_prompt; #ifdef ENABLE_SUBSHELL if (mc_global.tty.use_subshell) - tmp_prompt = strip_ctrl_codes (subshell_prompt->str); - if (tmp_prompt == NULL) + { + tmp_prompt = g_string_free (subshell_prompt, FALSE); + (void) strip_ctrl_codes (tmp_prompt); + } #endif - tmp_prompt = (char *) mc_prompt; + prompt_len = str_term_width1 (tmp_prompt); /* Check for prompts too big */ @@ -830,7 +832,14 @@ setup_cmdline (void) tmp_prompt[prompt_len] = '\0'; } - mc_prompt = tmp_prompt; +#ifdef ENABLE_SUBSHELL + if (mc_global.tty.use_subshell) + { + subshell_prompt = g_string_new (tmp_prompt); + g_free (tmp_prompt); + mc_prompt = subshell_prompt->str; + } +#endif y = LINES - 1 - mc_global.keybar_visible; diff --git a/src/subshell.c b/src/subshell.c index d2c3bc278..dfbc6bb55 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -985,6 +985,8 @@ read_subshell_prompt (void) int rc = 0; ssize_t bytes = 0; struct timeval timeleft = { 0, 0 }; + GString *p; + gboolean prompt_was_reset = FALSE; fd_set tmp; FD_ZERO (&tmp); @@ -994,6 +996,8 @@ read_subshell_prompt (void) if (subshell_prompt == NULL) subshell_prompt = g_string_sized_new (INITIAL_PROMPT_SIZE); + p = g_string_sized_new (INITIAL_PROMPT_SIZE); + while (subshell_alive && (rc = select (mc_global.tty.subshell_pty + 1, &tmp, NULL, NULL, &timeleft)) != 0) { @@ -1017,14 +1021,21 @@ read_subshell_prompt (void) bytes = read (mc_global.tty.subshell_pty, pty_buffer, sizeof (pty_buffer)); /* Extract the prompt from the shell output */ - g_string_set_size (subshell_prompt, 0); for (i = 0; i < bytes; i++) if (pty_buffer[i] == '\n' || pty_buffer[i] == '\r') - g_string_set_size (subshell_prompt, 0); + { + g_string_set_size (p, 0); + prompt_was_reset = TRUE; + } else if (pty_buffer[i] != '\0') - g_string_append_c (subshell_prompt, pty_buffer[i]); + g_string_append_c (p, pty_buffer[i]); } + if (p->len != 0 || prompt_was_reset) + g_string_assign (subshell_prompt, p->str); + + g_string_free (p, TRUE); + return (rc != 0 || bytes != 0); } -- 2.11.4.GIT