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

Detect iTerm2 and Terminal.app by DA2 (Secondary Device Attributes) #32

Merged
merged 3 commits into from
Jul 16, 2020

Conversation

yoichi
Copy link
Contributor

@yoichi yoichi commented Jul 15, 2020

I try to solve #27
But sometime it fails on iTerm2

スクリーンショット 2020-07-15 21 10 07

@yoichi
Copy link
Contributor Author

yoichi commented Jul 15, 2020

As far as I've tried, the failures seem to only occur on macOS.

with debug print:

diff --git a/main.go b/main.go
index 8da2fdf..9fe7452 100644
--- a/main.go
+++ b/main.go
@@ -197,6 +197,7 @@ func checkIterm() bool {
        if err != nil {
                return false
        }
+       fmt.Printf("checkIterm: %v", b[:n])
        return string(b[:n]) == "\x1b[>0;95;0c" // iTerm2 version 3
 }

@@ -217,6 +218,7 @@ func checkTerminalApp() bool {
        if err != nil {
                return false
        }
+       fmt.Printf("checkTerminalApp: %v", b[:n])
        return string(b[:n]) == "\x1b[>1;95;0c" // Terminal.app
 }

@@ -240,6 +242,7 @@ func checkSixel() bool {
        if err != nil {
                return false
        }
+       fmt.Printf("checkSixel: %v", b[:n])
        var supportedTerminals = []string{
                "\x1b[?62;", // VT240
                "\x1b[?63;", // wsltty

on macOS on ITerm2:
スクリーンショット 2020-07-16 7 02 58

on Linux (docker) on ubuntu, connected by ssh from macOS iTerm2:
スクリーンショット 2020-07-16 7 04 51

@yoichi
Copy link
Contributor Author

yoichi commented Jul 16, 2020

I've reproduced the problem on Linux (ubuntu 18.04) too.
There seems to be some problem regardless of the execution environment...

* Undo previous change since the failure is platform independent
* Use TERM_PROGRAM if it is set
* Wait 10ms before read terminal response
@yoichi yoichi marked this pull request as ready for review July 16, 2020 10:39
@yoichi
Copy link
Contributor Author

yoichi commented Jul 16, 2020

I think the cause of failure is that the read operation is invoked before the terminal response is written.
I couldn't find a good way to deal with it, so I decided to put a sleep.

I've confirmed the problem is not reproduced on my environments:

  • macOS and Terminal.app with "unset TERM_PROGRAM"
  • macOS and iTerm2 with "unset TERM_PROGRAM"

@mattn mattn merged commit d84b69a into mattn:master Jul 16, 2020
@mattn
Copy link
Owner

mattn commented Jul 16, 2020

Thank you!

@yoichi yoichi deleted the detect-terminal-by-da2 branch July 17, 2020 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants