Click here to Skip to main content
15,880,796 members
Articles / Desktop Programming / Windows Forms

Terminal Control Library (C# VT100/ANSI/XTERM SSH Telnet)

Rate me:
Please Sign up or sign in to vote.
4.59/5 (27 votes)
2 Jan 2009CPOL3 min read 348.6K   13.3K   72   106
This is based on Poderosa Project http://sourceforge.net/projects/poderosa/

Introduction

My original project can be found here.

I've been trying for a while to come up with a .NET control that would handle VT100/ANSI formatting and connect to SSH2 servers.

I've been through the commercial ones and still haven't found one that suited me.

My last project was based on Granados SSH library (open source SSH .NET implementation) and AckTerm (open source partially completed VT100 control).

Background

This library is an attempt at creating a library based on the "Poderosa" project which can be found here.

Poderosa IMO is the best terminal emulator. It's open source, and is better than the commercial clients. Go check it out for yourself, it's worth it. You can find the original Poderosa CSV source there.

I tried for a couple of weeks to encapsulate components of Poderosa, but the code comments are all in Japanese and I couldn't find any good docs that described the source code. The developer community for Poderosa also appears to be all Japanese, so I felt pretty much on my own.

Using the Code

What I pretty much did here was encapsulate the entire Poderosa application into a library. Then I exposed certain elements so an application developer can simply drop the "Terminal Control.dll" into his/her app and have a control that acts like you would expect any .NET control to act.

This code was written using Visual Studio .NET 2005 Professional and requires .NET Framework 2.0.

Points of Interest

The Poderosa solution is made up of 5 projects:

  1. Container - This is the actual Poderosa application
  2. Terminal - A library providing Telnet capabilities as well as the Terminal Emulation
  3. Common - Code that is shared between the Poderosa application and the Port Forwarding Tool
  4. Granados - SSH library that supports just about every feature of SSH
  5. Portforwarding - A standalone application (uses Terminal, Common, and Granados libraries) that provides SSH portforwarding functionality

First Step

What I've done with my library, was to change "Container" into a Library output, and implement a public class based on System.Windows.Forms.Control.

Second Step

The first time my class ("WalburySoftware.TerminalControl") is instanced, it runs Poderosa code:

C#
GApp.Run(args); GApp._frame._multiPaneControl.InitUI(null, GApp.Options);
GEnv.InterThreadUIService.MainFrameHandle = GApp._frame.Handle; 

Poderosa has lots and lots and lots of static variables. Until I can get the time and motivation to go through them and make the appropriate changes, these variables will need to be initialized before you can use any of Poderosa's classes.

Third Step

If you look at the method Poderosa.ConnectionCommandTarget.Resize, you'll see the line:

C#
if(GEnv.Connections.FindTag(_connection).ModalTerminalTask!=null) 
	return CommandResult.Denied 

This throws an exception. I took it out because it doesn't do anything for my library. I'm not sure what the ModalTerminalTask variable is used for. If you include that line, the terminal will not resize properly.

Final Step

Now we are free to create and use TerminalPanes as we need.

You'll see the steps in WalburySoftware.TerminalControl.Connect() that connect the TerminalPane to an SSH2 connection.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
SuggestionFixed Telnet and added Serial connection metod Pin
cholegm28-Mar-12 1:56
cholegm28-Mar-12 1:56 
GeneralRe: Fixed Telnet and added Serial connection metod Pin
ElectroMonster1-Mar-18 8:06
ElectroMonster1-Mar-18 8:06 
NewsATTENTION: This project is outdated Pin
Elmue2-Nov-11 16:12
Elmue2-Nov-11 16:12 
BugWhen i execute 2 doc commnds it work only for first... for second it always gives "More ?" kind of responce. Pin
prakash gajera17-Oct-11 3:12
prakash gajera17-Oct-11 3:12 
GeneralRe: When i execute 2 doc commnds it work only for first... for second it always gives "More ?" kind of responce. Pin
Member 440167625-Jan-13 10:37
Member 440167625-Jan-13 10:37 
QuestionDisconnect Pin
Member-42411152-Oct-11 11:31
Member-42411152-Oct-11 11:31 
AnswerRe: Disconnect Pin
Columbus-MCSD2-Oct-11 17:42
Columbus-MCSD2-Oct-11 17:42 
QuestionCapturing incoming data Pin
Columbus-MCSD16-Sep-11 5:25
Columbus-MCSD16-Sep-11 5:25 
Serveral people have asked this...

have a look at the TerminalDataReciever class. There's a method called DataArrived() are you use to gain access to the incoming bytes
QuestionMad props - a few questions. Pin
jtlutgen9-Sep-10 9:32
jtlutgen9-Sep-10 9:32 
AnswerRe: Mad props - a few questions. Pin
WuFei0727-Oct-10 10:25
WuFei0727-Oct-10 10:25 
GeneralRe: Mad props - a few questions. Pin
Columbus-MCSD2-Sep-11 0:30
Columbus-MCSD2-Sep-11 0:30 
QuestionHow to read output of command into some variable? Pin
Member 322335128-Jun-10 3:34
Member 322335128-Jun-10 3:34 
GeneralProblems with TerminalControl and Telnet Connection Pin
marcaurel198423-Jun-10 18:57
marcaurel198423-Jun-10 18:57 
GeneralRe: Problems with TerminalControl and Telnet Connection Pin
teebonaire23-Jun-10 22:44
teebonaire23-Jun-10 22:44 
GeneralRe: Problems with TerminalControl and Telnet Connection Pin
marcaurel198423-Jun-10 23:39
marcaurel198423-Jun-10 23:39 
GeneralSerial Port Connection Pin
teebonaire16-Jun-10 15:39
teebonaire16-Jun-10 15:39 
GeneralRe: Serial Port Connection Pin
Columbus-MCSD2-Sep-11 0:31
Columbus-MCSD2-Sep-11 0:31 
GeneralReading and hiding ansi escape sequence Pin
eldwinkhong12-May-10 20:59
eldwinkhong12-May-10 20:59 
GeneralRe: Reading and hiding ansi escape sequence Pin
ElectroMonster26-Jan-15 8:37
ElectroMonster26-Jan-15 8:37 
GeneralRe: Reading and hiding ansi escape sequence Pin
ElectroMonster1-Mar-18 8:07
ElectroMonster1-Mar-18 8:07 
GeneralUse Terminal Emulator portion only Pin
Broncos-Freak5-Mar-10 4:36
Broncos-Freak5-Mar-10 4:36 
GeneralRe: Use Terminal Emulator portion only Pin
Columbus-MCSD2-Sep-11 0:32
Columbus-MCSD2-Sep-11 0:32 
Questiondo you have serial port and telnet example in C# ? Pin
brandnew1231-Mar-10 4:36
brandnew1231-Mar-10 4:36 
AnswerRe: do you have serial port and telnet example in C# ? Pin
stuckne17-Apr-11 5:15
stuckne17-Apr-11 5:15 
QuestionCapture command response Pin
denson28-Nov-09 6:00
denson28-Nov-09 6:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.