Skip to content

Commit be8f04b

Browse files
Jakub Horkýgithub-actions[bot]
authored andcommitted
Ticket #4815: Fix no colored prompt after switching panels off for the first time
Fix the issue by strictly distinguishing between mc_prompt, which should be stripped using strip_ctrl_codes(), and subshell_prompt, which should always hold the original, non-stripped PS1. Make mc_prompt heap-based. Signed-off-by: Jakub Horký <[email protected]>
1 parent c7ea82f commit be8f04b

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

src/filemanager/filemanager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ WLabel *the_hint;
109109
WButtonBar *the_bar;
110110

111111
/* The prompt */
112-
const char *mc_prompt = NULL;
112+
char *mc_prompt = NULL;
113113

114114
/*** file scope macro definitions ****************************************************************/
115115

src/filemanager/filemanager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extern WPanel *left_panel;
3535
extern WPanel *right_panel;
3636
extern WPanel *current_panel;
3737

38-
extern const char *mc_prompt;
38+
extern char *mc_prompt;
3939

4040
/*** declarations of public functions ************************************************************/
4141

src/filemanager/layout.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,6 @@ setup_cmdline (void)
974974
const WRect *r = &mw->rect;
975975
int prompt_width;
976976
int y;
977-
char *tmp_prompt = (char *) mc_prompt;
978977

979978
if (!command_prompt)
980979
return;
@@ -984,32 +983,26 @@ setup_cmdline (void)
984983
{
985984
// Workaround: avoid crash on FreeBSD (see ticket #4213 for details)
986985
if (subshell_prompt != NULL)
987-
tmp_prompt = g_string_free (subshell_prompt, FALSE);
988-
else
989-
tmp_prompt = g_strdup (mc_prompt);
990-
(void) strip_ctrl_codes (tmp_prompt);
986+
{
987+
g_free (mc_prompt);
988+
mc_prompt = g_strndup (subshell_prompt->str, subshell_prompt->len);
989+
}
990+
991+
(void) strip_ctrl_codes (mc_prompt);
991992
}
992993
#endif
993994

994-
prompt_width = str_term_width1 (tmp_prompt);
995+
prompt_width = str_term_width1 (mc_prompt);
995996

996997
// Check for prompts too big
997998
if (r->cols > 8 && prompt_width > r->cols - 8)
998999
{
9991000
int prompt_len;
10001001

10011002
prompt_width = r->cols - 8;
1002-
prompt_len = str_offset_to_pos (tmp_prompt, prompt_width);
1003-
tmp_prompt[prompt_len] = '\0';
1004-
}
1005-
1006-
#ifdef ENABLE_SUBSHELL
1007-
if (mc_global.tty.use_subshell)
1008-
{
1009-
subshell_prompt = g_string_new_take (tmp_prompt);
1010-
mc_prompt = subshell_prompt->str;
1003+
prompt_len = str_offset_to_pos (mc_prompt, prompt_width);
1004+
mc_prompt[prompt_len] = '\0';
10111005
}
1012-
#endif
10131006

10141007
y = r->lines - 1 - (mc_global.keybar_visible ? 1 : 0);
10151008

src/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ main (int argc, char *argv[])
419419
enable_bracketed_paste ();
420420

421421
// subshell_prompt is NULL here
422-
mc_prompt = (geteuid () == 0) ? "# " : "$ ";
422+
mc_prompt = g_strdup ((geteuid () == 0) ? "# " : "$ ");
423423
}
424424

425425
// Program main loop
@@ -428,6 +428,8 @@ main (int argc, char *argv[])
428428
else
429429
exit_code = do_nc () ? EXIT_SUCCESS : EXIT_FAILURE;
430430

431+
g_free (mc_prompt);
432+
431433
disable_bracketed_paste ();
432434

433435
disable_mouse ();

0 commit comments

Comments
 (0)