NAME

Game::Terminal::Kit::Test::Screen - a keyboard and a screen for a test

VERSION

Version 0.05

SYNOPSIS

use Test::More;
use Game::Terminal::Kit::Test::Screen qw/kit within/;

my ($keys, $screen, $text) = kit(keys => "\e[B\e[B\r");

my $terminal = Game::Checkers::Terminal->new(keys => $keys, screen => $screen);
my $move = within(10, sub { $terminal->choose_move });

is $move->notation, '11-15', 'down twice and enter chose the third move';
like ${$text}, qr/^> 11-15$/m, 'and it was under the cursor';

DESCRIPTION

What a test of a terminal game needs in place of a terminal: keys that come from a string, a screen that goes into a string, and a limit on how long a game that is waiting for a key nobody will press may wait.

Nothing here touches a real terminal and Term::ReadKey is not needed.

FUNCTIONS

Each is exported on request.

keysource

my $source = keysource("\e[A\rq");

A keysource for Game::Terminal::Kit::Keys that hands out the string a character at a time and then undef. An arrow key is typed as the escape sequence a terminal sends for it.

capture

my ($out, $text) = capture();

A handle to write to and a reference to everything written to it.

typed

my $in = typed('e3 d4', 'quit');

A handle to read from, holding those lines.

kit

my ($keys, $screen, $text) = kit(keys => "\r", typed => ['yes']);

A Game::Terminal::Kit::Keys and a Game::Terminal::Kit::Screen wired to the above, and the reference to what the screen was sent. keys is the string of keys and typed the lines; with no keys there is no keyboard and the game is line by line. The screen is not a terminal, has no colour and is ASCII, so what a test matches is what was meant and nothing else; any other argument is the screen's and overrides that.

within

my $result = within($seconds, sub { $terminal->start });

Runs the body and returns what it returns. A body still running when the time is up is stopped and counted as one failed test, and nothing is returned: a test that hangs tells nobody anything. Any other error is thrown on.

SEE ALSO

Game::Terminal::Kit::Test::Handle, Game::Terminal::Kit.

AUTHOR

LNATION, <email at lnation.org>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)