micro icon indicating copy to clipboard operation
micro copied to clipboard

RunTermEmulator function doesn't seem to respect the "wait" flag

Open dakennedyd opened this issue 1 year ago • 1 comments

When using the fzf plugin to open a file the plugin displays an annoying "Press enter to close" message before closing the internal terminal. The fzf plugin uses the "RunTermEmulator" function with the "wait" flag set to "false" which I assume it should make it close the internal terminal immediately but instead displays a message that says "Press enter to close" before closing.

Specifications

Version: 2.0.14-dev.131 Commit hash: acb0d763 Compiled on April 10, 2024 OS: Ubuntu 22.04 Terminal: xterm

dakennedyd avatar Apr 10 '24 05:04 dakennedyd

I can reproduce this. From micro's code I see that the Press enter to close message actually indicates that an error occurred. So this message seems misleading, and moreover, it doesn't tell us which error occurred.

I've instrumented the code so it says which error is it:

diff --git a/internal/shell/terminal.go b/internal/shell/terminal.go
index 6fb1ce7f..5712efbd 100644
--- a/internal/shell/terminal.go
+++ b/internal/shell/terminal.go
@@ -2,6 +2,7 @@ package shell
 
 import (
 	"bytes"
+	"fmt"
 	"os/exec"
 	"strconv"
 
@@ -97,7 +98,7 @@ func (t *Terminal) Start(execCmd []string, getOutput bool, wait bool, callback f
 		for {
 			err := Term.Parse()
 			if err != nil {
-				Term.Write([]byte("Press enter to close"))
+				Term.Write([]byte(fmt.Sprintf("Press enter to close: %v", err)))
 				screen.Redraw()
 				break
 			}

and I can see the error is:

Press enter to close: read /dev/ptmx: input/output error                                                                                                                                                           

RunTermEmulator() uses the https://github.com/zyedidia/terminal library, which opens /dev/ptmx using the https://github.com/creack/pty library, and reads characters from it. Apparently, when finishing running the fzf job, reading from /dev/ptmx fails with EIO for some reason.

We can try to debug it further.

Quick googling: https://www.google.com/search?q=%2Fdev%2Fptmx+eio

finds some possibly useful links:

  • https://github.com/creack/pty/issues/21#issuecomment-129381749
  • https://unix.stackexchange.com/questions/478815/read2-blocking-behaviour-changes-when-pts-is-closed-resulting-in-read-return

dmaluka avatar Apr 11 '24 16:04 dmaluka