| 1 | package TUI::TextView::Terminal; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: TTerminal is a simple text view class | ||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 8 | 7 | our $VERSION = '2.000002'; | |||||||||||||||||||||||||||
| 9 | 7 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 10 | 7 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 7 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 14 | TTerminal | ||||||||||||||||||||||||||||
| 15 | new_TTerminal | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 7 | require bytes; | |||||||||||||||||||||||||||
| 19 | 7 | ▶ | use List::Util qw( min max ); | ||||||||||||||||||||||||||
|
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 | Maybe | ||||||||||||||||||||||||||||
| 23 | :is | ||||||||||||||||||||||||||||
| 24 | :types | ||||||||||||||||||||||||||||
| 25 | 7 | ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 7 | ▶ | use TUI::Views::Const qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | gfGrowHiX | ||||||||||||||||||||||||||||
| 29 | gfGrowHiY | ||||||||||||||||||||||||||||
| 30 | maxViewWidth | ||||||||||||||||||||||||||||
| 31 | 7 | ); | |||||||||||||||||||||||||||
| 32 | 7 | ▶ | use TUI::Views::DrawBuffer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 7 | ▶ | use TUI::TextView::TextDevice; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub TTerminal() { __PACKAGE__ } | ||||||||||||||||||||||||||||
| 36 | sub name() { 'TTerminal' } | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub new_TTerminal { __PACKAGE__->from(@_) } | ||||||||||||||||||||||||||
|
Subroutine
new_TTerminal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 7 | extends TTextDevice; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # protected attributes | ||||||||||||||||||||||||||||
| 42 | 7 | has bufSize => ( is => 'ro' ); | |||||||||||||||||||||||||||
| 43 | 7 | has buffer => ( is => 'ro', default => '' ); | |||||||||||||||||||||||||||
| 44 | 7 | has queFront => ( is => 'ro', default => 0 ); | |||||||||||||||||||||||||||
| 45 | 7 | has queBack => ( is => 'ro', default => 0 ); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub BUILDARGS { # \%args (%args) | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 49 | method => 1, | ||||||||||||||||||||||||||||
| 50 | named => [ | ||||||||||||||||||||||||||||
| 51 | bounds => Object, | ||||||||||||||||||||||||||||
| 52 | hScrollBar => Maybe[Object], { alias => 'aHScrollBar' }, | ||||||||||||||||||||||||||||
| 53 | vScrollBar => Maybe[Object], { alias => 'aVScrollBar' }, | ||||||||||||||||||||||||||||
| 54 | bufSize => PositiveOrZeroInt, { alias => 'aBufSize' }, | ||||||||||||||||||||||||||||
| 55 | ], | ||||||||||||||||||||||||||||
| 56 | caller_level => +1, | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | 0 | my ( $class, $args ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 59 | 0 | return { %$args }; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub BUILD { # void (\%args) | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 0 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | assert ( is_HashRef $args ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | $self->{growMode} = gfGrowHiX | gfGrowHiY; | |||||||||||||||||||||||||||
| 68 | 0 | $self->{bufSize} = min( 32000, $args->{bufSize} ); | |||||||||||||||||||||||||||
| 69 | 0 | $self->{buffer} = "\0" x $self->{bufSize}; | |||||||||||||||||||||||||||
| 70 | 0 | $self->setLimit( 0, 1 ); | |||||||||||||||||||||||||||
| 71 | 0 | $self->setCursor( 0, 0 ); | |||||||||||||||||||||||||||
| 72 | 0 | $self->showCursor(); | |||||||||||||||||||||||||||
| 73 | 0 | return; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub from { # $term ($bounds, $aHScrollBar|undef, $aVScrollBar|undef, aBufSize) | ||||||||||||||||||||||||||
|
Subroutine
from: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 77 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 78 | method => 1, | ||||||||||||||||||||||||||||
| 79 | pos => [Object, Maybe[Object], Maybe[Object], PositiveOrZeroInt], | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | 0 | my ( $class, @args ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 82 | 0 | return $class->new( bounds => $args[0], hScrollBar => $args[1], | |||||||||||||||||||||||||||
| 83 | vScrollBar => $args[2], bufSize => $args[3] ); | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub DEMOLISH { # void ($in_global_destruction) | ||||||||||||||||||||||||||
|
Subroutine
DEMOLISH: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 0 | my ( $self, $in_global_destruction ) = @_; | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | $self->{buffer} = undef; | |||||||||||||||||||||||||||
| 91 | 0 | return; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # The following subroutine was ported from the framework | ||||||||||||||||||||||||||||
| 95 | # "A modern port of Turbo Vision 2.0", which is licensed under MIT licence. | ||||||||||||||||||||||||||||
| 96 | # | ||||||||||||||||||||||||||||
| 97 | # Copyright 2019-2021 by magiblot <magiblot@hotmail.com> | ||||||||||||||||||||||||||||
| 98 | # | ||||||||||||||||||||||||||||
| 99 | # I<textview.cpp> | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub do_sputn { # $num ($s, $count) | ||||||||||||||||||||||||||
|
Subroutine
do_sputn: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 102 | method => Object, | ||||||||||||||||||||||||||||
| 103 | pos => [Str, Int], | ||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | 0 | my ( $self, $s, $count ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | my $screenLines = $self->{limit}{y}; | |||||||||||||||||||||||||||
| 108 | 0 | my $i; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ( $count > $self->{bufSize} - 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | $s = bytes::substr( $s, $count - ( $self->{bufSize} - 1 ) ); | |||||||||||||||||||||||||||
| 112 | 0 | $count = $self->{bufSize} - 1; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | $screenLines += ( $s =~ tr/\n// ); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | while ( !$self->canInsert( $count ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 0 | $self->{queBack} = $self->nextLine( $self->{queBack} ); | |||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ( $screenLines > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | $screenLines--; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ( $self->{queFront} + $count >= $self->{bufSize} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | $i = $self->{bufSize} - $self->{queFront}; | |||||||||||||||||||||||||||
| 126 | bytes::substr( | ||||||||||||||||||||||||||||
| 127 | 0 | $self->{buffer}, $self->{queFront}, $i, | |||||||||||||||||||||||||||
| 128 | bytes::substr( $s, 0, $i ) | ||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||
| 130 | bytes::substr( | ||||||||||||||||||||||||||||
| 131 | 0 | $self->{buffer}, 0, $count - $i, | |||||||||||||||||||||||||||
| 132 | bytes::substr( $s, $i, $count - $i ) | ||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||
| 134 | 0 | $self->{queFront} = $count - $i; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | else { | ||||||||||||||||||||||||||||
| 137 | bytes::substr( | ||||||||||||||||||||||||||||
| 138 | 0 | $self->{buffer}, $self->{queFront}, $count, | |||||||||||||||||||||||||||
| 139 | bytes::substr( $s, 0, $count ) | ||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||
| 141 | 0 | $self->{queFront} += $count; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | # drawLock: avoid redundant calls to drawView() | ||||||||||||||||||||||||||||
| 145 | 0 | $self->{drawLock}++; | |||||||||||||||||||||||||||
| 146 | 0 | $self->setLimit( $self->{limit}{x}, $screenLines ); | |||||||||||||||||||||||||||
| 147 | 0 | $self->scrollTo( 0, $screenLines + 1 ); | |||||||||||||||||||||||||||
| 148 | 0 | $self->{drawLock}--; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | $self->drawView(); | |||||||||||||||||||||||||||
| 151 | 0 | return $count; | |||||||||||||||||||||||||||
| 152 | } #/ sub do_sputn | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | ▶ | sub bufInc { # void (\$val) | ||||||||||||||||||||||||||
|
Subroutine
bufInc: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 155 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 156 | method => Object, | ||||||||||||||||||||||||||||
| 157 | pos => [ScalarRef[Int]], | ||||||||||||||||||||||||||||
| 158 | ); | ||||||||||||||||||||||||||||
| 159 | 0 | my ( $self, $val ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ( ++$$val >= $self->{bufSize} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | $$val = 0; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | 0 | return; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub canInsert { # $bool ($amount) | ||||||||||||||||||||||||||
|
Subroutine
canInsert: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 168 | method => Object, | ||||||||||||||||||||||||||||
| 169 | pos => [PositiveOrZeroInt], | ||||||||||||||||||||||||||||
| 170 | ); | ||||||||||||||||||||||||||||
| 171 | 0 | my ( $self, $amount ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | my $T = ( $self->{queFront} < $self->{queBack} ) | ||||||||||||||||||||||||||||
| 174 | ? ( $self->{queFront} + $amount ) | ||||||||||||||||||||||||||||
| 175 | 0 | ▶ | : ( $self->{queFront} - $self->{bufSize} + $amount ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 0 | return $self->{queBack} > $T; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub calcWidth { # $width () | ||||||||||||||||||||||||||
|
Subroutine
calcWidth: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 180 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 181 | method => Object, | ||||||||||||||||||||||||||||
| 182 | pos => [], | ||||||||||||||||||||||||||||
| 183 | ); | ||||||||||||||||||||||||||||
| 184 | 0 | $sig->( @_ ); | |||||||||||||||||||||||||||
| 185 | ... | ||||||||||||||||||||||||||||
| 186 | 0 | } | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | # The following subroutine was ported from the framework | ||||||||||||||||||||||||||||
| 189 | # "A modern port of Turbo Vision 2.0", which is licensed under MIT licence. | ||||||||||||||||||||||||||||
| 190 | # | ||||||||||||||||||||||||||||
| 191 | # Copyright 2019-2021 by magiblot <magiblot@hotmail.com> | ||||||||||||||||||||||||||||
| 192 | # | ||||||||||||||||||||||||||||
| 193 | # I<textview.cpp> | ||||||||||||||||||||||||||||
| 194 | 0 | ▶ | sub draw { # void () | ||||||||||||||||||||||||||
|
Subroutine
draw: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 195 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 196 | method => Object, | ||||||||||||||||||||||||||||
| 197 | pos => [], | ||||||||||||||||||||||||||||
| 198 | ); | ||||||||||||||||||||||||||||
| 199 | 0 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | my $b = TDrawBuffer->new(); | |||||||||||||||||||||||||||
| 202 | 0 | my $s; | |||||||||||||||||||||||||||
| 203 | my $sLen; | ||||||||||||||||||||||||||||
| 204 | 0 | my ( $x, $y ); | |||||||||||||||||||||||||||
| 205 | 0 | my ( $begLine, $endLine, $linePos ); | |||||||||||||||||||||||||||
| 206 | 0 | my $bottomLine; | |||||||||||||||||||||||||||
| 207 | 0 | my $color = $self->mapColor( 1 ); | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | $self->setCursor( -1, -1 ); | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | $bottomLine = $self->{size}{y} + $self->{delta}{y}; | |||||||||||||||||||||||||||
| 212 | 0 | ▶ | if ( $self->{limit}{y} > $bottomLine ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | $endLine = | ||||||||||||||||||||||||||||
| 214 | 0 | $self->prevLines( $self->{queFront}, $self->{limit}{y} - $bottomLine ); | |||||||||||||||||||||||||||
| 215 | 0 | $self->bufDec( \$endLine ); | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | else { | ||||||||||||||||||||||||||||
| 218 | 0 | $endLine = $self->{queFront}; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if ( $self->{limit}{y} > $self->{size}{y} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 0 | $y = $self->{size}{y} - 1; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | else { | ||||||||||||||||||||||||||||
| 225 | 0 | ▶ | for ( $y = $self->{limit}{y} ; $y < $self->{size}{y} ; $y++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 0 | $self->writeChar( 0, $y, ' ', 1, $self->{size}{x} ); | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | 0 | $y = $self->{limit}{y} - 1; | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 0 | ▶ | for ( ; $y >= 0 ; $y-- ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 0 | $x = 0; | |||||||||||||||||||||||||||
| 233 | 0 | $begLine = $self->prevLines( $endLine, 1 ); | |||||||||||||||||||||||||||
| 234 | 0 | $linePos = $begLine; | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 0 | ▶ | while ( $linePos != $endLine ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | # Processing lines of any length by copying only the characters to be | ||||||||||||||||||||||||||||
| 238 | # displayed in $s, assuming that these are < maxViewWidth. | ||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if ( $endLine >= $linePos ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | 0 | my $cpyLen = min( $endLine - $linePos, maxViewWidth ); | |||||||||||||||||||||||||||
| 241 | 0 | $s = substr( $self->{buffer}, $linePos, $cpyLen ); | |||||||||||||||||||||||||||
| 242 | 0 | $sLen = $cpyLen; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | else { | ||||||||||||||||||||||||||||
| 245 | 0 | my $fstCpyLen = min( $self->{bufSize} - $linePos, maxViewWidth ); | |||||||||||||||||||||||||||
| 246 | 0 | my $sndCpyLen = min( $endLine, maxViewWidth - $fstCpyLen ); | |||||||||||||||||||||||||||
| 247 | $s = substr( $self->{buffer}, $linePos, $fstCpyLen ) | ||||||||||||||||||||||||||||
| 248 | 0 | . substr( $self->{buffer}, 0, $sndCpyLen ); | |||||||||||||||||||||||||||
| 249 | 0 | $sLen = $fstCpyLen + $sndCpyLen; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 0 | # Report any overlapping characters at the end | |||||||||||||||||||||||||||
| 253 | 0 | ▶ | assert ( $sLen == length $s ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if ( $linePos >= $self->{bufSize} - $sLen ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | 0 | $linePos = $sLen - ( $self->{bufSize} - $linePos ); | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | else { | ||||||||||||||||||||||||||||
| 258 | 0 | $linePos += $sLen; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 0 | $x += do { | |||||||||||||||||||||||||||
| 262 | 0 | $b->moveStr( $x, $s, $color ); | |||||||||||||||||||||||||||
| 263 | 0 | length $s; | |||||||||||||||||||||||||||
| 264 | }; | ||||||||||||||||||||||||||||
| 265 | } #/ while ( $linePos != $endLine) | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 0 | $b->moveChar( $x, ' ', $color, max( $self->{size}{x} - $x, 0 ) ); | |||||||||||||||||||||||||||
| 268 | 0 | $self->writeBuf( 0, $y, $self->{size}{x}, 1, $b ); | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | # Draw the cursor when this is the last line | ||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if ( $endLine == $self->{queFront} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 0 | $self->setCursor( $x, $y ); | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | 0 | $endLine = $begLine; | |||||||||||||||||||||||||||
| 275 | 0 | $self->bufDec( \$endLine ); | |||||||||||||||||||||||||||
| 276 | } #/ for ( ; $y >= 0 ; $y-- ) | ||||||||||||||||||||||||||||
| 277 | 0 | return; | |||||||||||||||||||||||||||
| 278 | } #/ sub draw | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 0 | ▶ | sub nextLine { # $offset ($pos) | ||||||||||||||||||||||||||
|
Subroutine
nextLine: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 281 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 282 | method => Object, | ||||||||||||||||||||||||||||
| 283 | pos => [PositiveOrZeroInt], | ||||||||||||||||||||||||||||
| 284 | ); | ||||||||||||||||||||||||||||
| 285 | 0 | my ( $self, $pos ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 0 | ▶ | if ( $pos != $self->{queFront} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 288 | 0 | ▶ | while ( substr( $self->{buffer}, $pos, 1 ) ne "\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($self->{"buffer"}, $pos, 1) ne "\n" and $pos != $self->{"queFront"}
MC/DC0%0/2
substr($self->{"buffer"}, $pos, 1) ne "\n" and $pos != $self->{"queFront"}
substr($self->{"buffer"}, $pos, 1) ne "\n"
$pos != $self->{"queFront"}
Truth table0%0/3
A and B
A= substr($self->{"buffer"}, $pos, 1) ne "\n"B= $pos != $self->{"queFront"}
| |||||||||||||||||||||||||||||
| 289 | && $pos != $self->{queFront} | ||||||||||||||||||||||||||||
| 290 | ) { | ||||||||||||||||||||||||||||
| 291 | 0 | $self->bufInc( \$pos ); | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if ( $pos != $self->{queFront} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | 0 | $self->bufInc( \$pos ); | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | 0 | return $pos; | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | # The following two subroutines was ported from the framework | ||||||||||||||||||||||||||||
| 301 | # "A modern port of Turbo Vision 2.0", which is licensed under MIT licence. | ||||||||||||||||||||||||||||
| 302 | # | ||||||||||||||||||||||||||||
| 303 | # Copyright 2019-2021 by magiblot <magiblot@hotmail.com> | ||||||||||||||||||||||||||||
| 304 | # | ||||||||||||||||||||||||||||
| 305 | # I<ttprvlns.cpp> | ||||||||||||||||||||||||||||
| 306 | 0 | ▶ | my $findLfBackwards = sub { # $bool ($buffer, $pos, $count) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 307 | 0 | my ( $buffer, $pos, $count ) = @_; | |||||||||||||||||||||||||||
| 308 | 0 | ▶ | assert ( @_ == 3 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | 0 | ▶ | assert ( is_Str $buffer ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 0 | ▶ | assert ( is_PositiveOrZeroInt $pos ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 0 | ▶ | assert ( is_Int $count ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | 0 | alias: for $pos ( $_[1] ) { | |||||||||||||||||||||||||||
| 313 | # Pre: count >= 1. | ||||||||||||||||||||||||||||
| 314 | # Post: 'pos' points to the last checked character. | ||||||||||||||||||||||||||||
| 315 | 0 | ++$pos; | |||||||||||||||||||||||||||
| 316 | 0 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | 0 | ▶ | return true | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | if substr( $buffer, --$pos, 1 ) eq "\n"; | ||||||||||||||||||||||||||||
| 319 | } while ( --$count > 0 ); | ||||||||||||||||||||||||||||
| 320 | 0 | return false; | |||||||||||||||||||||||||||
| 321 | } #/ alias: for my $pos ( $_[1] ) | ||||||||||||||||||||||||||||
| 322 | 7 | }; | |||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | ▶ | sub prevLines { # $offset ($pos, $lines) | ||||||||||||||||||||||||||
|
Subroutine
prevLines: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 325 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 326 | method => Object, | ||||||||||||||||||||||||||||
| 327 | pos => [PositiveOrZeroInt, PositiveOrZeroInt], | ||||||||||||||||||||||||||||
| 328 | ); | ||||||||||||||||||||||||||||
| 329 | 0 | my ( $self, $pos, $lines ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ( $lines > 0 && $pos != $self->{queBack} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$lines > 0 and $pos != $self->{"queBack"}
MC/DC0%0/2
$lines > 0 and $pos != $self->{"queBack"}
$lines > 0
$pos != $self->{"queBack"}
Truth table0%0/3
A and B
A= $lines > 0B= $pos != $self->{"queBack"}
| |||||||||||||||||||||||||||||
| 332 | 0 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | return $self->{queBack} | ||||||||||||||||||||||||||||
| 334 | 0 | ▶ | if $pos == $self->{queBack}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 335 | 0 | $self->bufDec( \$pos ); | |||||||||||||||||||||||||||
| 336 | my $count = ( $pos >= $self->{queBack} | ||||||||||||||||||||||||||||
| 337 | ? $pos - $self->{queBack} | ||||||||||||||||||||||||||||
| 338 | 0 | ▶ | : $pos ) + 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | 0 | ▶ | --$lines if &$findLfBackwards( $self->{buffer}, $pos, $count ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | } while ( $lines > 0 ); | ||||||||||||||||||||||||||||
| 341 | 0 | $self->bufInc( \$pos ); | |||||||||||||||||||||||||||
| 342 | } #/ if ( $lines > 0 && $pos...) | ||||||||||||||||||||||||||||
| 343 | 0 | return $pos; | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 0 | ▶ | sub queEmpty { # $bool () | ||||||||||||||||||||||||||
|
Subroutine
queEmpty: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 347 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 348 | method => Object, | ||||||||||||||||||||||||||||
| 349 | pos => [], | ||||||||||||||||||||||||||||
| 350 | ); | ||||||||||||||||||||||||||||
| 351 | 0 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 352 | 0 | return $self->{queBack} == $self->{queFront}; | |||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 0 | ▶ | sub bufDec { # void ($val) | ||||||||||||||||||||||||||
|
Subroutine
bufDec: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 356 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 357 | method => Object, | ||||||||||||||||||||||||||||
| 358 | pos => [ScalarRef[Int]], | ||||||||||||||||||||||||||||
| 359 | ); | ||||||||||||||||||||||||||||
| 360 | 0 | my ( $self, $val ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 361 | 0 | ▶ | if ( $$val == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 362 | 0 | $$val = $self->{bufSize} - 1; | |||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | else { | ||||||||||||||||||||||||||||
| 365 | 0 | $$val--; | |||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | 0 | return; | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | 7 | 1 | |||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | __END__ | ||||||||||||||||||||||||||||