Caroline
view release on metacpan or search on metacpan
lib/Caroline.pm view on Meta::CPAN
my $plen = vwidth($state->prompt);
$self->debug($state->buf. "\n");
# rows used by current buf
my $rows = int(($plen + vwidth($state->buf) + $state->cols -1) / $state->cols);
if (defined $state->query) {
$rows++;
}
# cursor relative row
my $rpos = int(($plen + $state->oldpos + $state->cols) / $state->cols);
my $old_rows = $state->maxrows;
# update maxrows if needed.
if ($rows > $state->maxrows) {
$state->maxrows($rows);
}
$self->debug(sprintf "[%d %d %d] p: %d, rows: %d, rpos: %d, max: %d, oldmax: %d",
lib/Caroline.pm view on Meta::CPAN
if ($state->pos && $state->pos == $state->len && ($state->pos + $plen) % $state->cols == 0) {
$self->debug("<newline>");
print "\n";
print "\x1b[0G";
$rows++;
if ($rows > $state->maxrows) {
$state->maxrows(int $rows);
}
}
# Move cursor to right position
my $rpos2 = int(($plen + $state->vpos + $state->cols) / $state->cols); # current cursor relative row
$self->debug(sprintf ", rpos2 %d", $rpos2);
# Go up till we reach the expected position
if ($rows - $rpos2 > 0) {
# cursor up
printf "\x1b[%dA", $rows-$rpos2;
}
# Set column
my $col;
{
$col = 1;
my $buf = $state->prompt . substr($state->buf, 0, $state->pos);
for (split //, $buf) {
$col += vwidth($_);
lib/Caroline.pm view on Meta::CPAN
my $pos = $state->pos;
while ((vwidth($state->prompt)+$pos) >= $state->cols) {
substr($buf, 0, 1) = '';
$len--;
$pos--;
}
while (vwidth($state->prompt) + vwidth($buf) > $state->cols) {
$len--;
}
print STDOUT "\x1b[0G"; # cursor to left edge
print STDOUT $state->{prompt};
print STDOUT $buf;
print STDOUT "\x1b[0K"; # erase to right
# Move cursor to original position
printf "\x1b[0G\x1b[%dC", (
length($state->{prompt})
+ vwidth(substr($buf, 0, $pos))
);
}
sub edit_move_right {
my ($self, $state) = @_;
if ($state->pos != length($state->buf)) {
$state->{pos}++;
( run in 0.375 second using v1.01-cache-2.11-cpan-fd5d4e115d8 )