| 1 | package TUI::Editors::Indicator; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: indicator view which displays the editor cursor position | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 7 | our $VERSION = '2.000003'; | |||||||||||||||||||||||||||
| 10 | 7 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 11 | 7 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 7 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 15 | TIndicator | ||||||||||||||||||||||||||||
| 16 | new_TIndicator | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 7 | ▶ | use Encode qw( encode ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 7 | ▶ | use TUI::toolkit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use TUI::toolkit::Types qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | is_Object | ||||||||||||||||||||||||||||
| 23 | :types | ||||||||||||||||||||||||||||
| 24 | 7 | ); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 7 | ▶ | use TUI::Editors::Const qw( cpIndicator ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 7 | ▶ | use TUI::Objects::Point; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 7 | ▶ | use TUI::Views::Const qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | gfGrowHiY | ||||||||||||||||||||||||||||
| 30 | gfGrowLoY | ||||||||||||||||||||||||||||
| 31 | sfDragging | ||||||||||||||||||||||||||||
| 32 | 7 | ); | |||||||||||||||||||||||||||
| 33 | 7 | ▶ | use TUI::Views::DrawBuffer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 7 | ▶ | use TUI::Views::Palette; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 7 | ▶ | use TUI::Views::View; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub TIndicator() { __PACKAGE__ } | ||||||||||||||||||||||||||||
| 38 | sub name() { 'TIndicator' } | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub new_TIndicator { __PACKAGE__->from(@_) } | ||||||||||||||||||||||||||
|
Subroutine
new_TIndicator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 7 | extends TView; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # declare global variables | ||||||||||||||||||||||||||||
| 44 | 7 | our $dragFrame = encode( cp437 => "═" ); | |||||||||||||||||||||||||||
| 45 | 7 | our $normalFrame = encode( cp437 => "─" ); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # protected attributes | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | has location => ( is => 'ro', default => sub { TPoint->new } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 49 | 7 | has modified => ( is => 'ro', default => false ); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub BUILD { # void (\%args) | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 0 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | $self->{growMode} = gfGrowLoY | gfGrowHiY; | |||||||||||||||||||||||||||
| 56 | 0 | return; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub draw { # void () | ||||||||||||||||||||||||||
|
Subroutine
draw: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 61 | method => Object, | ||||||||||||||||||||||||||||
| 62 | pos => [], | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | 0 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my ( $color, $frame ); | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ( ( $self->{state} & sfDragging ) == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | $color = $self->getColor( 1 ); | |||||||||||||||||||||||||||
| 69 | 0 | $frame = $dragFrame; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | else { | ||||||||||||||||||||||||||||
| 72 | 0 | $color = $self->getColor( 2 ); | |||||||||||||||||||||||||||
| 73 | 0 | $frame = $normalFrame; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | my $b = TDrawBuffer->new(); | |||||||||||||||||||||||||||
| 77 | 0 | $b->moveChar( 0, $frame, $color, $self->{size}{x} ); | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | $b->putChar( 0, chr( 15 ) ) if $self->{modified}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # Borland's C++ implementation buffer of 15 bytes holds at most 14 characters | ||||||||||||||||||||||||||||
| 81 | my $s = substr( | ||||||||||||||||||||||||||||
| 82 | 0 | sprintf( ' %d:%d ', $self->{location}{y} + 1, $self->{location}{x} + 1 ), | |||||||||||||||||||||||||||
| 83 | 0, 14 | ||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||
| 85 | 0 | $b->moveCStr( 8 - index( $s, ':' ), $s, $color ); | |||||||||||||||||||||||||||
| 86 | 0 | $self->writeBuf( 0, 0, $self->{size}{x}, 1, $b ); | |||||||||||||||||||||||||||
| 87 | 0 | return; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub getPalette { # $palette () | ||||||||||||||||||||||||||
|
Subroutine
getPalette: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 92 | method => Object, | ||||||||||||||||||||||||||||
| 93 | pos => [], | ||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||
| 95 | 0 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 96 | 0 | state $palette = TPalette->new( | |||||||||||||||||||||||||||
| 97 | data => cpIndicator, | ||||||||||||||||||||||||||||
| 98 | size => length( cpIndicator ), | ||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||
| 100 | 0 | return $palette->clone(); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub setState { # void ($aState, $enable) | ||||||||||||||||||||||||||
|
Subroutine
setState: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 105 | method => Object, | ||||||||||||||||||||||||||||
| 106 | pos => [PositiveOrZeroInt, Bool], | ||||||||||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||||||||||
| 108 | 0 | my ( $self, $aState, $enable ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 109 | 0 | $self->SUPER::setState( $aState, $enable ); | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ( $aState == sfDragging ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | $self->drawView(); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 0 | return; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub setValue { # void ($aLocation, $aModified) | ||||||||||||||||||||||||||
|
Subroutine
setValue: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 118 | method => Object, | ||||||||||||||||||||||||||||
| 119 | pos => [Object, Bool], | ||||||||||||||||||||||||||||
| 120 | ); | ||||||||||||||||||||||||||||
| 121 | 0 | my ( $self, $aLocation, $aModified ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ( $self->{location} != $aLocation || $self->{modified} != $aModified ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"location"} != $aLocation or $self->{"modified"} != $aModified
MC/DC0%0/2
$self->{"location"} != $aLocation or $self->{"modified"} != $aModified
$self->{"location"} != $aLocation
$self->{"modified"} != $aModified
Truth table0%0/3
A or B
A= $self->{"location"} != $aLocationB= $self->{"modified"} != $aModified
| |||||||||||||||||||||||||||||
| 123 | 0 | $self->{location} = $aLocation->clone(); | |||||||||||||||||||||||||||
| 124 | 0 | $self->{modified} = $aModified; | |||||||||||||||||||||||||||
| 125 | 0 | $self->drawView(); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 0 | return; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 7 | 1 | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||||||||||