如何在 C# 中模拟 ANSI 终端? [英] How to emulate ANSI terminal in C#?

查看:50
本文介绍了如何在 C# 中模拟 ANSI 终端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Mono 中有一个应用程序,它创建一个 Putty 窗口,连接到它的 PTY 并通过它与世界通信.

I have an application in Mono that creates a putty window, connects to it's PTY and communicates with the world via it.

感谢 Putty,我有一个完整的终端,我可以向我的应用程序发送特殊代码(如 Ctrl+C、Ctrl+Z).

Thanks to Putty I have a full terminal, I can send special codes (like Ctrl+C, Ctrl+Z) to my app.

我想回到我的终端,在其中启动应用程序.我想获取尽可能多的组合键.这样我就可以通过 ssh 使用我的应用程序,而不会弹出任何窗口.

I would like to go back to my terminal, in which I start the application. I would like to grab as many key combinations as possible. That way I'd be able to use my app via ssh, with no windows popping up.

我的想法是从/dev/检索我当前的终端,忽略(或处理)所有可能的信号,轮询按下的键并转发到我的应用程序.这可以在 C 中使用 P/Invoke 完成.

My idea is to retrieve my current terminal from /dev/, ignore (or handle) all the possible signals, poll on the pressed keys and forward to my app. This could be done in C with P/Invoke.

这是可能的,但编写代码既痛苦又耗时.

This is possible, but painful and time-consuming to code.

我想知道它是否已经完成了?你知道任何图书馆吗?最好的选择是注册一两个回调,但任何能让它更容易的解决方案都会很棒.

I wonder if it's already done? Do you know about any libraries? The best option would be to register for a callback or two, but any solution making it easier would be great.

TL;DR

我需要一个可以为我提供如下界面的库:

I need a library that would give my interface like:

event Action<byte> CharReceived;
void WriteChar(byte val);

并允许我以字节序列的形式接收 ANSI 终端代码.

and allowed me to receive ANSI terminal codes as sequence of bytes.

另一种选择是根据 ANSI 终端规则将 ConsoleKeyInfo 转换为 byte[] 的库.

The alternative would be a library to translate ConsoleKeyInfo to byte[], according to ANSI terminal rules.

推荐答案

我发现以下项目链接非常有用.您可以下载该项目,然后查看 codeproject 站点上的第一条评论,了解如何将其扩展到 SerialPort 支持(这正是我所需要的).

I found the following project link very helpful. You can download the project, then look at the first comment on the codeproject site to see how to extend it to SerialPort support (which is what I needed).

http://www.codeproject.com/Articles/20781/Terminal-Control-Library-C-VT100-ANSI-XTERM-SSH-Te

该项目实际上是 Poderosa 项目的一个薄包装,但除非您会说日语,否则这个薄包装很有用.Poderosa 项目已经支持 SerialPorts,但Columbus-MCSD"并未将其带到表面.

The project is really a thin wrapper around the Poderosa project, but unless you speak Japanese, this thin wrapper is useful. The Poderosa project supports SerialPorts already, but it wasn't brought to the surface by "Columbus-MCSD".

这篇关于如何在 C# 中模拟 ANSI 终端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆