Term::Completion::_readkey - utility package for Term::Completion using Term::ReadKey


Term-Completion documentation Contained in the Term-Completion distribution.

Index


Code Index:

NAME

Top

Term::Completion::_readkey - utility package for Term::Completion using Term::ReadKey

DESCRIPTION

Top

This utility package contains few methods that are required for Term::Completion to put the terminal in "raw" mode and back. This package uses Term::ReadKey to accomplish this, which should be portable across many systems.

Methods

set_raw_tty()

Uses Term::ReadKey's ReadMode 4 to set the terminal into "raw" mode, i.e. switch off the meaning of any control characters like CRTL-C etc. Also the echo of characters is switched off, so that the program has full control of what is typed and displayed.

Uses the "in" field of the Term::Completion object to get the input file handle.

reset_tty()

Resets the terminal to its previous state, using ReadMode 0.

get_key()

Reads one byte from the input handle. Uses ReadKey.

get_term_size()

Determine the terminal size with GetTerminalSize and return the list of columns and rows (two integers).

AUTHOR

Top

Marek Rouchal <marekr@cpan.org>

COPYRIGHT

Top

SEE ALSO

Top

Term::ReadKey


Term-Completion documentation Contained in the Term-Completion distribution.

package Term::Completion::_readkey;

use strict;
use Term::ReadKey qw(ReadMode ReadKey GetTerminalSize);

sub set_raw_tty
{
  my __PACKAGE__ $this = shift;
  ReadMode 4, $this->{in};
  1;
}

sub reset_tty
{
  my __PACKAGE__ $this = shift;
  ReadMode 0, $this->{in};
  1;
}

sub get_key
{
  my __PACKAGE__ $this = shift;
  ReadKey(0, $this->{in});
}

sub get_term_size
{
  my __PACKAGE__ $this = shift;
  if(defined $this->{columns} and defined $this->{rows}) {
    return($this->{columns},  $this->{rows});
  }
  my ($c,$r) = GetTerminalSize($this->{out});
  $c ||= $Term::Completion::DEFAULTS{columns};
  $r ||= $Term::Completion::DEFAULTS{rows};
  return (
    (defined $this->{columns} ? $this->{columns} : $c),
    (defined $this->{rows}    ? $this->{rows}    : $r)
  );
}

1;

__END__