VtNetCore
VtNetCore copied to clipboard
User App Example
Is there an example of how to use the library... perhaps a simple terminal application?
Thanks!
There is this: https://github.com/darrenstarr/VtNetCore.UWP.
Thanks... but a UWP app is quite different from a .NET Winform app. I was not able to figure out how to translate the example into simple terminal application.
if you want to use it in a simple terminal application you probably want to setup something like this:
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using VtNetCore.VirtualTerminal;
using VtNetCore.XTermParser;
namespace VtNetCoreTest
{
internal class Program
{
private static CancellationTokenSource ctc;
private static TelnetClient telnetcli;
private static VirtualTerminalController vtController;
static DataConsumer DataPart;
public static async Task Main(string[] args)
{
await setupConnection("towel.blinkenlights.nl",23);
await telnetcli.Connect();
await telnetcli.Send("a");
await WaitForItToWork();
}
static async Task WaitForItToWork()
{
while (true)
{
Console.Clear();
Console.Write(vtController.GetScreenText());
await Task.Delay(1000); // arbitrary delay
}
}
public static async Task setupConnection(string host, int port)
{
ctc = new CancellationTokenSource();
vtController = new VirtualTerminalController();
vtController.ResizeView(80, 25);
DataPart = new VtNetCore.XTermParser.DataConsumer(vtController);
telnetcli = new TelnetClient(host, port, TimeSpan.FromSeconds(0), ctc.Token);
telnetcli.DataReceived += (sender, s) => DataPart.Push(Encoding.ASCII.GetBytes(s));
//telnetcli.LineReceived += (sender, s) => Console.WriteLine(s);
//telnetcli.ConnectionClosed += (sender, args) => Console.WriteLine(args);
//telnetcli.LineReceived += (sender, s) => OutputLog += s;
vtController.SendData += (sender, args) => Console.WriteLine(args.Data);
}
}
}
the hardest issue is you must well regularly get the screentext
如果要在简单的终端应用程序中使用它,则可能需要设置如下所示的内容:
using System; using System.Text; using System.Threading; using System.Threading.Tasks; using VtNetCore.VirtualTerminal; using VtNetCore.XTermParser; namespace VtNetCoreTest { internal class Program { private static CancellationTokenSource ctc; private static TelnetClient telnetcli; private static VirtualTerminalController vtController; static DataConsumer DataPart; public static async Task Main(string[] args) { await setupConnection("towel.blinkenlights.nl",23); await telnetcli.Connect(); await telnetcli.Send("a"); await WaitForItToWork(); } static async Task WaitForItToWork() { while (true) { Console.Clear(); Console.Write(vtController.GetScreenText()); await Task.Delay(1000); // arbitrary delay } } public static async Task setupConnection(string host, int port) { ctc = new CancellationTokenSource(); vtController = new VirtualTerminalController(); vtController.ResizeView(80, 25); DataPart = new VtNetCore.XTermParser.DataConsumer(vtController); telnetcli = new TelnetClient(host, port, TimeSpan.FromSeconds(0), ctc.Token); telnetcli.DataReceived += (sender, s) => DataPart.Push(Encoding.ASCII.GetBytes(s)); //telnetcli.LineReceived += (sender, s) => Console.WriteLine(s); //telnetcli.ConnectionClosed += (sender, args) => Console.WriteLine(args); //telnetcli.LineReceived += (sender, s) => OutputLog += s; vtController.SendData += (sender, args) => Console.WriteLine(args.Data); } } }最难的问题是您必须定期获取屏幕文本