c#: transform a string targeted for the unix shell use for the windows command prompt

谁都会走 提交于 2019-12-24 08:22:45

问题


Here is a sample string I got off a socket stream.

\033[H\033[J\033[1;30HSUPERVISOR MAIN MENU\033[6;5H 0.  Exit         Exit\033[7;5H 1.  Help         Display help\033[8;5H 2.  Control      Calling lists and users\033[9;5H 3.  Campaign     Campaigns\033[10;5H 4.  Manage  

If you want to see the output I expect open a unix/linux shell, type echo -e followed by a space followed by the above string in single quotes and hit Enter key. The output appears something like:

                     SUPERVISOR MAIN MENU


 0.  Exit         Exit
 1.  Help         Display help
 2.  Control      Calling lists and users
 3.  Campaign     Campaigns
 4.  Manage

I want the same output except it should be in memory...I require to work with it later...any ideas.


回答1:


I asked an almost equivalent question a few hours ago: Open Source C# VT100 Server. You want a client library that understands the vt100 escape commands.

I searched around for a while and to date haven't found any very good vt100 C# libraries. I've gotten started on a custom one and since I really only need to interpret left and right arrows and backspace it hasn't taken long.

Luckily the vt100 standard is very promiscuous and not overly complex. I don't think it would take you very long to whip up some code to understand the escape commands in your example. This link has a nice concise list of the VT100 escape sequences (you need to scroll down a bit). Another good site is vt100.net.

In your example the escape sequences are being in octal. Your first escape sequence is:

\033[H

which translates to the ASCII below and is used to set the cursor position.

ESC [ H

The second one is

\033[J

which translates to the ASCII sequence below and means clear the line to the end of screen.

ESC [ J 


来源:https://stackoverflow.com/questions/1643594/c-transform-a-string-targeted-for-the-unix-shell-use-for-the-windows-command-p

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