简体   繁体   中英

Mono console app in 256 color terminal

Do mono apps support 256 color terminals?

my program is giving very strange output in a 256 color environment.

Should I just check the $TERM value and disable colour entirely if its 256 color?

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. In my case, it was set to xterm-256color . Mono apparently doesn't like that.

Setting it to xterm will fix the issue.

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". A failure would occur if $TERM was not found in the terminfo database -- or if Mono is incorrectly configured to find the terminfo database. To check the former, use "infocmp" to show the terminal entry.

"Standard linux terminals" would be the Linux console, and that does not match either "xterm" or "vt220" (which differ) well enough to be usable. Again, use infocmp to see, eg, infocmp linux xterm , infocmp linux vt220

Back to the original question: the odd text which was printed came out of the terminfo database. 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. 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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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