Curses-Simp
view release on metacpan or search on metacpan
- Prmt: mk new 'rdls' type: as a radio list w/ auto (*) -
- Mesg: mk new 'slid' type: params for all overlay text, chars, ticks,
flags, etc. && updt pmix to use... maybe register sub fields,dims...
- Prnt: add multi-line option where text can split on /\n/ but each new
line prints relative to starting xcrs
- Prmt: add multi-line option where dtxt can split on /\n/ && ^d accepts
entry instead of RETURN
- Prnt: handle ASCII chars under 32 with escapes like Draw
- Draw: optimize rendering
- Prnt&&Draw: handle ASCII chars under 32 better than current escapes
- mk 'ceol' && 'ceos' params to clear text[n] from cursor on
- consider breaking sub (CPik|Brws|.+?) into own Curses::Simp::$1.pm
instead of letting Simp.pm remain so cluttered
if detectable:
- handle xterm resize events
- handle mouse input (study any existent Curses apps that use mouse
input you can find ... probably in C), read man for gpm(1), sysmouse(4),
&& sb(4) && study aumix mouse source
- Learn how to read a Shift-Tab key press if in any way distinguishable
Returns the number of available colors (last index: NumC() - 1)
Hite or Height
Returns the current Simp object's window height (last index: Height() -
1)
Widt or Width
Returns the current Simp object's window width (last index: Width() - 1)
Prnt or PrintString( $String )
Prints $String at current cursor position. PrintString() can also accept
a hash of parameters (e.g., PrintString('text' => $String)) where:
'text' => [ "String to Print" ], # or can just be string without arrayref
'fclr' => [ "ForegroundColorCodes corresponding to text" ],
'bclr' => [ "BackgroundColorCodes corresponding to text" ],
'ycrs' => 3, # Number to move the cursor's y to before printing
'xcrs' => 7, # Number to move the cursor's x to before printing
'yoff' => 15, # same as ycrs except original ycrs is restored afterwards
'xoff' => 31, # same as xcrs except original xcrs is restored afterwards
'prin' => 1, # flag to specify whether printed text should update the
# main Text(), FClr(), and BClr() data or just print to the
# screen temporarily. Default is true (i.e., Print Into all)
The hash keys can also be the corresponding VerboseNames described in
the new() section instead of these 4-letter abbreviated key names.
PrintString() returns the number of characters printed.
KMod or KeyMode( [$KeyName [,$NewValue]] )
Returns the key mode (state) of the key mode name $KeyName. $KeyName
should be one of the KMOD_ names from the bottom of the "SDLKEY NOTES"
section.
If no parameters are provided, the state of KMOD_NONE is returned.
If $NewValue is provided, the state of $KeyName is set to $NewValue.
GetS or GetString( [$YCursor, $XCursor[, $ResultLength]] )
GetString() returns the string found from the cursor (or the specified
coordinates) on to the end-of-line or to $ResultLength if provided.
Move or MoveCursor( [$YCursor, $XCursor] )
MoveCursor() updates the current Simp object's cursor position to the
newly specified $YCursor, $XCursor.
By default, the cursor is not visible but this can be changed through
the FlagCursorVisible(1) function.
Returns ($YCursor, $XCursor) as the coordinates of the cursor.
Rsiz or ResizeWindow( $Height, $Width )
ResizeWindow() updates the current Simp object's window dimensions to
the newly specified $Height, $Width.
Think of ResizeWindow() as an easy way to call both Height() and Width()
at once.
Returns ($Height, $Width) as the dimensions of the window.
'hifc' => "ColorCodes for highlighted (unedited) dref/dtxt foreground color",
'hibc' => "ColorCodes for highlighted (unedited) dref/dtxt background color",
'text' => [ "same as new \@text" ],
'fclr' => [ "ForegroundColorCodes corresponding to text" ],
'bclr' => [ "BackgroundColorCodes corresponding to text" ],
'hite' => 3, # height of the prompt window (including borders)
'widt' => 63, # width of the prompt window (including borders)
'titl' => "PromptWindow Title string",
'ttfc' => "ColorCodes corresponding to titl foreground color",
'ttbc' => "ColorCodes corresponding to titl background color",
'flagcvis' => 1, # a flag specifying whether the cursor should be displayed
The hash keys can also be the corresponding VerboseNames described in
the new() section instead of these 4-letter abbreviated key names.
CPik or ColorPickWindow()
ColorPickWindow() is a simple Color Picker window.
It accepts arrow keys to highlight a particular color and enter to
select. The letter corresponding to the color or the number of the index
can also be pressed instead.
BTyp or WindowBorderType # loop through border types
BTyp or WindowBorderType
Normal Accessors
Name or VerboseName # Description
---- ----------- -------------
Hite or WindowHeight # window height
Widt or WindowWidth # window width
YOff or WindowYOffset # window y-offset position
XOff or WindowXOffset # window x-offset position
YCrs or CursorYOffset # window y-cursor position
XCrs or CursorXOffset # window x-cursor position
BrFC or WindowBorderForegroundColor # border fg color code string
BrBC or WindowBorderBackgroundColor # border bg color code string
Titl or WindowTitle # title string
TtFC or WindowTitleForegroundColor # title fg color code string
TtBC or WindowTitleBackgroundColor # title bg color code string
DNdx or DisplayStackIndex # global display index
Hite or WindowHeight
Widt or WindowWidth
YOff or WindowYOffset
push(@_attrnamz, '_mque'); $_attrdata{$_attrnamz[-1]} = []; # Key Mod Queue
$_verbose_attrnamz{$_attrnamz[-1]} = 'KeyModQueue';
push(@_attrnamz, '_hite'); $_attrdata{$_attrnamz[-1]} = 0; # window height
$_verbose_attrnamz{$_attrnamz[-1]} = 'WindowHeight';
push(@_attrnamz, '_widt'); $_attrdata{$_attrnamz[-1]} = 0; # window width
$_verbose_attrnamz{$_attrnamz[-1]} = 'WindowWidth';
push(@_attrnamz, '_yoff'); $_attrdata{$_attrnamz[-1]} = 0; # window y-offset
$_verbose_attrnamz{$_attrnamz[-1]} = 'WindowYOffset';
push(@_attrnamz, '_xoff'); $_attrdata{$_attrnamz[-1]} = 0; # window x-offset
$_verbose_attrnamz{$_attrnamz[-1]} = 'WindowXOffset';
push(@_attrnamz, '_ycrs'); $_attrdata{$_attrnamz[-1]} = 0; # cursor y-offset
$_verbose_attrnamz{$_attrnamz[-1]} = 'CursorYOffset';
push(@_attrnamz, '_xcrs'); $_attrdata{$_attrnamz[-1]} = 0; # cursor x-offset
$_verbose_attrnamz{$_attrnamz[-1]} = 'CursorXOffset';
push(@_attrnamz, '_btyp'); $_attrdata{$_attrnamz[-1]} = 0; # border type
$_verbose_attrnamz{$_attrnamz[-1]} = 'WindowBorderType';
push(@_attrnamz, '_brfc'); $_attrdata{$_attrnamz[-1]} = 'w';# border fore color
$_verbose_attrnamz{$_attrnamz[-1]} = 'WindowBorderForegroundColor';
push(@_attrnamz, '_brbc'); $_attrdata{$_attrnamz[-1]} = 'k';# border back color
$_verbose_attrnamz{$_attrnamz[-1]} = 'WindowBorderBackgroundColor';
push(@_attrnamz, '_titl'); $_attrdata{$_attrnamz[-1]} = ''; # window title
$_verbose_attrnamz{$_attrnamz[-1]} = 'WindowTitle';
push(@_attrnamz, '_ttfc'); $_attrdata{$_attrnamz[-1]} = 'W';# title fore color
$self->{'_wind'} = newwin($self->{'_hite'}, $self->{'_widt'},
$self->{'_yoff'}, $self->{'_xoff'});
unless(exists($self->{'_wind'}) && defined($self->{'_wind'})){
exit();
# croak "!*EROR*! Curses::Simp::new could not create new window with hite:$self->{'_hite'}, widt:$self->{'_widt'}, yoff:$self->{'_yoff'}, xoff:$self->{'_xoff'}!\n";
}
}
# newwin doesn't auto draw so if there's init _text && autodraw is on...
$self->TestDraw();
$self->Move(-1, -1) unless($self->{'_ycrs'} || $self->{'_xcrs'});
curs_set($self->{'_flagcvis'}) if($curs); # set cursor state
# add new Simp object to display order stack
$self->{'_dndx'} = @DISPSTAK;
push(@DISPSTAK, \$self);
return($self);
}
sub FETCH { return( $_[0]->{'_text'}->[$_[1]]); }
sub FETCHSIZE { return(scalar(@{$_[0]->{'_text'}}) ); }
sub STORE {
$_[0]->{'_text'}->[$_[1]] = $_[2];
$_[0]->TestDraw();
$self->{$attr} = $nvkr->{$attr} if($nobj); } for(@KMODNAMZ){ $self->{'_kmod'}->{$_} = 0; }
if(defined($cork) && $cork !~ /::/){ $nvkr = shift if($nvkr =~ /::/); while(@_){ my $foun = 0; ($keey, $valu)=(shift, shift); # handle init params with
for my $attr ($self->AttrNamz()){ if($attr =~ /$keey/i){ $self->{$attr} = $valu;$foun = 1; } } # no colons (classname)
unless( $foun){ for my $attr ($self->AttrNamz()){ if($_verbose_attrnamz{$attr} eq $keey){ $self->{$attr} = $valu; $foun = 1; } } # exact match
unless($foun){ croak "!*EROR*! Curses::Simp::new initialization key:$keey was not recognized!\n"; } } } }
$self->{'_flagshrk'} = 0 if($self->{'_hite'} && $self->{'_widt'}); $self->Updt(1);
if($curs){ $self->{'_wind'} = newwin($self->{'_hite'}, $self->{'_widt'}, $self->{'_yoff'}, $self->{'_xoff'});
unless(exists($self->{'_wind'}) && defined($self->{'_wind'})){ exit;
#croak "!*EROR*! Curses::Simp::new could not create window with hite:$self->{'_hite'},widt:$self->{'_widt'},yoff:$self->{'_yoff'},xoff:$self->{'_xoff'}!\n";
} } $self->TestDraw(); $self->Move(-1, -1) unless($self->{'_ycrs'} || $self->{'_xcrs'}); # newwin does!autodraw so if therz init _text && autodraw is on...
curs_set($self->{'_flagcvis'}) if($curs); $self->{'_dndx'} = @DISPSTAK; push(@DISPSTAK, \$self); return($self); } # set cursor state,push obj2stack,&&retn
sub Prnt{ # Simp object PrintString method
my $self = shift; my %parm; my($ycrs, $xcrs); my($keey, $valu);
my($cnum, $delt, $chrz); my($yold, $xold); my($fgcl, $bgcl); my $foun;
$parm{'nore'} = 0; # No Refresh flag init'd to false
$parm{'ycrs'} = $self->{'_ycrs'};
$parm{'xcrs'} = $self->{'_xcrs'};
if($self->{'_btyp'}) { $parm{'ycrs'}++; $parm{'xcrs'}++; }
$parm{'prin'} = $self->{'_flagprin'}; # init prin param
while(@_){ ($keey, $valu)=(shift, shift); $foun = 0; if(defined($valu)){ # load params
for my $attr ($self->AttrNamz()){ if($_verbose_attrnamz{$attr} eq $keey){ $attr =~ s/^_*//; $parm{$attr} = $valu; $foun = 1; } } # exact match
$self->BordChar('vl', 1); $self->{'_wind'}->addstr('..');
}
$self->{'_wind'}->move(($self->{'_hite'} - 2), ($self->{'_widt'} - 4));
$self->BordChar('vl', 1); $self->{'_wind'}->addstr('\/');
$self->{'_wind'}->move(($self->{'_hite'} - 1), ($self->{'_widt'} - 4));
$self->BordChar('bt', 1);
}
}
unless($curs){ close(SCRP); system("call C:\\SimpDraw.bat"); }
$self->{'_valudol8'} = $dol8 if(defined($dol8));
$self->Move(); # replace cursor position && refresh the window
return();
}
sub TestDraw{ # Test whether an auto-Draw() should be called
$_[0]->Draw() if($_[0]->{'_text'} && @{$_[0]->{'_text'}} && $_[0]->{'_flagaudr'});
}
sub Wait{
my $self = shift; my $wait = 0;
my($keey, $valu); my $foun;
while(@_){ # load key/vals like new()
($keey, $valu)=(shift, shift); $foun = 0;
}
}
for(@KMODNAMZ){
if(/$kmod$/i){
$valu = shift;
$self->{'_kmod'}->{$_} = $valu if(defined($valu));
return($self->{'_kmod'}->{$_});
}
}
}
sub GetS{ # Get a string at the cursor or pass temp y, x, and length params
my $self = shift(); # maybe GetS() should update the cursor loc too?
my $ycrs = shift(); $ycrs = $self->YCrs() unless(defined($ycrs));
my $xcrs = shift(); $xcrs = $self->XCrs() unless(defined($xcrs));
my $leng = shift();
my $line = $self->{'_text'}->[$ycrs]; $line = '' unless(defined($line));
if(length($line) >= $xcrs){
if(defined($leng) && $leng <= (length($line) - $xcrs)){
return(substr($line, $xcrs, $leng));
}else{
return(substr($line, $xcrs));
}
}
}
sub Move{ # update cursor position
my $self = shift; my($ycrs, $xcrs)=(shift, shift); my $eflg = 0;
if(defined($ycrs) && defined($xcrs)){ # (-1, -1) is a special Move exception to put cursor in lower right corner of border (if BTyp)
if($ycrs == -1 && $xcrs == -1){ $eflg = 1;
$ycrs = ($self->{'_hite'}-1);
$xcrs = ($self->{'_widt'}-1);
}
}else{
$ycrs = $self->{'_ycrs'} unless(defined($ycrs));
$xcrs = $self->{'_xcrs'} unless(defined($xcrs));
}
$ycrs = 0 if($ycrs < 0);
$xcrs = 0 if($xcrs < 0);
if($self->{'_btyp'}){ # trap cursor inside border
if (($ycrs == $self->{'_hite'}-1 &&
$xcrs == $self->{'_widt'}-2) ||
($ycrs == $self->{'_hite'}-2 &&
$xcrs == $self->{'_widt'}-1)){
$ycrs = $self->{'_hite'}-2;
$xcrs = $self->{'_widt'}-2;
}elsif(!$eflg){ $ycrs++; $xcrs++;
$ycrs = $self->{'_hite'}-2 if($ycrs > $self->{'_hite'}-2);
$xcrs = $self->{'_widt'}-2 if($xcrs > $self->{'_widt'}-2);
}
# completely temporary Message window.
# If params are supplied, they must be hash key => value pairs.
sub Mesg{
my $main = shift; my($keey, $valu); my $char = -1;
my $self = bless({}, ref($main));
for my $attr ($self->AttrNamz()){
$self->{$attr} = $self->DfltValu($attr); # init defaults
}
# special Mesg window defaults
$self->{'_flagmaxi'} = 0; # not maximized
$self->{'_flagcvis'} = 0; # don't show cursor
$self->{'_flagclru'} = $main->{'_flagclru'}; # inherit ColorUsed flag
$self->{'_mesg'} = '';#EROR!';
$self->{'_text'} = [ ];
if($self->{'_flagclru'}){
$self->{'_fclr'} = [ 'C' ];
$self->{'_bclr'} = [ 'u' ];
}
$self->{'_titl'} = 'Message:';
$self->{'_ttfc'} = 'G';
$self->{'_ttbc'} = 'k';
}
}
$self->{'_flagshrk'} = 0 if($self->{'_hite'} && $self->{'_widt'});
$self->Updt(1);
$self->{'_wind'} = newwin($self->{'_hite'}, $self->{'_widt'},
$self->{'_yoff'}, $self->{'_xoff'});
unless(exists($self->{'_wind'}) && defined($self->{'_wind'})){
exit;
# croak "!*EROR*! Curses::Simp::Mesg could not create new window with hite:$self->{'_hite'}, widt:$self->{'_widt'}, yoff:$self->{'_yoff'}, xoff:$self->{'_xoff'}!\n";
}
$self->FlagCVis(); # set cursor visibility to new object state
$self->TestDraw();
if ($self->{'_flagprsk'}){
if($self->{'_wait'}) { $char = $self->GetK($self->{'_wait'}); }
else { $char = $self->GetK(-1); }
$char = '#' . $char if($self->{'_kmod'}->{'KMOD_SHIFT'});
$char = '^' . $char if($self->{'_kmod'}->{'KMOD_CTRL' });
$char = '@' . $char if($self->{'_kmod'}->{'KMOD_ALT' });
}elsif($self->{'_wait'}){
$self->Wait($self->{'_wait'});
}
$self->{'_dndx'} = @DISPSTAK; # add object to display order stack
push(@DISPSTAK, \$self);
if($self->{'_type'} =~ /^(butn|ckbx)$/){
return($self); # special types Button && CheckBox persist
}else{
$self->DelW();
$main->ShokScrn(2);# redraw rest
$main->FlagCVis(); # reset cursor visibility to calling object state
return($char); # return character pressed to dismiss Mesg (if any)
}
}
# Prmt() is a special Curses::Simp object constructor which creates a
# completely temporary Prompt window.
# If params are supplied, they must be hash key => value pairs.
sub Prmt{
my $main = shift; my($keey, $valu); my $char; my $tchr; my $data;
my $self = bless({}, ref($main)); my $twid; my $indx;
for my $attr ($self->AttrNamz()){
$self->{$attr} = $self->DfltValu($attr); # init defaults
}
# special Prmt window defaults
$self->{'_flagsdlk'} = 1; # get SDLKeys
$self->{'_flagmaxi'} = 0; # not maximized
$self->{'_flagcvis'} = 1; # show cursor
$self->{'_flagedit'} = 1; # editable
$self->{'_flagescx'} = 0; # Escape key eXits
$self->{'_flagclru'} = $main->{'_flagclru'}; # inherit ColorUsed flag
$self->{'_widt'} = getmaxx() - 4; # but almost full screen wide
$self->{'_hite'} = 3; # && start 1 text line high
# $self->{'_dref'} = \$data; # default text data ref !exist at start
$self->{'_dtxt'} = '';
$self->{'_text'} = [ ];
$self->{'_dtfc'} = 'G';
$self->{'_dtbc'} = 'u';
if($self->{'_flagclru'}){
$self->{'_fclr'} = [ $self->{'_dtfc'} ];
$self->{'_bclr'} = [ $self->{'_dtbc'} ];
}
$self->{'_titl'} = 'Enter Text:';
$self->{'_ttfc'} = 'C';
$self->{'_ttbc'} = 'k';
$self->{'_hifc'} = 'W';
$self->{'_hibc'} = 'g';
$self->{'_curs'} = 0; # special prompt cursor index
$self->{'_sscr'} = 0; # special prompt side-scrolling index
$self->{'_type'} = 'prmt'; # type can be set to special prompt types
# like 'drop', 'cbls', or 'rdls'
$self->{'_lndx'} = 0; # special line index for drop down types
$self->{'_elmo'} = ''; # special field to make this Prmt an ELeMent Of
for(@KMODNAMZ){ $self->{'_kmod'}->{$_} = 0; }
# there were init params with no colon (classname)
while(@_){
($keey, $valu)=(shift, shift);
if(defined($valu)) {
}
$self->{'_ycrs'} = 0;
$self->{'_xcrs'} = $self->{'_curs'};
$self->{'_flagshrk'} = 0 if($self->{'_hite'} && $self->{'_widt'});
$self->Updt(1);
$self->{'_wind'} = newwin($self->{'_hite'}, $self->{'_widt'},
$self->{'_yoff'}, $self->{'_xoff'});
unless(exists($self->{'_wind'}) && defined($self->{'_wind'})){
croak "!*EROR*! Curses::Simp::Prmt could not create new window with hite:$self->{'_hite'}, widt:$self->{'_widt'}, yoff:$self->{'_yoff'}, xoff:$self->{'_xoff'}!\n";
}
$self->FlagCVis(); # set cursor visibility to new object state
$self->TestDraw();
$self->{'_dndx'} = @DISPSTAK; # add object to display order stack
push(@DISPSTAK, \$self);
if($self->{'_type'} =~ /^(drop)$/){
return($self); # $self must be given explicit focus via Focu()
}else{
$self->Focu(); # give Prompt focus (to handle GetK loops)
${$self->{'_dref'}} = $self->{'_data'} if(exists($self->{'_dref'}));
$data = $self->{'_data'};
$self->DelW();
$main->ShokScrn(2);# redraw rest
$main->FlagCVis(); # reset cursor visibility to calling object state
return($data); # return updated text data
}
}
# Focu() is a Curses::Simp method which give focus to special
# typed objects like CheckBoxes or DropDownMenus.
# Maybe later, it will change the border type / color of normal
# Simp object windows as they gain focus.
sub Focu{
my $self = shift; return() unless(exists($self->{'_type'}));
my $updt = shift || 0; my $char = -1; my $tchr;
$self->{'_bclr'}->[0] = $self->{'_hibc'};
}
$self->{'_curs'} = length($self->{'_data'});
$self->{'_echg'} = 1 if($self->{'_elmo'} eq 'brws');
}
}elsif($self->{'_flagedit'} && $self->{'_curs'}){ # lowercase
my $temp = substr($self->{'_data'}, $self->{'_curs'}, 1);
substr($self->{'_data'}, $self->{'_curs'}, 1, lc($temp));
}
}elsif($self->{'_flagedit'}){
if ($tchr eq 'LEFT' ) { # move cursor left
if($self->{'_curs'}) {
$self->{'_curs'}--;
$self->{'_sscr'}-- if($self->{'_sscr'});
}
$cmov = 1;
}elsif($tchr eq 'RIGHT'){ # move cursor right
if($self->{'_curs'} < length($self->{'_data'})){
$self->{'_curs'}++;
}
$cmov = 1;
}elsif($tchr eq 'HOME' ){ # move cursor to beginning
$self->{'_curs'} = 0;
$self->{'_sscr'} = 0 if($self->{'_sscr'});
$cmov = 1;
}elsif($tchr eq 'END' ){ # move cursor to end
$self->{'_curs'} = length($self->{'_data'});
if(length($self->{'_data'}) < $self->{'_widt'} - 2){
$self->{'_sscr'} = (length($self->{'_data'}) - $self->{'_widt'} - 2);
}
$cmov = 1;
}elsif($tchr eq 'INSERT'){
$self->FlagInsr('togl');
if($self->FlagInsr){ $self->{'_titl'} =~ s/\[O\]$//; }
else { $self->{'_titl'} .= '[O]';
unless($self->Widt() > length($self->Titl()) + 4){
my $cmov;my $pick;my $done = 0;
# ' ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿','ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞß',
my @bchz = ( 'X', '@', '#', '$', 'Û', '²', '±', '°'); # block chars
my @styz = ( 'barz', 'blox', 'squr' ); # color display styles
for my $attr($self->AttrNamz()){
$self->{$attr} = $self->DfltValu($attr); # init defaults
}
# special CPik window defaults
$self->{'_flagsdlk'} = 1; # get SDLKeys
$self->{'_flagmaxi'} = 0; # not maximized
$self->{'_flagcvis'} = 1; # show cursor
$self->{'_flagbakg'} = 1; # pick background colors
$self->{'_flagforg'} = 1; # pick foreground colors
$self->{'_flagclru'} = $main->{'_flagclru'}; # inherit ColorUsed flag
# $self->{'_widt'} = getmaxx() - 4; # but almost full screen wide
# $self->{'_hite'} = getmaxy() - 4; # && high
$self->{'_text'} = [ ' ' ];
$self->{'_dtfc'} = 'G';
$self->{'_dtbc'} = 'u';
if($self->{'_flagclru'}){
$self->{'_fclr'} = [ $self->{'_dtfc'} ];
}
$self->{'_ycrs'} = $self->{'_hndx'};
$self->{'_xcrs'} = 0;
$self->{'_flagshrk'} = 0 if($self->{'_hite'} && $self->{'_widt'});
$self->Updt(1);
$self->{'_wind'} = newwin($self->{'_hite'}, $self->{'_widt'},
$self->{'_yoff'}, $self->{'_xoff'});
unless(exists($self->{'_wind'}) && defined($self->{'_wind'})){
croak "!*EROR*! Curses::Simp::CPik could not create new window with hite:$self->{'_hite'}, widt:$self->{'_widt'}, yoff:$self->{'_yoff'}, xoff:$self->{'_xoff'}!\n";
}
$self->FlagCVis(); # set cursor visibility to new object state
$self->BildBlox(); # build color block data into @text,@fclr,@bclr && Draw()
$self->Move($self->{'_hndx'}, 0);
while(!defined($char) || !$done){
$char = $self->GetK(-1);
if($char =~ /^SDLK_(RETURN|[0-9A-FRGYUPW])$/i){ # gonna be done
$char =~ s/^SDLK_//;
if ($char =~ /^[BRGYUPCW]$/i){
$pick = $char;
$pick = uc($pick) if($self->{'_kmod'}->{'KMOD_SHIFT'});
}else{
$self->{'_hndx'} = 16 unless($self->{'_hndx'});
$self->{'_hndx'}--;
}elsif($tchr eq 'RIGHT'){
$self->{'_hndx'}++;
$self->{'_hndx'} = 0 if($self->{'_hndx'} == 16);
}
} $self->BildBlox();
}
} delwin($self->{'_wind'}); # delete the CPik window, redraw rest
$main->ShokScrn(2);
$main->FlagCVis(); # reset cursor visibility to calling object state
return($pick); # return picked color code
}
sub BrwsHelp{ # BrwsHelp() just prints a help text message for Brws()
my $self = shift;
$self->Mesg('type' => 'help',
'titl' => 'File / Directory Browser Help: (F1)',
"This Browser dialog exists to make it easy to choose a file (or directory).
You can <TAB> between elements. Ctrl-I and TAB are interpreted as the same
key by Curses so either one can be pressed to cycle forward through Browse
# =C is configure wrench for new dialog of all toggles (&& hotkeys)
# md is mkdir dialog
# \/ drop down bar to show recent or common options
# .. is `cd ..`
# ?? is help / F1
# ==== box is highlighted (Enter selects)
# Ultimately, Brws() should be able to handle easy Browsing for
# Files or Directories for any Open/SaveAs/etc. purposes
sub BildBrws{
my $self = shift; my $updt = shift || 0; my $indx;
$self->FlagCVis(); # set cursor visibility to main Brws object state
$self->Draw();
for($indx=0;$indx<@{$self->{'_elem'}};$indx++){
if(!$self->{'_eflz'}->{$self->{'_elem'}->[$self->{'_endx'}]}){
$self->{'_endx'}++;
$self->{'_endx'} = 0 if($self->{'_endx'} == @{$self->{'_elem'}});
}
} # this for && below if make sure a visible element is indexed
if(!$self->{'_eflz'}->{$self->{'_elem'}->[$self->{'_endx'}]}){
$self->{'_eflz'}->{$self->{'_elem'}->[$self->{'_endx'}]} = 1;
}
# If params are supplied, they must be hash key => value pairs.
sub Brws{
my $main = shift; my($keey, $valu); my $char; my $tchr; my $choi = '';
my $self = bless({}, ref($main)); my $indx; my $done = 0;
for my $attr($main->AttrNamz()){
$self->{$attr} = $main->DfltValu($attr); # init defaults
}
# special Brws window defaults
$self->{'_flagsdlk'} = 1; # get SDLKeys
$self->{'_flagmaxi'} = 0; # not maximized
$self->{'_flagcvis'} = 0; # don't show cursor
$self->{'_flagview'} = 0; # show 0=short (1=detailed) view
$self->{'_flaghide'} = 0; # don't hide .files by default
$self->{'_flagquik'} = 0; # don't show quick access panel
$self->{'_flagsepd'} = 0; # don't show separate directory pane
$self->{'_flagflhi'} = 1; # HIghlight FiLes in browser view
$self->{'_flagbgho'} = 1; # BackGround Highlight Only in view
$self->{'_flagclru'} = $main->{'_flagclru'}; # inherit ColorUsed flag
$self->{'_widt'} = getmaxx() - 4; # but almost full screen wide
$self->{'_hite'} = getmaxy() - 4; # && high
$self->{'_text'} = [ ' ' ];
$self->{'_bobj'}->{'_path'}->{'_curs'} = length($self->{'_path'});
$self->{'_bobj'}->{'_path'}->{'_xcrs'} = length($self->{'_path'});
$self->{'_bobj'}->{'_path'}->{'_echg'} = 1;
$self->BildBrws(1);
$done = 0; # don't accept directory when choosing file
}
}
}
$self->DelW(); # Delete Brws Window && all element windows
$main->ShokScrn(2); # redraw all old stuff
$main->FlagCVis(); # reset cursor visibility to calling object state
return($choi); # return choice (file or dir name)
}
sub DESTROY{
my $self = shift || return(); my $dndx = $self->{'_dndx'};
my $shok = 1;
$shok = 0 if(exists($self->{'_type'}) && length($self->{'_type'}));
if($self->{'_wind'}){
delwin($self->{'_wind'});
for(++$dndx;$dndx<@DISPSTAK;$dndx++){
if($DISPSTAK[$dndx] && exists(${$DISPSTAK[$dndx]}->{'_dndx'})){
=item - Prmt: add multi-line option where dtxt can split on /\n/ && ^d
accepts entry instead of RETURN
=item - Prnt: handle ASCII chars under 32 with escapes like Draw
=item - Draw: optimize rendering
=item - Prnt&&Draw: handle ASCII chars under 32 better than current escapes
=item - mk 'ceol' && 'ceos' params to clear text[n] from cursor on
=item - consider breaking sub (CPik|Brws|.+?) into own Curses::Simp::$1.pm
instead of letting Simp.pm remain so cluttered
=back
if detectable:
=over 4
Returns the current Simp object's window height
(last index: Height() - 1)
=head2 Widt or Width
Returns the current Simp object's window width
(last index: Width() - 1)
=head2 Prnt or PrintString( $String )
Prints $String at current cursor position. PrintString() can also accept
a hash of parameters (e.g., PrintString('text' => $String)) where:
'text' => [ "String to Print" ], # or can just be string without arrayref
'fclr' => [ "ForegroundColorCodes corresponding to text" ],
'bclr' => [ "BackgroundColorCodes corresponding to text" ],
'ycrs' => 3, # Number to move the cursor's y to before printing
'xcrs' => 7, # Number to move the cursor's x to before printing
'yoff' => 15, # same as ycrs except original ycrs is restored afterwards
'xoff' => 31, # same as xcrs except original xcrs is restored afterwards
'prin' => 1, # flag to specify whether printed text should update the
# main Text(), FClr(), and BClr() data or just print to the
# screen temporarily. Default is true (i.e., Print Into all)
The hash keys can also be the corresponding VerboseNames described in the
new() section instead of these 4-letter abbreviated key names.
PrintString() returns the number of characters printed.
Returns the key mode (state) of the key mode name $KeyName. $KeyName
should be one of the KMOD_ names from the bottom of the L<"SDLKEY NOTES">
section.
If no parameters are provided, the state of KMOD_NONE is returned.
If $NewValue is provided, the state of $KeyName is set to $NewValue.
=head2 GetS or GetString( [$YCursor, $XCursor[, $ResultLength]] )
GetString() returns the string found from the cursor (or the specified
coordinates) on to the end-of-line or to $ResultLength if provided.
=head2 Move or MoveCursor( [$YCursor, $XCursor] )
MoveCursor() updates the current Simp object's cursor position
to the newly specified $YCursor, $XCursor.
By default, the cursor is not visible but this can be changed through
the FlagCursorVisible(1) function.
Returns ($YCursor, $XCursor) as the coordinates of the cursor.
=head2 Rsiz or ResizeWindow( $Height, $Width )
ResizeWindow() updates the current Simp object's window dimensions
to the newly specified $Height, $Width.
Think of ResizeWindow() as an easy way to call both Height() and
Width() at once.
Returns ($Height, $Width) as the dimensions of the window.
'hifc' => "ColorCodes for highlighted (unedited) dref/dtxt foreground color",
'hibc' => "ColorCodes for highlighted (unedited) dref/dtxt background color",
'text' => [ "same as new \@text" ],
'fclr' => [ "ForegroundColorCodes corresponding to text" ],
'bclr' => [ "BackgroundColorCodes corresponding to text" ],
'hite' => 3, # height of the prompt window (including borders)
'widt' => 63, # width of the prompt window (including borders)
'titl' => "PromptWindow Title string",
'ttfc' => "ColorCodes corresponding to titl foreground color",
'ttbc' => "ColorCodes corresponding to titl background color",
'flagcvis' => 1, # a flag specifying whether the cursor should be displayed
The hash keys can also be the corresponding VerboseNames described in the
new() section instead of these 4-letter abbreviated key names.
=head2 CPik or ColorPickWindow()
ColorPickWindow() is a simple Color Picker window.
It accepts arrow keys to highlight a particular color and enter to select.
The letter corresponding to the color or the number of the index can also
=head3 BTyp or WindowBorderType
=head2 Normal Accessors
Name or VerboseName # Description
---- ----------- -------------
Hite or WindowHeight # window height
Widt or WindowWidth # window width
YOff or WindowYOffset # window y-offset position
XOff or WindowXOffset # window x-offset position
YCrs or CursorYOffset # window y-cursor position
XCrs or CursorXOffset # window x-cursor position
BrFC or WindowBorderForegroundColor # border fg color code string
BrBC or WindowBorderBackgroundColor # border bg color code string
Titl or WindowTitle # title string
TtFC or WindowTitleForegroundColor # title fg color code string
TtBC or WindowTitleBackgroundColor # title bg color code string
DNdx or DisplayStackIndex # global display index
=head3 Hite or WindowHeight
=head3 Widt or WindowWidth
#!/usr/bin/perl -w
# 37K2jPD - test.pl created by Pip@CPAN.Org to validate Curses::Simp functionality. This test.pl mimics that of Term::Screen by Mark Kaehny.
# Before `make install' is performed this script should be run with `make test'. After `make install' it should work as `perl test.pl'.
use Test; BEGIN { plan tests => 1 }
use Curses::Simp; ok(1);
my @text; my $simp = tie(@text, 'Curses::Simp', 'flagaudr' => 0);
push(@text, 'Test series for Simp.pm module for perl5'); # test output
$simp->Prnt('ycrs' => 2, 'xcrs' => 3, '1. Should be at row 2 col 3 (upper left is 0,0)'); # test cursor movement && output together
my $rowe = $simp->YCrs(); my $colm = $simp->XCrs();
$simp->Prnt('ycrs' => 3, 'xcrs' => 0, "2. Last position $rowe $colm -- should be 2 50."); # test current position update
$simp->Prnt('ycrs' => 4, 'xcrs' => 0, "3. Screen size: " . $simp->Hite() . " rows and " .
$simp->Widt() . " columns." ); # test rows && cols
$simp->Move(6, 0); $simp->Prnt('4. Testing reverse'); # test standout && normal text # no more reverse
$simp->Prnt('fclr' => 'wwwwwwwWWWWwwwwwww', # bold is done with uc() in Curses::Simp
' mode, bold mode, ');
$simp->Prnt(#'fclr' => 'bWWWWWWWWwwwwwwwww', # still no reverse though
'and both together.');
my $line = "0---------10--------20--------30--------40--------50--------60--------70------- "; # test clreol ... so first put some stuff up
( run in 0.495 second using v1.01-cache-2.11-cpan-4d50c553e7e )