Ticket #4171 (closed enhancement: fixed)

Opened 4 years ago

Last modified 4 years ago

[patch] Fix #silent macro runs

Reported by: psprint Owned by: andrew_b
Priority: major Milestone: 4.8.27
Component: mcedit Version: master
Keywords: subshell, background, commands, macros Cc:
Blocked By: Blocking:
Branch state: merged Votes for changeset: committed-master

Description

Hi,
mc has a functionality of skipping the subshell when running a macro script – by prepending the macro with a "#silent" line, e.g.:

#silent

m       make
        TMPFILE=`mktemp /tmp/make.XX` || exit 1
        make 2> $TMPFILE
        mcedit $TMPFILE
        #rm $TMPFILE

This will make the script to be run without the subshell use. However, it's fairly broken currently – the screen will be disrupted – \r and \n codes will not work properly and will not make the caret return to the first column. This is probably also broken also for a non #silent background command runs, however I don't have the opportunity to test it as my subshell support segfaults for some reason.

The patch fixes this problem. It restores the pre-slang/pre-curses terminal state and clears the terminal before running the command, then sets the after-slang/curses terminal configuration.

Attachments

0001-Fix-silent-macro-runs-make-the-terminal-undisrupted.patch (1.5 KB) - added by psprint 4 years ago.
0001-Fix-silent-macro-runs-make-the-terminal-undisrupted.2.patch (1.3 KB) - added by psprint 4 years ago.
0001-Fix-usermenu-and-macro-system-calls-disrupting-termi.patch (1.4 KB) - added by psprint 4 years ago.
The mccore-wide version of the patch.

Change History

comment:1 Changed 4 years ago by andrew_b

    /* Emit the clear screen escape code. */
    fputs("\x1b[0m\x1b[2J",stdout);

We have ESC_STR.
Why is this sequence used?
https://stackoverflow.com/questions/37774983/clearing-the-screen-by-printing-a-character

comment:2 Changed 4 years ago by psprint

I've removed the screen clearing as it looks even better without it. Thanks for info about ESC_STR.

comment:3 Changed 4 years ago by andrew_b

Perhaps, it should be made not for editor only.
Something like following:

  • src/usermenu.c

    diff --git a/src/usermenu.c b/src/usermenu.c
    index 1fecbeaac..8aecb1b8b 100644
    a b execute_menu_command (const WEdit * edit_widget, const char *commands, gboolean 
    559559 
    560560        if (show_prompt) 
    561561            shell_execute (cmd, EXECUTE_HIDE); 
    562         else if (system (cmd) == -1) 
    563             message (D_ERROR, MSG_ERROR, "%s", _("Error calling program")); 
     562        else 
     563        { 
     564            gboolean ok; 
     565 
     566            /* Prepare the terminal by setting its flag to the initial ones. This will cause \r to work as 
     567             * expected, instead of being ignored. */ 
     568            tty_reset_shell_mode(); 
     569 
     570            ok = (system (cmd) != -1); 
     571 
     572            /* Restore the SLang terminal configuration and redraw the editor. */ 
     573            tty_raw_mode(); 
     574 
     575            if (!ok) 
     576                message (D_ERROR, MSG_ERROR, "%s", _("Error calling program")); 
     577        } 
    564578 
    565579        g_free (cmd); 
    566580    } 

comment:4 Changed 4 years ago by psprint

Yes, and the patch almost works – it only needs a clr_scr(); repaint_screen() calls after the raw mode restoration, because otherwise the screen remains as the external command left it. I attach a tested patch.

Last edited 4 years ago by psprint (previous) (diff)

Changed 4 years ago by psprint

The mccore-wide version of the patch.

comment:5 Changed 4 years ago by andrew_b

  • Owner set to andrew_b
  • Status changed from new to accepted
  • Branch state changed from no branch to on review
  • Milestone changed from Future Releases to 4.8.27
Last edited 4 years ago by andrew_b (previous) (diff)

comment:6 Changed 4 years ago by andrew_b

  • Votes for changeset set to andrew_b
  • Branch state changed from on review to approved

comment:7 Changed 4 years ago by andrew_b

  • Status changed from accepted to testing
  • Votes for changeset changed from andrew_b to committed-master
  • Resolution set to fixed
  • Branch state changed from approved to merged

comment:8 Changed 4 years ago by andrew_b

  • Status changed from testing to closed
Note: See TracTickets for help on using tickets.