Quizzer::FrontEnd::Tty - Tty FrontEnd


Quizzer documentation Contained in the Quizzer distribution.

Index


Code Index:

NAME

Top

Quizzer::FrontEnd::Tty - Tty FrontEnd

DESCRIPTION

Top

This FrontEnd is not useful by itself. It serves as a parent for any FrontEnds that have a user interface that runs in a tty. The screenheight property of this FrontEnd is always set to the current height of the tty, while the screenwidth property is always set to its width.

METHODS

Top

resize

This method is called whenever the tty is resized, and probes to determine the new screen size.

AUTHOR

Top

Joey Hess <joey@kitenet.net>


Quizzer documentation Contained in the Quizzer distribution.
#!/usr/bin/perl -w

package Quizzer::FrontEnd::Tty;
use Quizzer::FrontEnd;
use strict;
use vars qw(@ISA);
@ISA=qw(Quizzer::FrontEnd);

my $VERSION='0.01';

sub new {
	my $proto = shift;
	my $class = ref($proto) || $proto;
	my $self  = bless $proto->SUPER::new(@_), $class;
	$self->resize; # Get current screen size.
	$SIG{'WINCH'}=sub { $self->resize };
	return $self;
}

sub resize {
	my $this=shift;

	if (exists $ENV{'LINES'}) {
		$this->{'screenheight'}=$ENV{'LINES'};
	}
	else {
		($this->{'screenheight'})=`stty -a </dev/tty` =~ m/rows (\d+)/s;
		$this->{'screenheight'}=25 if ! $this->{'screenheight'};
	}

	if (exists $ENV{'COLUMNS'}) {
		$this->{'screenwidth'}=$ENV{'COLUMNS'};
	}
	else {
		($this->{'screenwidth'})=`stty -a </dev/tty` =~ m/columns (\d+)/s;
		$this->{'screenwidth'}=80 if ! $this->{'screenwidth'};
	}
}

1