Curses-UI-DelimitedTextViewer
view release on metacpan or search on metacpan
DelimitedTextViewer.pm view on Meta::CPAN
# Caclulate the widths of the columns
$obj->{'-widths'} = $obj->calculate_widths($userargs{'-text'});
$obj->{'-maxcolumns'} = scalar(@{$obj->{'-widths'}});
$obj->{'-current_column'} = 0;
# Turn the delimited text into fixed width text
$obj->{'-text'} = $obj->process_text($obj->{'-text'});
# Check to see if the user wants to scroll by column
if($userargs{'-columnScroll'}) {
$obj = $obj->set_routine('cursor-right', \&scroll_column_right);
$obj = $obj->set_routine('cursor-left', \&scroll_column_left);
}
return $obj;
}
###############################################################################
# process_text
# reformat the incoming text and get a list of the width of each delimited
# field. Store those widths for future scrolling
###############################################################################
DelimitedTextViewer.pm view on Meta::CPAN
unless(defined($column_widths[$i])) {
$column_widths[$i] = $length;
}
$column_widths[$i] = $length if($length > $column_widths[$i]);
}
}
return \@column_widths;
}
###############################################################################
# scroll the cursor by a column width at a time
###############################################################################
sub scroll_column_right {
my $self = shift;
# Check to make sure that the cursor is not already at the last
# column
return $self->dobeep
if($self->{'-current_column'} == $self->{'-maxcolumns'});
# Look up the current columns width and use that as the offset
my $index = $self->{'-current_column'};
my @widths = @{$self->{'-widths'}};
my $offset = $self->{'-widths'}->[$self->{'-current_column'}];
DelimitedTextViewer.pm view on Meta::CPAN
$self->{'-current_column'}++;
$self->{-xscrpos} += $offset;
$self->{-hscrollpos} = $self->{-xscrpos};
$self->{-xpos} = $self->{-xscrpos};
return $self;
}
###############################################################################
# scroll the cursor by a column width at a time
###############################################################################
sub scroll_column_left {
my $self = shift;
# Check to make sure that the cursor is not already at the first column
return $self->dobeep if($self->{'-current_column'} == 0);
# Look up the previous column's width and use that as the offset
my $index = $self->{'-current_column'};
$index--;
my $offset = $self->{'-widths'}->[$index];
# The first column should only be shifted the width the column
# whereas the others should be shifted the width of the column
( run in 0.285 second using v1.01-cache-2.11-cpan-4d50c553e7e )