mirror of
https://github.com/MidnightCommander/mc
synced 2025-02-02 00:16:04 +03:00
Ticket #3001: fix read and update of subshell prompt.
The bug was introduced in e35f044ccdd41922f925c99e6d50930ea8c7c47e. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
61d230e494
commit
f6684c638d
@ -8,7 +8,7 @@
|
||||
Written by:
|
||||
Janne Kukonlehto, 1995
|
||||
Miguel de Icaza, 1995
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2011, 2012
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2011, 2012, 2013
|
||||
Slava Zanko <slavazanko@gmail.com>, 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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user