Ticket #4171 (closed enhancement: fixed)
[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
Change History
Changed 4 years ago by psprint
- Attachment 0001-Fix-silent-macro-runs-make-the-terminal-undisrupted.patch added
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
Changed 4 years ago by psprint
- Attachment 0001-Fix-silent-macro-runs-make-the-terminal-undisrupted.2.patch added
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 559 559 560 560 if (show_prompt) 561 561 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 } 564 578 565 579 g_free (cmd); 566 580 }
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.
Changed 4 years ago by psprint
- Attachment 0001-Fix-usermenu-and-macro-system-calls-disrupting-termi.patch added
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
Branch: 4171_silent_macro
changeset:8177cdd0f1668df703f92dfd47034ba9027e16e6
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
Merged to master: [c7306aae18ee3cc1a6ffa659e3ce247ec8744c62].