How to identify the Terminal Emulator being used?

十年热恋 提交于 2021-01-28 04:42:12

问题


I'm developing a library that needs to identify the running terminal emulator in order to output emulator-specific escape code sequences.

For example, iTerm 2 uses the following proprietary sequence:

ESC ] 50 ; CurrentDir=/path/to/dir BEL

While ConEmu uses the following proprietary sequence:

ESC ]  9 ; 9 ; C:\path\to\dir BEL

Now, I need to query the terminal (either using environment variables or using an escape sequence) in order to output the correct terminal-specific codes.

How can I reliably detect and identify what terminal emulator that I'm running on?


回答1:


The answer depends...

Well, you may try to check environment variable, e.g. ConEmuServerPID. But that may be not reliable, because a) the variable may be somehow inherited from parent process when your process is running actually outside of ConEmu b) the variable may be not set in some cases, for example when you ssh somewhere

You may request terminal "version" with ESC [ > c reports ESC > 0 ; 136 ; 0 c. But of course, this 136 is not a guarantee of ConEmu.

Also, you may use ANSI sequence to execute IsConEmu GuiMacro. However, most likely you aren't able to check the result when ssh-ing.

You may call ConEmuC.exe -IsConEmu, but you can't do that in ssh.



来源:https://stackoverflow.com/questions/54747768/how-to-identify-the-terminal-emulator-being-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!