We are trying to implement our own display of the terminal screen using the IScreen interface and this is the skeleton of the code:
class RebexScreen : IScreen
{
RebexClient m_TnClient;
public RebexScreen (RebexClient cc)
{
m_TnClient = cc;
}
public void Clear(int left, int top, int width, int height)
{
// clear screen data
}
public void Copy(int sourceLeft, int sourceTop, int targetLeft, int targetTop, int width, int height)
{
// copy screen data
}
public void Resize(int width, int height)
{
}
public void Scroll(int rows)
{
// move screen data up
}
public void SetColor(int foreground, int background)
{
}
public void SetCursorPosition(int x, int y, bool visible)
{
if (visible)
{
// update cursor pos
}
}
public void Write(int left, int top, string text)
{
TerminalCell cell = m_TnClient.m_rxScript.Terminal.Screen.GetCell(left, top);
// my drawing code:
}
}
class RebexClient
{
public async Task<bool> ConnectAsync(ConnectionSettings cs)
{
m_rxTelnet = new Telnet(cs.HostNameIP, cs.Port, cs.SupportSSL ? SslMode.Explicit : SslMode.None);
m_rxTelnet.Timeout = cs.TimeOutSec * 1000;
TerminalOptions options = new TerminalOptions() {
TerminalType = TerminalType.Ansi,
Columns = cs.CustomCols,
Rows = cs.CustomRows,
};
options.ColorScheme = Rebex.TerminalEmulation.ColorScheme.Custom;
options.SetColorIndex(SchemeColorName.Foreground, 2);
options.SetColorIndex(SchemeColorName.Background, 6);
try
{
m_rxScript = null;
m_rxScript = await m_rxTelnet.StartScriptingAsync(options).ConfigureAwait(false);
RebexScreen my = new RebexScreen(this);
TerminalExtensions.SetCustomScreen(m_rxScript.Terminal, my);
m_rxScript.Terminal.Disconnected += Terminal_Disconnected;
m_rxScript.Terminal.DataReceived += Terminal_DataReceived;
}
catch (NetworkSessionException ex)
{
switch (ex.Status)
{
case NetworkSessionExceptionStatus.UnclassifiableError:
break;
case NetworkSessionExceptionStatus.OperationFailure:
break;
case NetworkSessionExceptionStatus.ConnectFailure:
break;
case NetworkSessionExceptionStatus.ConnectionClosed:
break;
case NetworkSessionExceptionStatus.SocketError:
break;
case NetworkSessionExceptionStatus.NameResolutionFailure:
break;
case NetworkSessionExceptionStatus.ProtocolError:
break;
case NetworkSessionExceptionStatus.OperationAborted:
break;
case NetworkSessionExceptionStatus.ServerProtocolViolation:
break;
case NetworkSessionExceptionStatus.Timeout:
break;
case NetworkSessionExceptionStatus.AsyncError:
break;
default:
break;
}
ReportError(ex.Message);
}
catch (Exception e)
{
ReportError(e.Message);
}
Task.Run(() =>
{
try
{
while (m_rxScript.Process(int.MaxValue) != TerminalState.Disconnected) ;
}
catch {}
}).Forget();
return true;
}
private void Terminal_DataReceived(object sender, DataReceivedEventArgs e)
{
}
private void Terminal_Disconnected(object sender, EventArgs e)
{
}
public async Task DisconnectAsync()
{
await Task.Run(() =>
{
try
{
m_rxScript.Terminal.Dispose();
m_rxScript.Close();
}
catch {}
}).ConfigureAwait(false);
}
public async Task<bool> SendAsync(byte[] acData, int nOffset, int nLen)
{
await Task.Run(() => m_rxScript.SendData(acData, nOffset, nLen)).ConfigureAwait(false);
return true;
}
}
1) I am assuming the IScreen.Write is the place to implement the drawing of text to my screen and the way to get the color and underline attributes is by calling the GetCell method there. Is that correct?
2) Setting the default foreground and background using SetColorIndex does not seem to work. I tried it with the Terminal Control and it works there but not here with the VirtualTerminal. Am I missing something?
3) Should I be using the Terminal_DataReceived event? But with that, there is no information about position of text.
4) Are there attributes for reverse video, double width/double height? If not, any plans of providing that in the near future?
5) Any way to disable 8-bit control characters?
Thank you.