Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User App Example #7

Open
joewez opened this issue Apr 22, 2019 · 4 comments
Open

User App Example #7

joewez opened this issue Apr 22, 2019 · 4 comments

Comments

@joewez
Copy link

joewez commented Apr 22, 2019

Is there an example of how to use the library... perhaps a simple terminal application?

Thanks!

@jwoptio
Copy link

jwoptio commented Sep 19, 2019

There is this: https://github.com/darrenstarr/VtNetCore.UWP.

@joewez
Copy link
Author

joewez commented Sep 28, 2019

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.

@jfm535
Copy link

jfm535 commented Nov 15, 2020

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

@heartacker
Copy link

如果要在简单的终端应用程序中使用它,则可能需要设置如下所示的内容:

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);

        }
    }
}

最难的问题是您必须定期获取屏幕文本

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants