Skip to main content

FakeTerminal class

Namespace: Arlecchino.Testing · Assembly: Arlecchino.Testing

A terminal that keeps everything in memory: keys queued in, output collected as text, and the size a test sets. The input queues are concurrent, so keys can be delivered late as a real terminal delivers them.

public sealed class FakeTerminal : IArlecchinoTerminal, IChecksFrames

Implements IArlecchinoTerminal, IChecksFrames

Constructors

MemberSummary
FakeTerminal(int, int)Creates the terminal at a fixed size.

Properties

MemberSummary
AreControlKeysTakenWhether the application borrowed Ctrl+C and has not handed it back.
CopiedTextThe last text copied, or null when nothing has been.
HeightRows. Assigning simulates a resize.
IsFullScreenWhether the application took over the screen and has not given it back.
IsMouseEnabledWhether the application asked for the mouse.
IsPasteEnabledWhether the application asked for bracketed paste.
KeyAvailableWhether any queued key is still waiting.
MouseAvailableWhether any queued mouse event is still waiting.
ScreenWhat the screen holds, rather than the cursor jumps and short runs FakeTerminal.WrittenText collected to get it there. It survives FakeTerminal.Clear, as a real screen does.
WidthColumns. Assigning simulates a resize.
WrittenTextEverything written so far, escape sequences included.

Methods

MemberSummary
Clear()Throws away what has been written, so the next assertion sees one frame rather than all of them.
CopyToClipboard(string)Keeps what was copied instead of reaching a real clipboard.
DisableMouse()Records that the mouse was released.
DisablePaste()Records that bracketed paste was turned off.
EnableMouse()Records that the mouse was asked for.
EnablePaste()Records that bracketed paste was asked for.
Enqueue(KeyPress)Queues a key press to be read.
EnqueueMouse(MouseEvent)Queues a mouse event to be read, the way a console that reports the mouse outside the key stream delivers one.
EnqueueText(string)Queues text one character at a time, as a terminal reports it, naming the key wherever ReadKey names one. An escape and the letter after it stay two presses.
EnterFullScreen()Records that the screen was taken over.
GiveBackControlKeys()Records that Ctrl+C was handed back to the terminal.
LeaveFullScreen()Records that the screen was given back, which is what a test checks after a crash.
ReadKey()Takes the next queued key, or nothing when the queue has run dry.
ReadMouse()Takes the next queued mouse event, or nothing when the queue has run dry.
TakeControlKeys()Records that Ctrl+C was borrowed, so it arrives as a key rather than as a signal.
Unread(KeyPress)Puts a key back, so the next read returns it.
Write(string)Collects output instead of showing it, and applies it to FakeTerminal.Screen.

Constructors in detail

FakeTerminal(int, int)

public FakeTerminal(int width, int height);

Creates the terminal at a fixed size.

Parameters

NameTypeDescription
widthintColumns.
heightintRows.

Properties in detail

AreControlKeysTaken

public bool AreControlKeysTaken { get; }

Whether the application borrowed Ctrl+C and has not handed it back.

Type bool

CopiedText

public string? CopiedText { get; }

The last text copied, or null when nothing has been.

Type string

Height

public int Height { get; set; }

Rows. Assigning simulates a resize.

Type int

IsFullScreen

public bool IsFullScreen { get; }

Whether the application took over the screen and has not given it back.

Type bool

IsMouseEnabled

public bool IsMouseEnabled { get; }

Whether the application asked for the mouse.

Type bool

IsPasteEnabled

public bool IsPasteEnabled { get; }

Whether the application asked for bracketed paste.

Type bool

KeyAvailable

public bool KeyAvailable { get; }

Whether any queued key is still waiting.

Type bool

MouseAvailable

public bool MouseAvailable { get; }

Whether any queued mouse event is still waiting.

Type bool

Screen

public ScreenGrid Screen { get; }

What the screen holds, rather than the cursor jumps and short runs FakeTerminal.WrittenText collected to get it there. It survives FakeTerminal.Clear, as a real screen does.

Type ScreenGrid

Width

public int Width { get; set; }

Columns. Assigning simulates a resize.

Type int

WrittenText

public string WrittenText { get; }

Everything written so far, escape sequences included.

Type string

Methods in detail

Clear()

public void Clear();

Throws away what has been written, so the next assertion sees one frame rather than all of them.

CopyToClipboard(string)

public void CopyToClipboard(string text);

Keeps what was copied instead of reaching a real clipboard.

Parameters

NameTypeDescription
textstringWhat was copied.

DisableMouse()

public void DisableMouse();

Records that the mouse was released.

DisablePaste()

public void DisablePaste();

Records that bracketed paste was turned off.

EnableMouse()

public void EnableMouse();

Records that the mouse was asked for.

EnablePaste()

public void EnablePaste();

Records that bracketed paste was asked for.

Enqueue(KeyPress)

public void Enqueue(KeyPress key);

Queues a key press to be read.

Parameters

NameTypeDescription
keyKeyPressThe key press.

EnqueueMouse(MouseEvent)

public void EnqueueMouse(MouseEvent mouse);

Queues a mouse event to be read, the way a console that reports the mouse outside the key stream delivers one.

Parameters

NameTypeDescription
mouseMouseEventThe event.

EnqueueText(string)

public void EnqueueText(string text);

Queues text one character at a time, as a terminal reports it, naming the key wherever ReadKey names one. An escape and the letter after it stay two presses.

Parameters

NameTypeDescription
textstringThe characters to queue.

EnterFullScreen()

public void EnterFullScreen();

Records that the screen was taken over.

GiveBackControlKeys()

public void GiveBackControlKeys();

Records that Ctrl+C was handed back to the terminal.

LeaveFullScreen()

public void LeaveFullScreen();

Records that the screen was given back, which is what a test checks after a crash.

ReadKey()

public KeyPress ReadKey();

Takes the next queued key, or nothing when the queue has run dry.

Returns KeyPress — The key press.

ReadMouse()

public MouseEvent ReadMouse();

Takes the next queued mouse event, or nothing when the queue has run dry.

Returns MouseEvent — The event.

TakeControlKeys()

public void TakeControlKeys();

Records that Ctrl+C was borrowed, so it arrives as a key rather than as a signal.

Unread(KeyPress)

public void Unread(KeyPress key);

Puts a key back, so the next read returns it.

Parameters

NameTypeDescription
keyKeyPressThe key to put back.

Write(string)

public void Write(string text);

Collects output instead of showing it, and applies it to FakeTerminal.Screen.

Parameters

NameTypeDescription
textstringWhat was written.