Skip to content

Class DemoShell

A small local shell for demos: line editing, a few commands such as colors and figlet, and a telnet command that hands the terminal to a remote host. Runs in-process through LocalProgramConnection.

Declaration
public sealed class DemoShell : ITerminalProgram

Implements:
DarkEffekt.Terminal.ITerminalProgram

The font the figlet command prints its text in. With none, the shell has no figlet command.

Declaration
public FigletFont BannerFont { get; set; }

The line being edited, for tests and inspection.

Declaration
public string CurrentLine { get; }
Declaration
public int CursorPosition { get; }

AddCommand(string, string, Action<string>, string)

Section titled “AddCommand(string, string, Action<string>, string)”

Adds a command of your own to the shell. It runs with the rest of the line as its argument, and the help command lists it with its usage in place of its name when given: “demo [NAME]”, arguments in capitals and optional ones in brackets. A command added under the name of one of the shell’s own replaces that one.

Declaration
public void AddCommand(string name, string help, Action<string> run, string usage = null)
Type Name
System.String name
System.String help
System.Action<System.String> run
System.String usage

Adds a group of commands under one word, such as screen: each command in it runs as “screen power”, the word alone lists them, and help lists the group as one line. A group added under the name of an existing command or group replaces it.

Declaration
public ShellCommandGroup AddGroup(string name, string help)

DarkEffekt.Terminal.ShellCommandGroup

Type Name
System.String name
System.String help

Prints text and waits for a key: Enter runs the action, any other key returns to the prompt. For a command that should say what it is about to do first, such as one that hands the terminal to a game. Call this from a command added with AddCommand.

Declaration
public void Confirm(string text, Action then)
Type Name
System.String text
System.Action then

Writes text to the terminal, for a command added with AddCommand to answer with. End a line with “\r\n”.

Declaration
public void Print(string text)
Type Name
System.String text

Takes a command out of the shell, one of its own or one added with AddCommand, and out of the help list: exit, say, where the shell should stay. The help command stays.

Declaration
public void RemoveCommand(string name)
Type Name
System.String name
Declaration
public void Start(IProgramHost host)
Type Name
DarkEffekt.Terminal.IProgramHost host
Declaration
public void OnInput(byte[] data)
Type Name
System.Byte[] data

Hands the terminal to a connection until it closes or Ctrl-] ends it, as the telnet command does with a host: the connection’s output goes to the screen, and everything typed goes to the connection. The shell opens the connection and disposes it. Call this from a command added with AddCommand.

Declaration
public void Attach(ITerminalConnection remote)
Type Name
DarkEffekt.Terminal.ITerminalConnection remote
Declaration
public void OnResize(int cols, int rows)
Type Name
System.Int32 cols
System.Int32 rows
Declaration
public void Stop()