简体   繁体   English

如何识别正在使用的终端仿真器?

[英]How to identify the Terminal Emulator being used?

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: 例如, iTerm 2 使用以下专有序列:

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

While ConEmu uses the following proprietary sequence: 虽然ConEmu 使用以下专有序列:

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? 如何可靠地检测和识别正在运行的终端模拟器?

The answer depends... 答案取决于...

Well, you may try to check environment variable, eg ConEmuServerPID . 好吧,您可以尝试检查环境变量,例如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 但这可能是不可靠的,因为a)当您的进程实际上在ConEmu之外运行时,该变量可能以某种方式从父进程继承了b)在某些情况下,例如当您在某处ssh时,可能未设置该变量

You may request terminal "version" with ESC [ > c reports ESC > 0 ; 136 ; 0 c 您可以使用ESC [ > c报告ESC > 0 ; 136 ; 0 c来请求终端“版本” ESC > 0 ; 136 ; 0 c ESC > 0 ; 136 ; 0 c ESC > 0 ; 136 ; 0 c . ESC > 0 ; 136 ; 0 c But of course, this 136 is not a guarantee of ConEmu. 但是,当然,这136不是ConEmu的保证。

Also, you may use ANSI sequence to execute IsConEmu GuiMacro . 另外,您可以使用ANSI序列执行IsConEmu GuiMacro However, most likely you aren't able to check the result when ssh-ing. 但是,很可能在ssh-ing时无法检查结果。

You may call ConEmuC.exe -IsConEmu , but you can't do that in ssh. 您可以调用ConEmuC.exe -IsConEmu ,但不能在ssh中执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM