Ticket #4171 (new enhancement)

Opened 4 days ago

Last modified 3 days ago

[patch] Fix #silent macro runs

Reported by: psprint Owned by:
Priority: major Milestone: Future Releases
Component: mcedit Version: master
Keywords: subshell, background, commands, macros Cc:
Blocked By: Blocking:
Branch state: no branch Votes for changeset:

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 days ago.
0001-Fix-silent-macro-runs-make-the-terminal-undisrupted.2.patch (1.3 KB) - added by psprint 3 days ago.
0001-Fix-usermenu-and-macro-system-calls-disrupting-termi.patch (1.4 KB) - added by psprint 3 days ago.
The mccore-wide version of the patch.

Change History

comment:1 Changed 4 days 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 3 days 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 3 days 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 3 days 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 3 days ago by psprint (previous) (diff)

Changed 3 days ago by psprint

The mccore-wide version of the patch.

Note: See TracTickets for help on using tickets.