Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[patch] Fix #silent macro runs #4171

Closed
mc-butler opened this issue Jan 11, 2021 · 11 comments
Closed

[patch] Fix #silent macro runs #4171

mc-butler opened this issue Jan 11, 2021 · 11 comments
Assignees
Labels
area: mcedit mcedit, the built-in text editor prio: medium Has the potential to affect progress
Milestone

Comments

@mc-butler
Copy link

Important

This issue was migrated from Trac:

Origin https://midnight-commander.org/ticket/4171
Reporter psprint (sg44567@….com)
Keywords subshell, background, commands, macros

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.

Note

Original attachments:

@mc-butler
Copy link
Author

Changed by psprint (sg44567@….com) on Jan 11, 2021 at 7:09 UTC

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Jan 11, 2021 at 14:08 UTC (comment 1)

    /* 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

@mc-butler
Copy link
Author

Changed by psprint (sg44567@….com) on Jan 12, 2021 at 6:15 UTC

@mc-butler
Copy link
Author

Changed by psprint (sg44567@….com) on Jan 12, 2021 at 6:16 UTC (comment 2)

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

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Jan 12, 2021 at 9:54 UTC (comment 3)

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

      <li class="entry">
        <h2>
          <a>src/usermenu.c</a>
          
        </h2>
        <pre>diff --git a/src/usermenu.c b/src/usermenu.c
    

    index 1fecbeaac..8aecb1b8b 100644

        <table class="trac-diff inline" summary="Differences" cellspacing="0">
          
            
            
              <colgroup><col class="lineno" /><col class="lineno" /><col class="content" /></colgroup>
              <thead>
                <tr>
                  <th title="File a/src/usermenu.c">
                    
                      a
                  </th>
                  <th title="File b/src/usermenu.c">
                    
                      b
                  </th>
                  <td><em> execute_menu_command (const WEdit * edit_widget, const char *commands, gboolean</em> </td>
                </tr>
              </thead>
            
          
          
            <tbody class="unmod">
              
    
                 
                  <tr>
                      
                      
                        
                        
                          <th>559</th><th>559</th><td class="l"><span></span> </td>
                        
                      
                    
                  </tr><tr>
                      
                      
                        
                        
                          <th>560</th><th>560</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; if (show_prompt)</span> </td>
                        
                      
                    
                  </tr><tr>
                      
                      
                        
                        
                          <th>561</th><th>561</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shell_execute (cmd, EXECUTE_HIDE);</span> </td>
                        
                      
                    
                  </tr>
                
    
                
    
                
    
                
    
              
            </tbody><tbody class="mod">
              
    
                
    
                
    
                
    
                 
                  
                    
                    
                      
                      <tr class="first">
                        <th>562</th><th> </th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; else if (system (cmd) == -1)</span> </td>
                      </tr><tr>
                        <th>563</th><th> </th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message (D_ERROR, MSG_ERROR, "%s", _("Error calling program"));</span> </td>
                      </tr>
                      
                      <tr>
                        <th> </th><th>562</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; else</span> </td>
                      </tr><tr>
                        <th> </th><th>563</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; {</span> </td>
                      </tr><tr>
                        <th> </th><th>564</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gboolean ok;</span> </td>
                      </tr><tr>
                        <th> </th><th>565</th><td class="r"><span></span> </td>
                      </tr><tr>
                        <th> </th><th>566</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* Prepare the terminal by setting its flag to the initial ones. This will cause \r to work as</span> </td>
                      </tr><tr>
                        <th> </th><th>567</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* expected, instead of being ignored. */</span> </td>
                      </tr><tr>
                        <th> </th><th>568</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tty_reset_shell_mode();</span> </td>
                      </tr><tr>
                        <th> </th><th>569</th><td class="r"><span></span> </td>
                      </tr><tr>
                        <th> </th><th>570</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ok = (system (cmd) != -1);</span> </td>
                      </tr><tr>
                        <th> </th><th>571</th><td class="r"><span></span> </td>
                      </tr><tr>
                        <th> </th><th>572</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* Restore the SLang terminal configuration and redraw the editor. */</span> </td>
                      </tr><tr>
                        <th> </th><th>573</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tty_raw_mode();</span> </td>
                      </tr><tr>
                        <th> </th><th>574</th><td class="r"><span></span> </td>
                      </tr><tr>
                        <th> </th><th>575</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!ok)</span> </td>
                      </tr><tr>
                        <th> </th><th>576</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message (D_ERROR, MSG_ERROR, "%s", _("Error calling program"));</span> </td>
                      </tr><tr class="last">
                        <th> </th><th>577</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; }</span> </td>
                      </tr>
                    
                  
                
    
              
            </tbody><tbody class="unmod">
              
    
                 
                  <tr>
                      
                      
                        
                        
                          <th>564</th><th>578</th><td class="l"><span></span> </td>
                        
                      
                    
                  </tr><tr>
                      
                      
                        
                        
                          <th>565</th><th>579</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; g_free (cmd);</span> </td>
                        
                      
                    
                  </tr><tr>
                      
                      
                        
                        
                          <th>566</th><th>580</th><td class="l"><span>&nbsp; &nbsp; }</span> </td>
                        
                      
                    
                  </tr>
                
    
                
    
                
    
                
    
              
            </tbody>
            
          
        </table>
      </li>
    

@mc-butler
Copy link
Author

Changed by psprint (sg44567@….com) on Jan 12, 2021 at 12:39 UTC (comment 4)

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.

@mc-butler
Copy link
Author

Changed by psprint (sg44567@….com) on Jan 12, 2021 at 12:40 UTC

The mccore-wide version of the patch.

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Jan 26, 2021 at 10:45 UTC (comment 5)

  • Milestone changed from Future Releases to 4.8.27
  • Owner set to andrew_b
  • Status changed from new to accepted
  • Branch state changed from no branch to on review

Branch: 4171_silent_macro
[8177cdd]

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Jan 31, 2021 at 16:28 UTC (comment 6)

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

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Jan 31, 2021 at 16:30 UTC (comment 7)

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

Merged to master: [c7306aa].

@mc-butler
Copy link
Author

Changed by andrew_b (@aborodin) on Jan 31, 2021 at 16:34 UTC (comment 8)

  • Status changed from testing to closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: mcedit mcedit, the built-in text editor prio: medium Has the potential to affect progress
Development

No branches or pull requests

2 participants