简体   繁体   English

256色终端的单声道控制台应用程序

[英]Mono console app in 256 color terminal

Do mono apps support 256 color terminals? 单声道应用程序是否支持256色终端?

my program is giving very strange output in a 256 color environment. 我的程序在256色环境中提供非常奇怪的输出。

Should I just check the $TERM value and disable colour entirely if its 256 color? 如果它的256色,我应该检查$ TERM值并完全禁用颜色吗?

My output looks like this: 我的输出如下:

1%{8}%<%t37%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;7%;m1%{8}%<%t31%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;1%;mYou have not registered
1%{8}%<%t37%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;7%;m1%{8}%<%t31%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;1%;mMOTD File is missing
1%{8}%<%t37%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;7%;m1%{8}%<%t30%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;0%;mThetis joined #sanctuary.
1%{8}%<%t37%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;7%;m1%{8}%<%t36%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;6%;mPlugin - Factoids - Saved.
1%{8}%<%t37%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;7%;m1%{8}%<%t36%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;6%;mPlugin - Factoids - Saved.
1%{8}%<%t37%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;7%;m1%{8}%<%t30%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;0%;mChanMess 77 and still going...
1%{8}%<%t37%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;7%;m1%{8}%<%t36%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;6%;mPlugin - Factoids - Saved.
1%{8}%<%t37%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;7%;m1%{8}%<%t36%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;6%;mPlugin - Factoids - Saved.

Obviously a very late reaction, but I had this problem as well, and, while searching for it, the only relevant result that turned up was this question. 显然是一个非常晚的反应,但我也有这个问题,并且,在搜索它时,出现的唯一相关结果就是这个问题。

I eventually figured it out on my own - Turns out the $TERM environment variable wasn't set correctly. 我最终自己想出来了 - 结果证明$TERM环境变量设置不正确。 In my case, it was set to xterm-256color . 就我而言,它被设置为xterm-256color Mono apparently doesn't like that. Mono显然不喜欢这样。

Setting it to xterm will fix the issue. 将其设置为xterm将解决问题。

Reading the source code TermInfoDriver.cs shows that Mono first attempts to find $TERM in the terminfo database, and failing that is hardcoded to accept "xterm" or "linux". 读取源代码TermInfoDriver.cs表明Mono首先尝试在terminfo数据库中找到$ TERM,并且失败的是硬编码接受“xterm”或“linux”。 A failure would occur if $TERM was not found in the terminfo database -- or if Mono is incorrectly configured to find the terminfo database. 如果在terminfo数据库中找不到$ TERM,或者如果未正确配置Mono以查找terminfo数据库,则会发生故障。 To check the former, use "infocmp" to show the terminal entry. 要检查前者,请使用“infocmp”显示终端条目。

"Standard linux terminals" would be the Linux console, and that does not match either "xterm" or "vt220" (which differ) well enough to be usable. “标准linux终端”将是Linux控制台,并且它与“xterm”或“vt220”(不同)不匹配,足以使用。 Again, use infocmp to see, eg, infocmp linux xterm , infocmp linux vt220 再次,使用infocmp来查看,例如, infocmp linux xterminfocmp linux vt220

Back to the original question: the odd text which was printed came out of the terminfo database. 回到原来的问题:打印出来的奇数文本来自terminfo数据库。 Applications which are written to use the database usually use the terminfo functions to interpret the data and prepare it for output to the terminal. 编写为使用数据库的应用程序通常使用terminfo函数来解释数据并准备输出到终端。 Mono has its own interpreter for terminfo strings (which may work correctly), and I recall some comment that it also has its own terminal emulator (to display). Mono有自己的terminfo字符串解释器(可能正常工作),我记得有一些评论说它也有自己的终端模拟器(显示)。 It is not unusual for these programs to do odd things with strings which they do not expect to handle, including printing error messages. 这些程序用他们不希望处理的字符串做奇怪的事情并不罕见,包括打印错误消息。 A "real" hardware terminal would generally simply ignore unexpected input. “真正的”硬件终端通常会忽略意外输入。

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

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