Ticket #4126: 0007-disable-subshell-cursor-position-translation-for-bas.patch

File 0007-disable-subshell-cursor-position-translation-for-bas.patch, 3.0 KB (added by ossi, 22 months ago)
  • src/subshell/common.c

    From b43a14c5aa861b51ff1f24efa148e2689d9e4799 Mon Sep 17 00:00:00 2001
    From: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
    Date: Thu, 8 Oct 2020 20:30:47 +0200
    Subject: [PATCH 7/7] disable subshell cursor position translation for bash v5+
    
    the changelog clearly states that the position is now returned as a
    character offset.
    
    amends ff0fc17a.
    ---
     src/subshell/common.c | 22 +++++++++++++++-------
     1 file changed, 15 insertions(+), 7 deletions(-)
    
    diff --git a/src/subshell/common.c b/src/subshell/common.c
    index b9e04e8ea..0f54ec42a 100644
    a b read_command_line_buffer (gboolean test_mode) 
    518518    struct timeval subshell_prompt_timer = { 0, 0 }; 
    519519    int command_buffer_length; 
    520520    int command_buffer_char_length; 
     521    int bash_version; 
    521522    int cursor_position; 
    522523    int maxfdp; 
    523524    int rc; 
    524     char *end; 
    525525 
    526526    if (!use_persistent_buffer) 
    527527        return TRUE; 
    read_command_line_buffer (gboolean test_mode) 
    612612        return FALSE; 
    613613 
    614614    subshell_cursor_buffer[bytes - 1] = '\0'; 
    615     cursor_position = strtol (subshell_cursor_buffer, &end, 10); 
    616     if (end == subshell_cursor_buffer) 
    617         return FALSE; 
     615    if (mc_global.shell->type == SHELL_BASH) 
     616    { 
     617        if (sscanf (subshell_cursor_buffer, "%d:%d", &bash_version, &cursor_position) != 2) 
     618            return FALSE; 
     619    } 
     620    else 
     621    { 
     622        if (sscanf (subshell_cursor_buffer, "%d", &cursor_position) != 1) 
     623            return FALSE; 
     624        bash_version = 1000; 
     625    } 
    618626 
    619627    if (test_mode) 
    620628        return TRUE; 
    read_command_line_buffer (gboolean test_mode) 
    629637    input_assign_text (cmdline, ""); 
    630638    input_insert (cmdline, subshell_command_buffer, FALSE); 
    631639 
    632     if (mc_global.shell->type == SHELL_BASH) 
     640    if (bash_version < 5)  /* implies SHELL_BASH */ 
    633641    { 
    634         /* We need to do this because bash gives the cursor position in a utf-8 string based 
     642        /* We need to do this because bash < v5 gives the cursor position in a utf-8 string based 
    635643         * on the location in bytes, not in unicode characters. */ 
    636644        char *curr = subshell_command_buffer; 
    637645        char *stop = curr + cursor_position; 
    init_subshell_precmd (char *precmd, size_t buff_size) 
    10561064        g_snprintf (precmd, buff_size, 
    10571065                    " mc_print_command_buffer () { printf \"%%s\\\\n\" \"$READLINE_LINE\" >&%d; }\n" 
    10581066                    " bind -x '\"\\e" SHELL_BUFFER_KEYBINDING "\":\"mc_print_command_buffer\"'\n" 
    1059                     " bind -x '\"\\e" SHELL_CURSOR_KEYBINDING "\":\"echo $READLINE_POINT>&%d\"'\n" 
     1067                    " bind -x '\"\\e" SHELL_CURSOR_KEYBINDING "\":\"echo $BASH_VERSINFO:$READLINE_POINT >&%d\"'\n" 
    10601068                    " PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND\n}'pwd>&%d;kill -STOP $$'\n" 
    10611069                    "PS1='\\u@\\h:\\w\\$ '\n", 
    10621070                    command_buffer_pipe[WRITE], command_buffer_pipe[WRITE], subshell_pipe[WRITE]);