| 1 | package Term::ReadLine::Perl5::OO::State; | ||
| 2 | =pod | ||
| 3 | |||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | Term::ReadLine::Perl5::OO:State | ||
| 7 | |||
| 8 | =head1 DESCRIPTION | ||
| 9 | |||
| 10 | Object to old the internal state of an editable line. Thas things like | ||
| 11 | the text of the line and cursor position, | ||
| 12 | |||
| 13 | =cut | ||
| 14 | |||
| 15 | |||
| 16 | use Class::Accessor::Lite 0.05 ( | ||
| 17 | rw => [qw(buf pos cols prompt oldpos maxrows query)], | ||
| 18 | ); | ||
| 19 | |||
| 20 | sub new { | ||
| 21 | my $class = shift; | ||
| 22 | bless { | ||
| 23 | buf => '', | ||
| 24 | pos => 0, | ||
| 25 | oldpos => 0, | ||
| 26 | maxrows => 0, | ||
| 27 | }, $class; | ||
| 28 | } | ||
| 29 | use Text::VisualWidth::PP 0.03 qw(vwidth); | ||
| 30 | |||
| 31 | sub len { length(shift->buf) } | ||
| 32 | sub plen { length(shift->prompt) } | ||
| 33 | |||
| 34 | sub vpos { | ||
| 35 | my $self = shift; | ||
| 36 | vwidth(substr($self->buf, 0, $self->pos)); | ||
| 37 | } | ||
| 38 | |||
| 39 | sub width { | ||
| 40 | my $self = shift; | ||
| 41 | vwidth($self->prompt . $self->buf); | ||
| 42 | } | ||
| 43 | |||
| 44 | 1; |