1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
#
# Curses interface module.
#
my $VERSION = "0.01";
my $FAILED = 0;
BEGIN
{
if ((defined $INTERFACE) || ($daemon))
{
$SUCCESS = 0; return 1;
}
foreach (@SCRIPT_PATH)
{
push @INC, "$_/CursesLib";
}
my $oh = $SIG{__DIE__};
$SIG{__DIE__} = sub { return; };
eval
{
require Curses;
import Curses
require Window;
import Window;
require InputLine;
import InputLine;
};
$SIG{__DIE__} = $oh;
if ($@)
{
print "Error, unable to load Curses module...\n";
$SUCCESS = 0;
return;
}
else
{
$SUCCESS = 1;
}
}
return if (! $SUCCESS);
push @{ $code_hash{&MSG_SERVER_STATS} }, \&update_counts;
push @{ $code_hash{&MSG_INIT} }, \&setup_curses;
$INTERFACE = 1;
$SCROLL_LENGTH = 101 if (! defined $SCROLL_LENGTH);
push @extensions, "Curses";
print "Curses TUI Module $VERSION Loaded...\n";
#
# Set up keyboard handler
#
my $handle = \*STDIN;
$handles{$handle} = { Handle => $handle,
Callback => \&check_keyboard };
$command_hash{"/pageup"} = [ \&do_page_up ];
$command_hash{"/pagedown"} = [ \&do_page_down ];
$command_hash{"/clear"} = [ \&do_clear ];
$help_hash{"/pageup"} = "Usage: /pageup\n\n Causes the screen to shift up by a half-page.\n\n";
$help_hash{"/pagedown"} = "Usage: /pagedown\n\n Causes the screen to shift down by a half-page\n\n";
$help_hash{"/clear"} = "Usage: /clear\n\n Clears the display.\n\n";
#
# Set up screen.
#
my ($window, $input);
$CURSES_ENABLED = 1;
unshift @{ $code_hash{&MSG_SHUTDOWN} }, sub { endwin() };
sub setup_curses
{
my $tieclass;
my $textwin;
my $cmdwin;
my ($scr_width, $scr_height);
initscr();
cbreak();
noecho();
# This is a butt-ugly palette which tries to emulate the GUI palette
# to some degree... what Curses needs is the ability to store attributes
# in colour pairs...
if ($colours)
{
start_color();
init_pair(1, COLOR_YELLOW, COLOR_BLACK);
init_pair(2, COLOR_WHITE, COLOR_BLACK);
init_pair(3, COLR_BLUE, COLOR_BLACK);
init_pair(4, COLOR_GREEN, COLOR_BLACK);
init_pair(5, COLOR_RED, COLOR_BLACK);
init_pair(6, COLOR_MAGENTA, COLOR_BLACK);
init_pair(7, COLOR_MAGENTA, COLOR_BLACK);
init_pair(8, COLOR_YELLOW, COLOR_BLACK);
init_pair(9, COLOR_YELLOW, COLOR_BLACK);
init_pair(10, COLOR_GREEN, COLOR_BLACK);
init_pair(11, COLOR_GREEN, COLOR_BLACK);
init_pair(12, COLOR_CYAN, COLOR_BLACK);
init_pair(13, COLOR_BLUE, COLOR_BLACK);
init_pair(14, COLOR_WHITE, COLOR_BLACK);
init_pair(15, COLOR_WHITE, COLOR_BLACK);
init_pair(16, COLOR_WHITE, COLOR_BLUE);
}
getmaxyx($scr_height, $scr_width);
$textwin = subwin($scr_height-2, $scr_width, 0, 0);
$cmdwin = subwin(2, $scr_width, $scr_height-2, 0);
attrset($cmdwin, COLOR_PAIR(16));
addstr($cmdwin, 0, 0, "-"x$scr_width);
attrset($cmdwin, COLOR_PAIR(2));
my $oldwin = tied *STDOUT;
($window, $input) = (Window->new($textwin, $SCROLL_LENGTH, $oldwin),
InputLine->new($cmdwin));
tie *STDOUT, 'Window', $window;
refresh($cmdwin);
}
sub check_keyboard
{
my ($sock, $handle) = @_;
my $ch;
$input->getchar($ch);
return if ($input->line_available() == $FALSE);
do_command($sock, $input->getline());
}
sub update_counts
{
my ($sock, $text) = @_;
my ($libs, $total, $gigs);
$$text =~ s/(\d+) (\d+) (\d+)//g;
$total = $2; $libs = $1; $gigs = $3;
return if (! isa($input->{"window"}, 'Curses::Window'));
attrset($input->{"window"}, COLOR_PAIR(16));
addstr($input->{"window"}, 0, 0, "-- Songs: $total -- Libraries: $libs -- Gigs: $gigs ");
attrset($input->{"window"}, COLOR_PAIR(2));
refresh($input->{"window"});
}
sub do_page_up
{
my ($sock, $param_str, @params) = @_;
$window->page_up;
}
sub do_page_down
{
my ($sock, $param_str, @params) = @_;
$window->page_down;
}
sub do_clear
{
my ($sock, $param_str, @params) = @_;
$window->clear;
}
|