| 1 | package TUI::Editors::Editor::Edits; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: TEditor buffer and line functions (1:1 port) | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 14 | our $VERSION = '2.000003'; | |||||||||||||||||||||||||||
| 9 | 14 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 10 | 14 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 14 | ▶ | use PerlX::Assert::PP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 14 | ▶ | use Terminal::WCWidth qw( wcwidth ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 14 | ▶ | use TUI::toolkit::Types qw( :is ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub TUI::Editors::Editor::bufChar { # $char ($self, $P) | ||||||||||||||||||||||||||
|
Subroutine
bufChar: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 0 | my ( $self, $P ) = @_; | |||||||||||||||||||||||||||
| 18 | 0 | assert ( @_ == 2 ); | |||||||||||||||||||||||||||
| 19 | 0 | assert ( is_Object $self ); | |||||||||||||||||||||||||||
| 20 | 0 | assert ( is_PositiveOrZeroInt $P ); | |||||||||||||||||||||||||||
| 21 | 0 | return substr( $self->{buffer}, $P, 1 ); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub TUI::Editors::Editor::bufPtr { # $pos ($self, $P) | ||||||||||||||||||||||||||
|
Subroutine
bufPtr: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 0 | my ( $self, $P ) = @_; | |||||||||||||||||||||||||||
| 26 | 0 | assert ( @_ == 2 ); | |||||||||||||||||||||||||||
| 27 | 0 | assert ( is_Object $self ); | |||||||||||||||||||||||||||
| 28 | 0 | assert ( is_PositiveOrZeroInt $P ); | |||||||||||||||||||||||||||
| 29 | 0 | return $P; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub TUI::Editors::Editor::formatLine { # void ($self, $b, $linePtr, $width, $colors) | ||||||||||||||||||||||||||
|
Subroutine
formatLine: not called CC=15 SCAR=54.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 0 | my ( $self, $b, $linePtr, $width, $colors ) = @_; | |||||||||||||||||||||||||||
| 34 | 0 | assert ( @_ == 5 ); | |||||||||||||||||||||||||||
| 35 | 0 | assert ( is_Object $self ); | |||||||||||||||||||||||||||
| 36 | 0 | assert ( is_Object $b ); | |||||||||||||||||||||||||||
| 37 | 0 | assert ( is_PositiveOrZeroInt $linePtr ); | |||||||||||||||||||||||||||
| 38 | 0 | assert ( is_Int $width ); | |||||||||||||||||||||||||||
| 39 | 0 | assert ( is_PositiveInt $colors ); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | my $P = $linePtr; | |||||||||||||||||||||||||||
| 42 | 0 | my $selStart = $self->{selStart}; | |||||||||||||||||||||||||||
| 43 | 0 | my $selEnd = $self->{selEnd}; | |||||||||||||||||||||||||||
| 44 | 0 | my $cNorm = $colors & 0xFF; | |||||||||||||||||||||||||||
| 45 | 0 | my $cSel = $colors >> 8; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | my $eol = $self->lineEnd( $P ); | |||||||||||||||||||||||||||
| 48 | 0 | my $x = 0; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | while ( $P < $eol ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | my $ch = $self->bufChar( $P ); | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $color = ( $selStart <= $P && $P < $selEnd ) ? $cSel : $cNorm; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$selStart <= $P and $P < $selEnd
MC/DC0%0/2
$selStart <= $P and $P < $selEnd
$selStart <= $P
$P < $selEnd
Truth table0%0/3
A and B
A= $selStart <= $PB= $P < $selEnd
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( $ch eq "\t" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | last if $x >= $width; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | my $next = ( $x | 7 ) + 1; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | $next = $width if $next > $width; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | $b->moveChar( $x, ' ', $color, $next - $x ); | |||||||||||||||||||||||||||
| 60 | 0 | $x = $next; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||
| 63 | 0 | my $w = wcwidth( ord $ch ); | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | $w = 1 if $w < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | last if $x > $width; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | last if $x == $width && $w > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$x == $width and $w > 0
MC/DC0%0/2
$x == $width and $w > 0
$x == $width
$w > 0
Truth table0%0/3
A and B
A= $x == $widthB= $w > 0
| |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | last if $x + $w > $width; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | $b->moveStr( $x, $ch, $color ); | |||||||||||||||||||||||||||
| 71 | 0 | $x += $w; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ++$P; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ( $x < $width ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my $color = $selStart <= $P && $P < $selEnd ? $cSel : $cNorm; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$selStart <= $P and $P < $selEnd
MC/DC0%0/2
$selStart <= $P and $P < $selEnd
$selStart <= $P
$P < $selEnd
Truth table0%0/3
A and B
A= $selStart <= $PB= $P < $selEnd
| |||||||||||||||||||||||||||||
| 79 | 0 | $b->moveChar( $x, ' ', $color, $width - $x ); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | return; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub TUI::Editors::Editor::lineEnd { # $pos ($self, $p) | ||||||||||||||||||||||||||
|
Subroutine
lineEnd: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 0 | my ( $self, $p ) = @_; | |||||||||||||||||||||||||||
| 87 | 0 | assert ( @_ == 2 ); | |||||||||||||||||||||||||||
| 88 | 0 | assert ( is_Object $self ); | |||||||||||||||||||||||||||
| 89 | 0 | assert ( is_PositiveOrZeroInt $p ); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | my $len = $self->bufLen; | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | return $len | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | if $p >= $len; | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | pos( $self->{buffer} ) = $p; | |||||||||||||||||||||||||||
| 96 | 0 | $self->{buffer} =~ /\G(?:(?!\R).)*+/gcs; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | return pos( $self->{buffer} ); | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub TUI::Editors::Editor::lineStart { # $pos ($self, $p) | ||||||||||||||||||||||||||
|
Subroutine
lineStart: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | 0 | my ( $self, $p ) = @_; | |||||||||||||||||||||||||||
| 103 | 0 | assert ( @_ == 2 ); | |||||||||||||||||||||||||||
| 104 | 0 | assert ( is_Object $self ); | |||||||||||||||||||||||||||
| 105 | 0 | assert ( is_PositiveOrZeroInt $p ); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | state $chunkSize = 256; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | return 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | if $p <= 0; | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | my $end = $p; | |||||||||||||||||||||||||||
| 113 | 0 | ▶ | while ( $end > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | my $start = $end - $chunkSize; | |||||||||||||||||||||||||||
| 115 | 0 | ▶ | $start = 0 if $start < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | my $chunk = substr( $self->{buffer}, $start, $end - $start ); | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | return $start + $+[0] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | if $chunk =~ /.*\R/gs; | ||||||||||||||||||||||||||||
| 119 | 0 | $end = $start; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | return 0; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub TUI::Editors::Editor::nextChar { # $pos ($self, $p) | ||||||||||||||||||||||||||
|
Subroutine
nextChar: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | 0 | my ( $self, $p ) = @_; | |||||||||||||||||||||||||||
| 127 | 0 | assert ( @_ == 2 ); | |||||||||||||||||||||||||||
| 128 | 0 | assert ( is_Object $self ); | |||||||||||||||||||||||||||
| 129 | 0 | assert ( is_PositiveOrZeroInt $p ); | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | my $len = $self->bufLen; | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | return $len | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | if $p >= $len; | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | pos( $self->{buffer} ) = $p; | |||||||||||||||||||||||||||
| 136 | return pos( $self->{buffer} ) | ||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if $self->{buffer} =~ /\G\R/gc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | return $p + 1; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub TUI::Editors::Editor::nextLine { # $pos ($self, $p) | ||||||||||||||||||||||||||
|
Subroutine
nextLine: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 143 | 0 | my ( $self, $p ) = @_; | |||||||||||||||||||||||||||
| 144 | 0 | assert ( @_ == 2 ); | |||||||||||||||||||||||||||
| 145 | 0 | assert ( is_Object $self ); | |||||||||||||||||||||||||||
| 146 | 0 | assert ( is_PositiveOrZeroInt $p ); | |||||||||||||||||||||||||||
| 147 | 0 | return $self->nextChar( $self->lineEnd( $p ) ); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub TUI::Editors::Editor::prevChar { # $pos ($self, $p) | ||||||||||||||||||||||||||
|
Subroutine
prevChar: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 151 | 0 | my ( $self, $p ) = @_; | |||||||||||||||||||||||||||
| 152 | 0 | assert ( @_ == 2 ); | |||||||||||||||||||||||||||
| 153 | 0 | assert ( is_Object $self ); | |||||||||||||||||||||||||||
| 154 | 0 | assert ( is_PositiveOrZeroInt $p ); | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | return 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | if $p <= 0; | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if ( $p >= 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 0 | pos( $self->{buffer} ) = $p - 2; | |||||||||||||||||||||||||||
| 161 | return $p - 2 | ||||||||||||||||||||||||||||
| 162 | if $self->{buffer} =~ /\G\R/gc | ||||||||||||||||||||||||||||
| 163 | 0 | ▶ | && pos( $self->{buffer} ) == $p; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"buffer"} =~ /\G\R/cg and pos $self->{"buffer"} == $p
MC/DC0%0/2
$self->{"buffer"} =~ /\G\R/cg and pos $self->{"buffer"} == $p
$self->{"buffer"} =~ /\G\R/cg
pos $self->{"buffer"} == $p
Truth table0%0/3
A and B
A= $self->{"buffer"} =~ /\G\R/cgB= pos $self->{"buffer"} == $p
| |||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | return $p - 1; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub TUI::Editors::Editor::prevLine { # $pos ($self, $p) | ||||||||||||||||||||||||||
|
Subroutine
prevLine: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 170 | 0 | my ( $self, $p ) = @_; | |||||||||||||||||||||||||||
| 171 | 0 | assert ( @_ == 2 ); | |||||||||||||||||||||||||||
| 172 | 0 | assert ( is_Object $self ); | |||||||||||||||||||||||||||
| 173 | 0 | assert ( is_PositiveOrZeroInt $p ); | |||||||||||||||||||||||||||
| 174 | 0 | return $self->lineStart( $self->prevChar( $p ) ); | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 14 | 1 | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | __END__ | ||||||||||||||||||||||||||||