NAME
Game::Terminal::Kit::Run - give the terminal back on every way out
VERSION
Version 0.05
SYNOPSIS
use Game::Terminal::Kit::Run;
sub run {
my ($class, @argv) = @_;
my $terminal = $class->new(...);
my $result = Game::Terminal::Kit::Run::guard(
sub { $terminal->start },
$terminal->keys, $terminal->screen,
);
return $result && $result->lost ? 1 : 0;
}
DESCRIPTION
A game that reads a key at a time has changed the terminal, and has to change it back however it stops: at the end, on an error, and when it is interrupted. A terminal left as the game had it echoes nothing and shows no cursor.
FUNCTIONS
Neither is exported.
guard
my $result = Game::Terminal::Kit::Run::guard(\&body, @held);
Calls the body and returns what it returns, in the caller's context. Each of @held is an object with a leave_raw method, a restore method or both, such as a Game::Terminal::Kit::Keys and a Game::Terminal::Kit::Screen. They are given back when the body returns, and when it dies, after which the error is thrown again unchanged.
While the body runs, INT, TERM and HUP give them back too and then arrive as they would have: the signal is raised again with its default action, so the program still stops and its parent still sees why. The handlers that were there before are there again afterwards.
give_back
Game::Terminal::Kit::Run::give_back(@held);
The giving back on its own. An error from one object does not stop the next from being given back.
SEE ALSO
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)