blib/lib/Search/Fzf.pm

filter: Statementstmt 4.2% 39 / 911 Branchbran 0.0% 0 / 586 Conditioncond 0.0% 0 / 78 MC/DCmcdc 0.0% 0 / 52 Subroutinesub 26.5% 13 / 49 Podpod n/a totaltotal 3.1% 52 / 1676 CC 340 SCAR 103.9
CC
340
Cov
2%
fzf
54056.0
bufferOutputWithFormat
1122.0
fixUtf8List
306.0
CRAP 32454.2
↑ Summary AlgoCpp/t/00-load.t »
1 #!/usr/bin/perl
2 package Search::Fzf;
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Term::ANSIColor qw(uncolor color);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Text::ANSI::Util qw( ta_split_codes );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use List::Util qw( first any uniqstr pairs reduce );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use List::MoreUtils qw(firstidx qsort minmax indexes);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Time::HiRes qw(usleep);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Scalar::Util qw(openhandle);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use lib '.';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 require Search::Fzf::Tui;
15 1 ▶use Search::Fzf::AlgoCpp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 # require Search::Fzf::Algo;
17  
18 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 # use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
20 1 ▶use vars qw(@ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 #缺省export 函数fzf
23 our $VERSION = '0.04';
24 @ISA = qw(Exporter);
25 @EXPORT = qw(fzf);
26 # @EXPORT_OK = qw(fzf);
27  
28 #####################################################################################
29 #全局变量
30 #运行时的一些过程控制信息
31 my %runStatus=(
32 previewStatus => 0,
33 spinnerID => 0,
34 isSpinner => 0,
35 maxLen => 0,
36 );
37 #CONFIG init
38 # my %keymap = (
39 # # 'ctrl-p' => 'COMMAND_UP',
40 # # 'ctrl-n' => 'COMMAND_DOWN',
41 # );
42  
43 #缺省配置信息
44 my $DEFAULTCONFIG = {
45 # Search
46 prompt => "> Your Entered: ",
47 pointer => '>',
48 marker => '*',
49 algo => 'v2', #v1, v2, exact, regex
50 caseInsensitive => 1,
51 sort => 1,
52 delimiter => "\\s+",
53 # nth => [1,2,3],
54 # nth => [1..3],
55 nth => undef,
56 # withNth => [1,2,3,4],
57 # withNth => [1..4],
58 withNth => undef,
59 tac => 0,
60 disable => 0,
61 expect => undef,
62
63 #Interface
64 # header => "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890",
65 multi => 0,
66 cycle => 1,
67 mouse => 1,
68 #next test
69 keepRight => 0,
70 #缺省为5, 若小于0, 则当行长超过显示宽度时不会跟踪显示最后匹配的字符
71 hScrollOff => 5,
72 # hScrollOff => 0,
73 hScroll => 1,
74 jumpLabels => ['a'..'z'],
75 # jumpLabels => ['d', 'e', 'f'],
76 # jumpLabels => undef,
77 header => undef,
78 headerLines => 0,
79 headerFirst => 0,
80  
81 border => 0,
82 topMargin => 0,
83 bottomMargin => 0,
84 leftMargin => 0,
85 rightMargin => 0,
86 topPadding => 0,
87 bottomPadding => 0,
88 leftPadding => 0,
89 rightPadding => 0,
90 layout => 0, #0 default 1 reverse 2 reverse list
91 info => 0, #0 default 1 incline 2 hidden
92  
93 #Color
94 color => 1,
95 colorFg => 'default',
96 colorBg => 'default',
97 colorFgPlus => 'default',
98 colorBgPlus => 'cyan',
99 colorHl => 'red',
100 colorHlPlus => 'red',
101 # colorHlPlus => 'magenta',
102 colorPointer => 'blue',
103 colorMarker => 'green',
104 colorGutter => 'default',
105 colorInfo => 'white',
106 colorPrompt => 'grey8',
107 colorHeader => 'grey5',
108 colorQuery => 'yellow',
109 colorDisabled => 'grey5',
110 colorSpinner => 'green',
111 colorFgPreview => 'default',
112 colorBgPreview => 'default',
113
114  
115 # keymap => \%keymap,
116 keymap => {},
117  
118 preview => 0,
119 # previewFunc => \&defaultPreviewFunc,
120 # previewWithColor => 0,
121 previewWithColor => 1,
122 previewPosition => 1, #0 up 1 down 2 left 3 right
123 previewBorder => 1,
124 previewWrap => 0,
125 previewScrollOff => 0, #scroll off
126 previewCyclic => 0,
127 previewHead => 0,
128 previewFollow => 0,
129 previewFunc => \&batPreviewFunc,
130  
131 #getch timeout
132 timeout => 100,
133 # timeout => 0,
134 rowDelimeter => "\n",
135 execFunc => \&defaultExecFunc,
136  
137 #input thread config
138 asynRead => 0,
139 #match threads num
140 threads => 4,
141 };
142 #####################################################################################
143  
144  
145 #流式输入时的动画字符
146 my %spinnerHash = (0 => '/', 1 => '-', 2 => "\\", 3 => '|');
147 #TODO
148 0 ▶sub getSpinnerChar {
Subroutine getSpinnerChar: not called CC=2 SCAR=17.9
149 0 ▶ return ' ' if not $runStatus{isSpinner};
Branch: 1 branch
BranchTrueFalseTotal
unless $runStatus{"isSpinner"} 0 0 0
150  
151 0 my $spinnerChar = $spinnerHash{$runStatus{spinnerID}};
152 0 $runStatus{spinnerID} = ($runStatus{spinnerID} + 1) % 4;
153 0 $runStatus{isSpinner} = 0;
154 0 return $spinnerChar;
155 }
156  
157 #min函数, 两个标量参数, 返回较小的
158 0 ▶sub min {
Subroutine min: not called CC=2 SCAR=17.9
159 0 my ($a, $b) = @_;
160 0 ▶ return $a<$b? $a:$b;
Branch: 1 branch
BranchTrueFalseTotal
$a < $b ? : 0 0 0
161 }
162 #max函数, 两个标量参数, 返回较大的
163 0 ▶sub max {
Subroutine max: not called CC=2 SCAR=17.9
164 0 my ($a, $b) = @_;
165 0 ▶ return $a>$b? $a:$b;
Branch: 1 branch
BranchTrueFalseTotal
$a > $b ? : 0 0 0
166 }
167  
168 #用于重置屏幕的左右尺寸信息
169 #home=1为从左侧定位, home=0为从右侧定位
170 0 ▶sub resetLeftRight {
Subroutine resetLeftRight: not called CC=3 SCAR=24.8
171 0 my ($CONFIG, $home) = @_;
172  
173 0 my $hoff = $CONFIG->{leftMargin} + $CONFIG->{rightMargin};
174 0 ▶ $hoff = 2 + $CONFIG->{leftPadding} + $CONFIG->{rightPadding} if ($CONFIG->{border});
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"border"} 0 0 0
175  
176 0 ▶ if ($home == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($home == 1) { } 0 0 0
177 0 $runStatus{left} = 0;
178 0 $runStatus{right} = $runStatus{width} +$runStatus{left} - 2 - $hoff;
179 }else{
180 0 $runStatus{right} = &max($runStatus{maxLen}+2, $runStatus{width}-2-$hoff) ;
181 0 $runStatus{left} = $runStatus{right} - $runStatus{width} + 2 + $hoff;
182 }
183 }
184  
185 #用于设置屏幕的右对齐信息
186 #$right为最后的匹配结束结束位置, 留出hScrollOff, 作为最右侧的定位
187 0 ▶sub alignRight {
Subroutine alignRight: not called CC=3 SCAR=24.8
188 0 my ($CONFIG, $right) = @_;
189  
190 0 my $hoff = 0;
191 0 ▶ $hoff = 2 + $CONFIG->{leftPadding} + $CONFIG->{rightPadding} if ($CONFIG->{border});
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"border"} 0 0 0
192  
193 0 ▶ if ($right + $CONFIG->{hScrollOff} > $runStatus{right}){
Branch: 1 branch
BranchTrueFalseTotal
if ($right + $CONFIG->{"hScrollOff"} > $runStatus{"right"}) 0 0 0
194 0 $runStatus{right} = $right + $CONFIG->{hScrollOff};
195 0 $runStatus{left} = $runStatus{right} - $runStatus{width} + 2 + $hoff;
196 }
197 }
198  
199 #重置光标位置, 设置输出到屏幕的底部和头部信息, left和right信息
200 0 ▶sub resetPointer {
Subroutine resetPointer: not called CC=5 SCAR=34.0
201 0 my ($CONFIG, $h, $w) = @_;
202  
203 0 $runStatus{height} = $h;
204 0 $runStatus{width} = $w;
205  
206 #计算border和padding占据的位置宽度
207 0 my $voff = 0;
208 0 ▶ $voff = 2 + $CONFIG->{topPadding} + $CONFIG->{bottomPadding} if ($CONFIG->{border});
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"border"} 0 0 0
209 0 my $hoff = 0;
210 0 ▶ $hoff = 2 + $CONFIG->{leftPadding} + $CONFIG->{rightPadding} if ($CONFIG->{border});
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"border"} 0 0 0
211  
212 #显示信息初始化, 预留info和header高度
213 0 my $before = 2;
214 0 ▶ $before = 3 if ($CONFIG->{info} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"info"} == 0 0 0 0
215 0 ▶ $before += scalar(@{$runStatus{headerList}}) if (exists $runStatus{headerList});
Branch: 1 branch
BranchTrueFalseTotal
if exists $runStatus{"headerList"} 0 0 0
216  
217 0 $runStatus{bottom} = 0;
218 0 $runStatus{top} = $runStatus{height} - $before - $voff;
219 0 $runStatus{left} = 0;
220 0 $runStatus{right} = $runStatus{width} - 2 - $hoff;
221 }
222  
223 #根据光标位置设置输出到屏幕的底部和头部信息
224 0 ▶sub setPointer {
Subroutine setPointer: not called CC=14 SCAR=53.5
225 0 my ($CONFIG, $ptr, $move) = @_;
226  
227 0 my $vboff = 0;
228 0 ▶ $vboff = 1 + $CONFIG->{bottomPadding} if ($CONFIG->{border});
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"border"} 0 0 0
229 0 my $voff = 0;
230 0 ▶ $voff = 2 + $CONFIG->{topPadding} + $CONFIG->{bottomPadding} if ($CONFIG->{border});
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"border"} 0 0 0
231 0 my $hloff = 0;
232 0 ▶ $hloff = 1 + $CONFIG->{leftPadding} if ($CONFIG->{border});
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"border"} 0 0 0
233  
234 #正文列表前的输入提示信息所占据的行数
235 0 my $before = 1;
236 0 ▶ $before =2 if ($CONFIG->{info} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"info"} == 0 0 0 0
237 0 ▶ $before += ($#{$runStatus{headerList}} + 1) if (defined $runStatus{headerList});
Branch: 1 branch
BranchTrueFalseTotal
if defined $runStatus{"headerList"} 0 0 0
238  
239 #纵向scroll up
240 0 ▶ if($ptr > $runStatus{pointer} && $ptr > $runStatus{top}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ptr > $runStatus{'pointer'} and $ptr > $runStatus{'top'}) { } 0 0 0
elsif ($ptr < $runStatus{'pointer'} and $ptr < $runStatus{'bottom'}) { } 0 0 0
Condition0%0/3
$ptr > $runStatus{"pointer"} and $ptr > $runStatus{"top"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ptr > $runStatus{"pointer"} and $ptr > $runStatus{"top"}
$ptr > $runStatus{"pointer"} $ptr > $runStatus{"top"}
Truth table0%0/3
A and B
A= $ptr > $runStatus{"pointer"}B= $ptr > $runStatus{"top"}
ABresult
0X0
100
111
241 0 $runStatus{top} = $ptr;
242 0 $runStatus{bottom} = $runStatus{top} - $runStatus{height} + $before + 1 + $voff;
243 ▶ }elsif($ptr < $runStatus{pointer} && $ptr < $runStatus{bottom}){
Condition0%0/3
$ptr < $runStatus{"pointer"} and $ptr < $runStatus{"bottom"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ptr < $runStatus{"pointer"} and $ptr < $runStatus{"bottom"}
$ptr < $runStatus{"pointer"} $ptr < $runStatus{"bottom"}
Truth table0%0/3
A and B
A= $ptr < $runStatus{"pointer"}B= $ptr < $runStatus{"bottom"}
ABresult
0X0
100
111
244 0 $runStatus{bottom} = $ptr;
245 0 $runStatus{top} = $runStatus{height} + $runStatus{bottom} - $before - 1 - $voff;
246 }
247
248 #横向滚动
249 0 ▶ if($move<0){
Branch: 2 branches
BranchTrueFalseTotal
if ($move < 0) { } 0 0 0
elsif ($move > 0) { } 0 0 0
250 0 ▶ if($runStatus{left}>0){
Branch: 1 branch
BranchTrueFalseTotal
if ($runStatus{"left"} > 0) 0 0 0
251 0 $runStatus{left} -= 1;
252 0 $runStatus{right} -= 1;
253 }
254 }elsif($move>0){
255 0 ▶ if($runStatus{right} < $runStatus{maxLen}+2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($runStatus{"right"} < $runStatus{"maxLen"} + 2) 0 0 0
256 0 $runStatus{left} += 1;
257 0 $runStatus{right} += 1;
258 }
259 }
260  
261 0 $runStatus{pointer} = $ptr;
262 0 $runStatus{location} = $runStatus{pointer} - $runStatus{bottom};
263 }
264  
265 #窗口尺寸变化, 重新绘制窗口
266 0 ▶sub resize {
Subroutine resize: not called CC=1 SCAR=6.9
267 0 my ($CONFIG, $tui) = @_;
268  
269 0 $tui->clearWin;
270 0 $tui->clearPreviewWin;
271 0 my ($h, $w) = $tui->openWin();
272 0 &resetPointer($CONFIG, $h, $w);
273 }
274  
275 #函数togglePreview, 打开或关闭preview窗口
276 0 ▶sub togglePreview {
Subroutine togglePreview: not called CC=1 SCAR=6.9
277 0 my ($CONFIG, $tui) = @_;
278  
279 0 $tui->clearWin;
280 0 $tui->clearPreviewWin;
281 0 $CONFIG->{preview} ++;
282 0 $CONFIG->{preview} %= 2;
283 0 my ($h, $w) = $tui->openWin();
284 0 &resetPointer($CONFIG, $h, $w);
285 }
286  
287 #切换preview窗口的位置
288 0 ▶sub togglePreviewPosition {
Subroutine togglePreviewPosition: not called CC=1 SCAR=6.9
289 0 my ($CONFIG, $tui) = @_;
290  
291 0 $tui->clearWin;
292 0 $tui->clearPreviewWin;
293 0 $CONFIG->{previewPosition} ++;
294 0 $CONFIG->{previewPosition} %= 4;
295 0 my ($h, $w) = $tui->openWin();
296 0 &resetPointer($CONFIG, $h, $w);
297 }
298  
299 #函数bufferOutputWithFormat, 带格式的显示输出
300 #生成buffer数据结构, 作为tui->setBuffer的参数
301 #buffer数据结构是一个数组, 数组中的每个元素代表1行
302 #每行中含有若干段, 代表一段带有格式的字符串
303 #每个段包含两个元素, 分别是字符串和格式, 格式由1个整数表示
304 #参数:
305 #$CONFIG: 配置参数
306 #currList_ref, 匹配信息, 匹配上的行相关信息, 每行包括一个列表, 列表中没项是一串整型编码, 需要调用unpackList解码
307 #解码后的信息
308 #位置[0]:score, [1]:匹配起始位置, [2]:匹配结束位置, [3]:对应strList_ref的行号
309 #$iPattern, 在输入部分显示
310 #返回值:
311 #buffer引用
312 0 ▶sub bufferOutputWithFormat{
Subroutine bufferOutputWithFormat: not called CC=33 SCAR=70.2
313 0 my ($CONFIG, $algo, $currList_ref, $iPattern) = @_;
314  
315 0 my @buf;
316 0 my $before = 0;
317 #整个列表长度
318 0 my $catLen = $algo->getCatArraySize;
319 #当前匹配列表长度
320 0 my $currLen = scalar(@{$currList_ref});
321 0 my $hasInput = length($iPattern);
322  
323 #输出头部信息
324 0 ▶ if ($CONFIG->{headerFirst}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"headerFirst"}) 0 0 0
325 0 ▶ if(exists $runStatus{headerList}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $runStatus{"headerList"}) 0 0 0
326 0 $buf[$before+$_][0] = [$runStatus{headerList}->[$_], 10] foreach (0 .. $#{$runStatus{headerList}});
327 }
328 0 $before += scalar(@{$runStatus{headerList}});
329 }
330 #输出提示信息
331 0 my $queryColorPair = 11;
332 0 ▶ $queryColorPair = 12 if ($CONFIG->{disable});
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
333 0 my $spinnerChar = &getSpinnerChar;
334 0 $buf[$before][0] = [$spinnerChar."$CONFIG->{prompt}", 9];
335 0 $buf[$before][1] = [$iPattern, $queryColorPair];
336 0 $runStatus{inputRow} = $before;
337 0 $before += 1;
338 0 ▶ if ($CONFIG->{info} == 0){
Branch: 3 branches
BranchTrueFalseTotal
if ($CONFIG->{'info'} == 0) { } 0 0 0
elsif ($CONFIG->{'info'} == 1) { } 0 0 0
elsif ($CONFIG->{'info'} == 2) { } 0 0 0
339 0 $buf[$before][0] = [" $currLen/$catLen ($CONFIG->{algo})", 8];
340 0 $before += 1;
341 }elsif($CONFIG->{info} == 1) {
342 0 $buf[$before-1][2] = [" <$currLen/$catLen ($CONFIG->{algo})", 8];
343 }elsif($CONFIG->{info} == 2) { }
344 #输出头部信息
345 0 ▶ if (not $CONFIG->{headerFirst}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($CONFIG->{"headerFirst"}) 0 0 0
346 0 ▶ if(exists $runStatus{headerList}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $runStatus{"headerList"}) 0 0 0
347 0 $buf[$before+$_][0] = [$runStatus{headerList}->[$_], 10] foreach (0 .. $#{$runStatus{headerList}});
348 }
349 0 $before += scalar(@{$runStatus{headerList}});
350 }
351 0 $runStatus{before} = $before;
352  
353 0 ▶ return \@buf if $currLen == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $currLen == 0 0 0 0
354 0 ▶ if($CONFIG->{withNth}) { #设置withNth选项
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{'withNth'}) { } 0 0 0
355 0 my $bi=0;
356 0 foreach my $i ($runStatus{bottom} .. min($runStatus{top}, $#{$currList_ref})) {
357 #取出匹配列表所对应的原始字符串, 以及相关匹配信息
358 0 my $currItem = unpackList($currList_ref->[$i]);
359 0 my $id = $currItem->[3];
360 0 my $matchStr = $algo->getStr($id);
361 0 my $start = $currItem->[1];
362 0 my $end = $currItem->[2];
363 # 后端算法模块处理的是char数组, 若被查询字符串含有宽字符编码, 需要修正匹配位置信息
364 # $matchStr = Encode::decode_utf8($matchStr);
365 0 ($matchStr, $start, $end) = fixUtf8List($matchStr, $start, $end);
366  
367 #组装withNth列表中的显示字段
368 0 my @strs = split /$CONFIG->{delimiter}/, $matchStr;
369 0 my @dels = ($matchStr =~ /$CONFIG->{delimiter}/g);
370 0 my @arr = map {join "", ($strs[$_], $dels[$_])} (0 .. $#strs);
371 0 ▶ if (not $hasInput){
Branch: 1 branch
BranchTrueFalseTotal
if (not $hasInput) { } 0 0 0
372 #筛选
373 0 my @filter = @{$CONFIG->{withNth}};
374 0 my @arr = grep {defined $_} map {$arr[$_]} @filter;
375  
376 #整合筛选后的字符串列表并输出
377 0 my $outStr = join "", @arr;
378 #若标记为选中, 输出选择标记
379 0 ▶ if ($algo->getMarkLabel($id)==1){
Branch: 1 branch
BranchTrueFalseTotal
if ($algo->getMarkLabel($id) == 1) { } 0 0 0
380 0 $buf[$bi+$before][0] = [" ".$CONFIG->{marker}, 5];
381 } else{
382 0 $buf[$bi+$before][0] = [" ", 1];
383 }
384 0 push @{$buf[$bi+$before]}, [$outStr, 1];
385 0 ▶ if(length($outStr) > $runStatus{maxLen}) {$runStatus{maxLen} = length($outStr)};
Branch: 1 branch
BranchTrueFalseTotal
if (length $outStr > $runStatus{"maxLen"}) 0 0 0
386 }else{
387 #筛选
388 0 my @filter = @{$CONFIG->{withNth}};
389 0 my @charMark;
390 #逐位设置筛选标记, 1代表在筛选范围内, 0代表不在筛选范围内
391 0 foreach my $j (0 .. $#arr) {
392 0 ▶ if (grep{$_ == $j} @filter){
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ == $j;} @filter) { } 0 0 0
393 0 push @charMark, (1) x length($arr[$j])
394 }else {
395 0 push @charMark, (0) x length($arr[$j]);
396 }
397 }
398  
399 #regex position mark, 正则匹配的位置
400 0 my @regxMark;
401 0 push @regxMark, (0) x ($start->[0] - 0);
402 #转换成为逐位匹配标记
403 0 for my $j (0 .. $#{$start}) {
404 0 push @regxMark, (1) x ($end->[$j] - $start->[$j]);
405 0 ▶ if($j < $#{$start}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $#{$start;}) { } 0 0 0
406 0 push @regxMark, (0) x ($start->[$j+1] - $end->[$j]);
407 } else {
408 0 push @regxMark, (0) x (length($matchStr) - $end->[$j]);
409 }
410 }
411  
412 #outPut
413 0 my $outputStr;
414 #将字符串拆分成为逐位列表
415 0 my @charArr = split //, $matchStr;
416 #输出选择标记
417 0 ▶ if ($algo->getMarkLabel($id)==1){
Branch: 1 branch
BranchTrueFalseTotal
if ($algo->getMarkLabel($id) == 1) { } 0 0 0
418 0 $buf[$bi+$before][0] = [" ".$CONFIG->{marker}, 5];
419 } else{
420 0 $buf[$bi+$before][0] = [" ", 1];
421 }
422 #逐位输出, 每个字符带有1个属性值
423 0 my $outLen = 0;
424 0 foreach my $j (0 .. $#regxMark) {
425 0 ▶ if ($charMark[$j]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($charMark[$j]) 0 0 0
426 0 ▶ if ($regxMark[$j]){
Branch: 1 branch
BranchTrueFalseTotal
if ($regxMark[$j]) { } 0 0 0
427 0 push @{$buf[$bi+$before]}, ["$charArr[$j]", 3];
428 }else{
429 0 push @{$buf[$bi+$before]}, ["$charArr[$j]", 1];
430 }
431 0 $outLen ++;
432 }
433 }
434 0 ▶ if($outLen > $runStatus{maxLen}) {$runStatus{maxLen} = $outLen};
Branch: 1 branch
BranchTrueFalseTotal
if ($outLen > $runStatus{"maxLen"}) 0 0 0
435 }
436 0 $bi ++;
437 }
438 }else { #未设置withNth选项
439 0 my $bi=0;
440 0 foreach my $i ($runStatus{bottom} .. min($runStatus{top}, $#{$currList_ref})) {
441 #取出匹配列表所对应的原始字符串, 以及相关匹配信息
442 0 my $currItem = unpackList($currList_ref->[$i]);
443 0 my $id = $currItem->[3];
444 #输出选择标记
445 0 ▶ if ($algo->getMarkLabel($id)==1){
Branch: 1 branch
BranchTrueFalseTotal
if ($algo->getMarkLabel($id) == 1) { } 0 0 0
446 0 $buf[$bi+$before][0] = [" ".$CONFIG->{marker}, 5];
447 } else{
448 0 $buf[$bi+$before][0] = [" ", 1];
449 }
450  
451 0 ▶ if (not $hasInput) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $hasInput) { } 0 0 0
452 #输出完整的字符串
453 0 my $outStr = $algo->getStr($id);
454 0 $outStr = Encode::decode_utf8($outStr);
455 0 push @{$buf[$bi+$before]}, [$outStr, 1];
456 0 ▶ if(length($outStr) > $runStatus{maxLen}) {$runStatus{maxLen} = length($outStr)};
Branch: 1 branch
BranchTrueFalseTotal
if (length $outStr > $runStatus{"maxLen"}) 0 0 0
457 }else {
458 #正则匹配的开始和结束位置
459 0 my $start = $currItem->[1];
460 0 my $end = $currItem->[2];
461  
462 0 my $outStr = $algo->getStr($id);
463 # 后端算法模块处理的是char数组, 若被查询字符串含有宽字符编码, 需要修正匹配位置信息
464 # $outStr = Encode::decode_utf8($outStr);
465 0 ($outStr, $start, $end) = fixUtf8List($outStr, $start, $end);
466 0 ▶ if(length($outStr) > $runStatus{maxLen}) {$runStatus{maxLen} = length($outStr)};
Branch: 1 branch
BranchTrueFalseTotal
if (length $outStr > $runStatus{"maxLen"}) 0 0 0
467 #第1个匹配位置前的字符串, 正常显示
468 0 my $partStr = substr($outStr, 0, $start->[0]);
469 0 push @{$buf[$bi+$before]}, ["$partStr", 1];
470 0 foreach my $j (0 .. $#{$start}){
471 #匹配上的字符串, 格式输出
472 0 $partStr = substr($outStr, $start->[$j], $end->[$j] - $start->[$j]);
473 0 push @{$buf[$bi+$before]}, [$partStr, 3];
474 0 ▶ if ($j < $#{$start} ) { #每个匹配位置间隔中的字符串, 正常输出
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $#{$start;}) { } 0 0 0
475 0 $partStr = substr($outStr, $end->[$j], $start->[$j+1] - $end->[$j]);
476 } else{ #最后1个匹配位置后的字符串, 正常输出
477 0 $partStr = substr($outStr, $end->[$j]);
478 }
479 0 push @{$buf[$bi+$before]}, [$partStr, 1];
480 }
481 }
482 0 $bi ++;
483 }
484 }
485 0 return \@buf;
486 }
487  
488 #从cpp算法后端返回的匹配信息是一串整型编码
489 #int[1]=line, int[2]=score, 后面一串匹配位置信息, 每对包括start和end位置
490 #解码后的匹配信息为[$score, \@start, \@end, $line]
491 0 ▶sub unpackList{
Subroutine unpackList: not called CC=2 SCAR=17.9
492 0 my $packStr = shift @_;
493
494 0 my $len = length($packStr)/4;
495 0 my @unList = unpack("i$len", $packStr);
496 0 my $line = shift @unList;
497 0 my $score = shift @unList;
498 0 my @start;
499 my @end;
500 0 ▶ while(scalar(@unList) >0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @unList > 0) 0 0 0
501 0 my $s = shift @unList;
502 0 push @start, $s;
503 0 my $e = shift @unList;
504 0 push @end, $e;
505 }
506 0 return [$score, \@start, \@end, $line];
507 }
508  
509 # 后端算法模块处理的是char数组, 若被查询字符串含有宽字符编码, 需要修正匹配位置信息
510 # $inStr被匹配字符串, $start匹配字符的起始位置, $end匹配字符的结束位置
511 0 ▶sub fixUtf8List {
Subroutine fixUtf8List: not called CC=17 SCAR=57.2
512 0 my ($inStr, $start, $end) = @_;
513 #复制匹配信息
514 0 my @fixStart = @$start;
515 0 my @fixEnd = @$end;
516  
517 #将被匹配字符串拆成char数组
518 0 my @chars = split //, $inStr;
519 0 my $charIdx;
520 0 ▶ while($charIdx < length($inStr)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($charIdx < length $inStr) 0 0 0
521 0 my $ch=$chars[$charIdx];
522 0 ▶ if (ord($ch) < 128){ #普通的asc字符编码
Branch: 4 branches
BranchTrueFalseTotal
if (ord $ch < 128) { } 0 0 0
elsif (ord $ch >= 192 and ord $ch < 224) { } 0 0 0
elsif (ord $ch >= 224 and ord $ch < 240) { } 0 0 0
elsif (ofd($ch) >= 240) { } 0 0 0
523 0 $charIdx ++;
524 0 next;
525 ▶ }elsif (ord($ch) >=192 && ord($ch) < 224) {#utf8双字节编码
Condition0%0/3
ord $ch >= 192 and ord $ch < 224
!ll&&!rl&&r
000
MC/DC0%0/2
ord $ch >= 192 and ord $ch < 224
ord $ch >= 192 ord $ch < 224
Truth table0%0/3
A and B
A= ord $ch >= 192B= ord $ch < 224
ABresult
0X0
100
111
526 0 foreach my $i (0 .. $#{$start}) {
527 0 ▶ $fixStart[$i] -= 1 if ($charIdx < $start->[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $charIdx < $start->[$i] 0 0 0
528 0 ▶ $fixEnd[$i] -=1 if ($charIdx < $start->[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $charIdx < $start->[$i] 0 0 0
529 }
530 0 $charIdx += 2;
531 ▶ }elsif (ord($ch) >=224 && ord($ch) < 240) {#utf8三字节编码
Condition0%0/3
ord $ch >= 224 and ord $ch < 240
!ll&&!rl&&r
000
MC/DC0%0/2
ord $ch >= 224 and ord $ch < 240
ord $ch >= 224 ord $ch < 240
Truth table0%0/3
A and B
A= ord $ch >= 224B= ord $ch < 240
ABresult
0X0
100
111
532 0 foreach my $i (0 .. $#{$start}) {
533 0 ▶ $fixStart[$i] -= 2 if ($charIdx < $start->[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $charIdx < $start->[$i] 0 0 0
534 0 ▶ $fixEnd[$i] -=2 if ($charIdx < $start->[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $charIdx < $start->[$i] 0 0 0
535 }
536 0 $charIdx += 3;
537 }elsif (ofd($ch) >=240) {
538 0 foreach my $i (0 .. $#{$start}) {#utf8四字节编码
539 0 ▶ $fixStart[$i] -= 3 if ($charIdx < $start->[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $charIdx < $start->[$i] 0 0 0
540 0 ▶ $fixEnd[$i] -=3 if ($charIdx < $start->[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $charIdx < $start->[$i] 0 0 0
541 }
542 0 $charIdx += 4;
543 }
544 }
545 #将被匹配字符串转化成为utf8编码
546 0 $inStr = Encode::decode_utf8($inStr);
547 0 return ($inStr, \@fixStart, \@fixEnd);
548 }
549  
550 #调用后端cpp算法模块的匹配算法
551 0 ▶sub matchList {
Subroutine matchList: not called CC=1 SCAR=6.9
552 0 my ($CONFIG, $algo, $iPattern) = @_;
553  
554 0 my @algoList = qw(exact v1 v2);
555 0 ▶ my $algoIdx = firstidx {$_ eq $CONFIG->{algo}} @algoList;
Subroutine __ANON__: not called CC=1 SCAR=6.9
556  
557 0 my $currList = $algo->matchList($iPattern, $CONFIG->{sort}, $CONFIG->{caseInsensitive}, $algoIdx, $CONFIG->{threads});
558  
559 0 return $currList;
560 }
561  
562 #函数movePointerDown, 向下移动匹配项指针
563 #参数
564 #$CONFIG, 配置信息
565 #$currList_ref, 当前匹配记录列表
566 #$ptr_ref, 指针变量引用
567 #$off, 移动的位移
568 0 ▶sub movePointerDown{
Subroutine movePointerDown: not called CC=4 SCAR=30.0
569 0 my ($CONFIG, $currList_ref, $ptr_ref, $off) = @_;
570 0 ▶ if (defined $off) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $off) { } 0 0 0
571 0 ${$ptr_ref} -= $off;
572 }else{
573 0 ${$ptr_ref} --;
574 }
575 #若指针小于0, 则循环为列表结尾, 或者设置为0
576 0 ▶ if (${$ptr_ref} < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (${$ptr_ref;} < 0) 0 0 0
577 0 ▶ if ($CONFIG->{cycle}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{'cycle'}) { } 0 0 0
578 0 ${$ptr_ref} = $#{$currList_ref};
579 }else{
580 0 ${$ptr_ref} = 0;
581 0 return;
582 }
583 }
584 }
585  
586 #函数movePointerUp, 向上移动匹配项指针
587 #参数
588 #$CONFIG, 配置信息
589 #$currList_ref, 当前匹配记录列表
590 #$ptr_ref, 指针变量引用
591 #$off, 移动的位移
592 0 ▶sub movePointerUp{
Subroutine movePointerUp: not called CC=4 SCAR=30.0
593 0 my ($CONFIG, $tui, $currList_ref, $ptr_ref, $off) = @_;
594 0 ▶ if (defined $off) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $off) { } 0 0 0
595 0 ${$ptr_ref} += $off;
596 }else{
597 0 ${$ptr_ref} ++;
598 }
599 #若指针超过列表边界, 则设置为0, 或停留在边界
600 0 ▶ if (${$ptr_ref} > $#{$currList_ref}) {
Branch: 1 branch
BranchTrueFalseTotal
if (${$ptr_ref;} > $#{$currList_ref;}) 0 0 0
601 0 ▶ if ($CONFIG->{cycle}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{'cycle'}) { } 0 0 0
602 0 ${$ptr_ref} = 0;
603 }else{
604 0 ${$ptr_ref} = $#{$currList_ref};
605 0 return;
606 }
607 }
608 }
609  
610  
611 #函数bufferPreviewOutput, 生成preview的显示buffer, 不带颜色格式, 仅仅类似catStr
612 #参数,
613 #$previewString, preview的字符串列表引用
614 #返回显示buffer的引用
615 0 ▶sub bufferPreviewOutput {
Subroutine bufferPreviewOutput: not called CC=2 SCAR=17.9
616 0 my ($previewStrings) = @_;
617 0 my @buffer;
618 #14是preview文本的显示缺省格式号
619 0 push @buffer, [[$_, 14]] foreach (@{$previewStrings});
620 0 return \@buffer;
621 }
622  
623 #函数bufferPreviewOutputWithANSI, 生成preview的显示buffer, 使用ANSI256颜色配置
624 #参数,
625 #$previewString, preview的字符串列表引用
626 #返回显示buffer的引用
627 #使用Term::ANSIColor中对颜色的命名, 包括有4类形式
628 #16种缺省颜色, grey\d是灰度颜色, rgb\d\d\d是216种颜色, \d是0到5的rgb数字,
629 #r\d+g\d+b\d+是24位的rgb颜色, 在代码中被转化为216种颜色配置
630 0 ▶sub bufferPreviewOutputWithANSI {
Subroutine bufferPreviewOutputWithANSI: not called CC=17 SCAR=57.2
631 0 my ($tui, $previewStrings) = @_;
632  
633 #对显示的字符串列表按照分割成为正文和转义序列, 存储在@showList中
634 0 my @showList;
635 #所有的转义序列列表
636 my @escList;
637 #hash, 转义序列为key, 对应的颜色标识
638 0 my %escMap;
639  
640 #对每行字符串, 按照转义序列间隔分割为列表, 列表奇数位置为转义字符串
641 #将所有的转义字符串, 加入列表@escList, 并排重
642 0 foreach my $input (@{$previewStrings}){
643 0 my @parts = ta_split_codes($input);
644 0 foreach my $i (0 .. $#parts) {
645 #去除干扰
646 0 ▶ if ($i % 2== 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($i % 2 == 1) 0 0 0
647 0 $parts[$i] =~ s/.*(\e\[.*m).*/\1/;
648 0 push @escList, $parts[$i];
649 }
650 }
651 0 push @showList, \@parts;
652 }
653 0 @escList = uniqstr @escList;
654  
655 #将缺省的重置转义命令设置为缺省的Curses颜色对
656 0 my @pairList = ([-1, -1]);
657 0 $escMap{"\e[0m"} = 0;
658
659 #处理出现的esc码
660 0 foreach my $escStr (@escList){
661 0 my $p = $escStr;
662 0 $p =~ s/\e\[(.*?)m/\1/;
663 0 my @names = uncolor($p);
664 0 my @cs;
665 0 foreach my $n (@names){
666 0 ▶ if (any {$_ eq $n} @{$tui->{colorList}}){
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 4 branches
BranchTrueFalseTotal
if (&any(sub { $_ eq $n; } , @{$$tui{'colorList'};})) { } 0 0 0
elsif ($n =~ /r\d+g\d+b\d+/) { } 0 0 0
elsif ($n =~ /rgb\d+/) { } 0 0 0
elsif ($n =~ /grey\d+/) { } 0 0 0
667 0 push @cs, $n;
668 }elsif ($n =~ /r\d+g\d+b\d+/){
669 0 push @cs, $n;
670 }elsif ($n =~ /rgb\d+/) {
671 0 push @cs, $n;
672 }elsif ($n =~ /grey\d+/) {
673 0 push @cs, $n;
674 }
675 }
676 #fg, 前景颜色处理, 将ANSIColor中的颜色名称, 转化为预定义好的颜色对标识
677 0 my $fg = -1;
678 0 ▶ my $fgstr = first {not $_ =~ /^on/} @cs;
Subroutine __ANON__: not called CC=1 SCAR=6.9
679 0 ▶ if (defined $fgstr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fgstr) 0 0 0
680 0 $fg = $tui->getColorID($fgstr);
681 }
682 #bg, 背景颜色处理
683 0 my $bg = -1;
684 0 ▶ my $bgstr = first {$_ =~ /^on/} @cs;
Subroutine __ANON__: not called CC=1 SCAR=6.9
685 0 ▶ if (defined $bgstr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bgstr) 0 0 0
686 0 $bg = $tui->getColorID($bgstr);
687 }
688 #以每个转义序列颜色配置作为key, 索引颜色对
689 #20之前为保留的颜色对配置
690 0 ▶ if (not exists $escMap{escStr}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $escMap{"escStr"}) 0 0 0
691 0 push @pairList, [$fg, $bg];
692 0 $escMap{$escStr} = $#pairList+20;
693 0 $tui->initPair($#pairList+20, $fg, $bg);
694 }
695 }
696  
697 #将原文中的每个转义颜色配置所对应的文字, 分段组装的显示buffer中
698 0 my @buf;
699 0 foreach my $i (0 .. $#showList) {
700 0 my $line = $showList[$i];
701 #在列表开头增加控制序列
702 0 ▶ if (not $line->[0] =~ /\e\[.*?m/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line->[0] =~ /\e\[.*?m/) 0 0 0
703 0 unshift @{$line}, "\e[0m";
704 }
705 0 my $j = 0;
706 0 foreach my $pair (pairs @{$line}){
707 0 my ($escstr, $str) = @$pair;
708 0 my $attrNum = 0;
709 0 ▶ $attrNum = $escMap{$escstr} if (exists $escMap{$escstr});
Branch: 1 branch
BranchTrueFalseTotal
if exists $escMap{$escstr} 0 0 0
710 0 $buf[$i][$j] = [$str, $attrNum];
711 0 $j ++;
712 }
713 }
714 0 return \@buf;
715 }
716  
717 #函数setPreviewStatusON, 用于指示preview的外部状态是否发生变化, 是否需要重新调用回调函数更新preview内容
718 0 ▶sub setPreviewStatusOn {
Subroutine setPreviewStatusOn: not called CC=1 SCAR=6.9
719 0 $runStatus{previewStatus} = 1;
720 }
721  
722 #函数setPreviewStatusOff, 用于关闭指示preview的外部状态
723 0 ▶sub setPreviewStatusOff {
Subroutine setPreviewStatusOff: not called CC=1 SCAR=6.9
724 0 $runStatus{previewStatus} = 0;
725 }
726  
727 #函数getPreviewStatus, 用于获取preview的外部状态
728 0 ▶sub getPreviewStatus {
Subroutine getPreviewStatus: not called CC=1 SCAR=6.9
729 0 return $runStatus{previewStatus};
730 }
731  
732 #函数showPreview, 负责调用用户定义的显示preview回调函数
733 #参数
734 #$CONFIG, 配置信息
735 #$tui, 显示模块引用
736 #$currentList, 模式匹配记录集引用
737 #$pointer, 当前记录指针
738 0 ▶sub showPreview {
Subroutine showPreview: not called CC=6 SCAR=37.4
739 0 my ($CONFIG, $algo, $tui, $currList, $pointer) = @_;
740 #若显示列表为空, 直接打印空列表, 并退出
741 0 ▶ if (not defined $currList) {return;}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $currList) 0 0 0
742 0 ▶ if (scalar @{$currList} == 0){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$currList;} == 0) 0 0 0
743 0 $tui->setPreviewBuffer(undef);
744 0 $tui->previewPrint;
745 0 return;
746 }
747  
748 #将当前记录的字符串, 切割为列表后, 传递给回调函数
749 #回调函数的参数包括, 字符串列表, 显示模块的行和列, 用于控制显示
750 0 my $currItem = unpackList($currList->[$pointer]);
751 0 my $id = $currItem->[3];
752  
753 0 my $str = $algo->getStr($id);
754 0 my @arr = split /$CONFIG->{delimiter}/, $str;
755 0 my $lines = $tui->getPreviewLines();
756 0 my $columns = $tui->getPreviewCols();
757  
758 #调用回调函数, 获得显示字符串列表引用
759 0 my $rList = &{$CONFIG->{previewFunc}}(\@arr, $lines, $columns);
760
761 #convert to utf8
762 0 foreach my $i (0 .. $#{$rList}) {
763 0 $rList->[$i] = Encode::decode_utf8($rList->[$i]);
764 }
765  
766 #转换为显示buffer, 按照配置是否显示颜色
767 0 my $buf;
768 0 ▶ if ($CONFIG->{previewWithColor}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{'previewWithColor'}) { } 0 0 0
769 0 $buf = &bufferPreviewOutputWithANSI($tui, $rList);
770 }else{
771 0 $buf = &bufferPreviewOutput($rList);
772 }
773
774 #设置显示模块的preview buffer, 并调用显示preview打印函数
775 0 $tui->setPreviewBuffer($buf);
776 0 ▶ if ($CONFIG->{previewFollow}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{'previewFollow'}) { } 0 0 0
777 0 $tui->setPreviewTail;
778 }else{
779 0 $tui->previewPrint;
780 }
781 }
782  
783 #执行用户回调函数
784 #将列表指针指向的字符串取出, 安分割符切分为数组, 作为参数调用回调函数
785 0 ▶sub execute {
Subroutine execute: not called CC=2 SCAR=17.9
786 0 my ($CONFIG, $algo, $currList, $pointer) = @_;
787 0 ▶ return if (scalar @{$currList} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$currList;} == 0 0 0 0
788  
789 0 my $currItem = unpackList($currList->[$pointer]);
790 0 my $id = $currItem->[3];
791 0 my $str = $algo->getStr($id);
792 0 my @arr = split /$CONFIG->{delimiter}/, $str;
793  
794 #调用配置中的执行回调函数
795 0 &{$CONFIG->{execFunc}}(\@arr);
796 0 return;
797 }
798  
799 #切换算法
800 0 ▶sub toggleAlgo {
Subroutine toggleAlgo: not called CC=1 SCAR=6.9
801 0 my ($CONFIG) = @_;
802
803 0 my @algoList = qw(exact v1 v2);
804 0 ▶ my $idx = firstidx {$_ eq $CONFIG->{algo}} @algoList;
Subroutine __ANON__: not called CC=1 SCAR=6.9
805 0 $idx = ($idx + 1) % 3;
806 0 $CONFIG->{algo} = $algoList[$idx];
807 }
808  
809 #缺省的preview回调函数
810 0 ▶sub defaultPreviewFunc {
Subroutine defaultPreviewFunc: not called CC=4 SCAR=30.0
811 0 my ($strList, $lines, $columns) = @_;
812  
813 0 my @rList;
814 0 ▶ if (defined $strList->[8]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $strList->[8]) 0 0 0
815 0 open PREVIEWFILE, "<$strList->[8]";
816 0 my $i = 0;
817 0 ▶ while (my $input = <PREVIEWFILE>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $input = readline PREVIEWFILE)) 0 0 0
818 0 chomp $input;
819 0 push @rList, $input;
820 0 ▶ last if ($i >= $lines);
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $lines 0 0 0
821 0 $i ++;
822 }
823 0 close PREVIEWFILE;
824 }
825 0 return \@rList;
826 }
827  
828 #使用bat做带颜色的输出的preview回调函数
829 0 ▶sub batPreviewFunc {
Subroutine batPreviewFunc: not called CC=3 SCAR=24.8
830 0 my ($strList, $lines, $columns) = @_;
831  
832 0 my @rList;
833 0 ▶ if (defined $strList->[8]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $strList->[8]) 0 0 0
834 0 my $file = $strList->[8];
835 0 my $str;
836 # open STDERR, ">>", "/dev/null" or die "cannot redirect err output";
837 # open STDERR, ">>", STDOUT or die "cannot redirect err output";
838 0 eval{
839 0 $str = qx (bat --color=always $file 2> /dev/null);
840 };
841 0 ▶ $str= "" if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
842  
843 0 @rList = split /\n/, $str;
844 # @rList = map {$rList[$_]} grep{$_ < $lines} (0 .. $#rList);
845 }
846 0 return \@rList;
847 }
848  
849 #缺省的执行回调函数
850 0 ▶sub defaultExecFunc {
Subroutine defaultExecFunc: not called CC=1 SCAR=6.9
851 0 my ($strList) = @_;
852 0 return;
853 }
854  
855 #curse应用, 调试信息输出到文件
856 # my $DEBUGFILE;
857 # sub debug {
858 # my $str = shift @_;
859 # select $DEBUGFILE;
860 # $| = 1;
861 # print $str;
862 # select STDOUT;
863 # $| = 1;
864 # }
865  
866 # main entrace
867 #主函数fzf, 根据输入的查询pattrn, 交互式显示查询的结果
868 #参数$inputs, 被检索的字符数组地址, 或者输入文件句柄用于输入信息
869 #参数$USERCONFIG, 用户配置hash地址
870 #返回检索的字符串
871 0 ▶sub fzf{
Subroutine fzf: not called CC=232 SCAR=109.0
872 0 my ($inputs, $USERCONFIG) = @_;
873  
874 # #debug file init
875 # open $DEBUGFILE, ">>debug.log";
876  
877 #融合用户配置信息和缺省配置信息
878 0 my $CONFIG = $DEFAULTCONFIG;
879 0 ▶ if (defined $USERCONFIG) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $USERCONFIG) 0 0 0
880 0 foreach (keys %{$USERCONFIG} ) {
881 0 $CONFIG->{$_}= $USERCONFIG->{$_};
882 }
883 }
884 # $CONFIG->{debug} = \&debug;
885  
886 #处理输入
887 #输入是否是文件句柄
888 0 my $isFile=0;
889 0 my $algo;
890 #生成后端cpp算法模块对象
891 0 ▶ if (not defined $CONFIG->{nth}){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $CONFIG->{'nth'}) { } 0 0 0
892 0 $algo = Search::Fzf::AlgoCpp->new($CONFIG->{tac}, $CONFIG->{caseInsensitive}, $CONFIG->{headerLines});
893 }else{
894 0 $algo = Search::Fzf::AlgoCpp->newAlgoCpp($CONFIG->{tac}, $CONFIG->{caseInsensitive}, $CONFIG->{headerLines}, 1, $CONFIG->{delimiter}, $CONFIG->{nth});
895 }
896 0 ▶ if (ref($inputs) eq 'ARRAY'){ #数组输入
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inputs eq 'ARRAY') { } 0 0 0
897 0 $algo->read($inputs);
898 }else { #文件句柄输入
899 0 $isFile = 1;
900 0 $algo->asynRead($inputs);
901 0 ▶ if (not $CONFIG->{asynRead}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($CONFIG->{"asynRead"}) 0 0 0
902 0 ▶ while(1) {last if $algo->getReaderStatus == 1;}
Branch: 1 branch
BranchTrueFalseTotal
if $algo->getReaderStatus == 1 0 0 0
903 }
904 }
905  
906 #处理header
907 0 my @header;
908 0 ▶ push (@header, $CONFIG->{header}) if(defined $CONFIG->{header});
Branch: 1 branch
BranchTrueFalseTotal
if defined $CONFIG->{"header"} 0 0 0
909 0 my $inputHeader = $algo->getHeaderStr();
910 0 push @header, @{$inputHeader};
911 0 $runStatus{headerList} = \@header;
912  
913 #匹配信息列表
914 0 my $currList ;
915 my $currLen;
916 #当前选择的记录指针
917 0 my $ptr = 0;
918 #左右移动的位置
919 0 my $move = 0;
920 #光标位置
921 0 my $cursor = 0;
922 #处理curses模块getch方法的缓冲区, 用于处理utf8宽字符编码
923 0 my @inBuf = ();
924 #输入的查询字符数组
925 0 my @pattArr;
926 0 my $iPattern = "";
927 0 my $isExpect = 0;
928
929 #init Curses
930 0 my $tui = new Search::Fzf::Tui($CONFIG); #startx, starty, width, height
931 0 ▶ $SIG{INT} = sub {$tui->closeWin;
Subroutine __ANON__: not called CC=2 SCAR=17.9
932 0 ▶ close($inputs) if $isFile;
Branch: 1 branch
BranchTrueFalseTotal
if $isFile 0 0 0
933 0 exit;};
934 0 my ($h, $w) = $tui->openWin();
935 0 &resetPointer($CONFIG, $h, $w);
936  
937 0 my $init = 1;
938 0 my $shouldPrint = 1;
939 0 my $seqLen = 1;
940 0 while(1) {
941 #读取输入命令
942 0 my ($ch, $command, $clickrow);
943 0 ▶ if ($init) {
Branch: 1 branch
BranchTrueFalseTotal
if ($init) { } 0 0 0
944 0 $command = $tui->{COMMAND_CHECK};
945 0 $init = 0;
946 }else{
947 0 ($ch, $command, $clickrow) = $tui->getc();
948 }
949
950 0 ▶ if (not defined $command){ #如果是查询字符输入
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $command) { } 0 0 0
951 #如果设置disable选项, 仅仅功能键可以使用
952 0 ▶ next if ($CONFIG->{disable});
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
953 0 ▶ next if (not (defined $ch) || length($ch) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ch or length $ch == 0 0 0 0
Condition0%0/3
not defined $ch or length $ch == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $ch or length $ch == 0
not defined $ch length $ch == 0
Truth table0%0/3
not(A) or B
A= not defined $chB= length $ch == 0
ABresult
1X1
011
000
954  
955 #处理宽字符输入
956 0 my $inStr;
957 0 ▶ if (ord ($ch) <128) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord $ch < 128) { } 0 0 0
958 0 @inBuf = ();
959 0 $inStr = $ch;
960 }else{
961 0 ▶ if (scalar(@inBuf) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @inBuf == 0) 0 0 0
962 0 ▶ if (ord($ch) >=192 && ord($ch) < 224) {
Branch: 3 branches
BranchTrueFalseTotal
if (ord $ch >= 192 and ord $ch < 224) { } 0 0 0
elsif (ord $ch >= 224 and ord $ch < 240) { } 0 0 0
elsif (ord $ch >= 240) { } 0 0 0
Condition0%0/3
ord $ch >= 192 and ord $ch < 224
!ll&&!rl&&r
000
MC/DC0%0/2
ord $ch >= 192 and ord $ch < 224
ord $ch >= 192 ord $ch < 224
Truth table0%0/3
A and B
A= ord $ch >= 192B= ord $ch < 224
ABresult
0X0
100
111
963 0 $seqLen = 2;
964 ▶ }elsif (ord($ch) >=224 && ord($ch) < 240) {
Condition0%0/3
ord $ch >= 224 and ord $ch < 240
!ll&&!rl&&r
000
MC/DC0%0/2
ord $ch >= 224 and ord $ch < 240
ord $ch >= 224 ord $ch < 240
Truth table0%0/3
A and B
A= ord $ch >= 224B= ord $ch < 240
ABresult
0X0
100
111
965 0 $seqLen = 3;
966 }elsif (ord($ch) >=240) {
967 0 $seqLen = 4;
968 }
969 }
970 0 push @inBuf, $ch;
971 0 ▶ if (scalar(@inBuf) < $seqLen) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @inBuf < $seqLen) 0 0 0
972 0 next;
973 }
974 0 ▶ $inStr = reduce {$a . $b} @inBuf;
Subroutine __ANON__: not called CC=1 SCAR=6.9
975 0 @inBuf = ();
976 0 $seqLen = 1;
977 }
978
979 #打开utf8编码标志
980 0 Encode::_utf8_on($inStr);
981 0 splice(@pattArr, $cursor, 0, $inStr);
982 0 $cursor += 1;
983 0 $shouldPrint = 1;
984 }else{ #function
985 0 ▶ if($command == $tui->{COMMAND_ABORT}) {
Branch: 63 branches
BranchTrueFalseTotal
if ($command == $tui->{'COMMAND_ABORT'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_ACCEPT'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_EXPECT_ACCEPT'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_ACCEPT_NON_EMPTY'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_BACKWARD_CHAR'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_BACKWARD_DELETE_CHAR'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_BACKWARD_DELETE_CHAR_EOF'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_BACKWARD_KILL_WORD'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_BACKWARD_WORD'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_BEGINNING_OF_LINE'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_CANCEL'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_CLEAR_SELECTION'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_CLEAR_QUERY'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_DELETE_CHAR'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_DELETE_CHAR_EOF'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_DESELECT'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_DESELECT_ALL'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_DISABLE_SEARCH'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_DOWN'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_ENABLE_SEARCH'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_END_OF_LINE'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_EXECUTE'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_FIRST'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_FORWARD_CHAR'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_FORWARD_WORD'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_JUMP'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_JUMP_ACCEPT'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_KILL_LINE'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_KILL_WORD'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_LAST'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_PAGE_DOWN'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_PAGE_UP'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_HALF_PAGE_DOWN'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_HALF_PAGE_UP'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_PREVIEW_DOWN'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_PREVIEW_UP'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_PREVIEW_PAGE_DOWN'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_PREVIEW_PAGE_UP'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_PREVIEW_HALF_PAGE_DOWN'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_PREVIEW_HALF_PAGE_UP'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_PREVIEW_BOTTOM'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_PREVIEW_TOP'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_SELECT'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_SELECT_ALL'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_TOGGLE_ALGO'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_TOGGLE'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_TOGGLE_ALL'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_TOGGLE_DOWN'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_TOGGLE_PREVIEW'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_TOGGLE_PREVIEW_POSITION'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_TOGGLE_PREVIEW_WRAP'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_TOGGLE_SEARCH'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_TOGGLE_SORT'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_TOGGLE_UP'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_UP'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_LEFT'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_RIGHT'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_HOME'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_END'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_CLICKED'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_CLICKED_ACCEPT'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_RESIZE'}) { } 0 0 0
elsif ($command == $tui->{'COMMAND_CHECK'}) { } 0 0 0
986 0 $algo->sendExitSign;
987 0 ▶ while(1) {last if $algo->getReaderStatus == 1};
Branch: 1 branch
BranchTrueFalseTotal
if $algo->getReaderStatus == 1 0 0 0
988 0 $tui->closeWin;
989 0 ▶ close($inputs) if $isFile;
Branch: 1 branch
BranchTrueFalseTotal
if $isFile 0 0 0
990 0 exit 0;
991 }elsif($command == $tui->{COMMAND_ACCEPT}){
992 #退出键
993 0 $algo->sendExitSign;
994 0 ▶ while(1) {last if $algo->getReaderStatus == 1};
Branch: 1 branch
BranchTrueFalseTotal
if $algo->getReaderStatus == 1 0 0 0
995 0 last;
996 }elsif($command == $tui->{COMMAND_EXPECT_ACCEPT}){
997 #退出键
998 0 ▶ $isExpect = 1 if ((defined $CONFIG->{expect}) && (length($CONFIG->{expect})>0));
Branch: 1 branch
BranchTrueFalseTotal
if defined $CONFIG->{"expect"} and length $CONFIG->{"expect"} > 0 0 0 0
Condition0%0/3
defined $CONFIG->{"expect"} and length $CONFIG->{"expect"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $CONFIG->{"expect"} and length $CONFIG->{"expect"} > 0
defined $CONFIG->{"expect"} length $CONFIG->{"expect"} > 0
Truth table0%0/3
A and B
A= defined $CONFIG->{"expect"}B= length $CONFIG->{"expect"} > 0
ABresult
0X0
100
111
999 0 $algo->sendExitSign;
1000 0 ▶ while(1) {last if $algo->getReaderStatus == 1};
Branch: 1 branch
BranchTrueFalseTotal
if $algo->getReaderStatus == 1 0 0 0
1001 0 last;
1002 }elsif($command == $tui->{COMMAND_ACCEPT_NON_EMPTY}) {
1003 0 ▶ if($algo->getMarkedCount() > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($algo->getMarkedCount > 0) 0 0 0
1004 0 $algo->sendExitSign;
1005 0 ▶ while(1) {last if $algo->getReaderStatus == 1};
Branch: 1 branch
BranchTrueFalseTotal
if $algo->getReaderStatus == 1 0 0 0
1006 0 last;
1007 }
1008 }elsif($command == $tui->{COMMAND_BACKWARD_CHAR}) {
1009 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1010 0 $cursor -= 1;
1011 0 ▶ $cursor = 0 if $cursor < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $cursor < 0 0 0 0
1012 0 $tui->printQuery($runStatus{inputRow}, $cursor, \@pattArr);
1013 0 $shouldPrint = 0;
1014 }elsif($command == $tui->{COMMAND_BACKWARD_DELETE_CHAR}){
1015 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1016 #回退并删除
1017 0 ▶ if ($cursor > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor > 0) { } 0 0 0
1018 0 splice(@pattArr, $cursor - 1, 1);
1019 0 $cursor -= 1;
1020 0 $shouldPrint = 1;
1021 }else {
1022 0 $shouldPrint =0;
1023 }
1024 }elsif($command == $tui->{COMMAND_BACKWARD_DELETE_CHAR_EOF}){
1025 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1026 0 ▶ if (scalar(@pattArr) == 0){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @pattArr == 0) 0 0 0
1027 0 $algo->sendExitSign;
1028 0 ▶ while(1) {last if $algo->getReaderStatus == 1};
Branch: 1 branch
BranchTrueFalseTotal
if $algo->getReaderStatus == 1 0 0 0
1029 0 $tui->closeWin;
1030 0 ▶ close($inputs) if $isFile;
Branch: 1 branch
BranchTrueFalseTotal
if $isFile 0 0 0
1031 0 exit 0;
1032 }
1033 #回退并删除, 若到头则退出
1034 0 ▶ if ($cursor >0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor > 0) { } 0 0 0
1035 0 splice(@pattArr, $cursor - 1, 1);
1036 0 $cursor -= 1;
1037 0 ▶ if (scalar(@pattArr) == 0){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @pattArr == 0) 0 0 0
1038 0 $algo->sendExitSign;
1039 0 ▶ while(1) {last if $algo->getReaderStatus == 1};
Branch: 1 branch
BranchTrueFalseTotal
if $algo->getReaderStatus == 1 0 0 0
1040 0 $tui->closeWin;
1041 0 ▶ close($inputs) if $isFile;
Branch: 1 branch
BranchTrueFalseTotal
if $isFile 0 0 0
1042 0 exit 0;
1043 }
1044 0 $shouldPrint = 1;
1045 }else {
1046 0 $shouldPrint = 0;
1047 }
1048 }elsif($command == $tui->{COMMAND_BACKWARD_KILL_WORD}){
1049 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1050
1051 0 ▶ if ($cursor > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor > 0) { } 0 0 0
1052 0 my $i = $cursor;
1053 0 ▶ while ($i > 0 && $pattArr[$i-1] =~ /\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0 and $pattArr[$i - 1] =~ /\s/) 0 0 0
Condition0%0/3
$i > 0 and $pattArr[$i - 1] =~ /\s/
!ll&&!rl&&r
000
MC/DC0%0/2
$i > 0 and $pattArr[$i - 1] =~ /\s/
$i > 0 $pattArr[$i - 1] =~ /\s/
Truth table0%0/3
A and B
A= $i > 0B= $pattArr[$i - 1] =~ /\s/
ABresult
0X0
100
111
1054 0 $i --;
1055 }
1056 0 ▶ if ($i >0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 0 0 0
1057 0 ▶ while ($i > 0 && $pattArr[$i-1] =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0 and $pattArr[$i - 1] =~ /\S/) 0 0 0
Condition0%0/3
$i > 0 and $pattArr[$i - 1] =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$i > 0 and $pattArr[$i - 1] =~ /\S/
$i > 0 $pattArr[$i - 1] =~ /\S/
Truth table0%0/3
A and B
A= $i > 0B= $pattArr[$i - 1] =~ /\S/
ABresult
0X0
100
111
1058 0 $i--;
1059 }
1060 }
1061 0 splice(@pattArr, $i, $cursor - $i);
1062 0 $cursor = $i;
1063 0 $shouldPrint = 1;
1064 }else{
1065 0 $shouldPrint = 0;
1066 }
1067 }elsif($command == $tui->{COMMAND_BACKWARD_WORD}){
1068 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1069 0 ▶ if ($cursor > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor > 0) 0 0 0
1070 0 my $i = $cursor;
1071 0 ▶ while ($i > 0 && $pattArr[$i-1] =~ /\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0 and $pattArr[$i - 1] =~ /\s/) 0 0 0
Condition0%0/3
$i > 0 and $pattArr[$i - 1] =~ /\s/
!ll&&!rl&&r
000
MC/DC0%0/2
$i > 0 and $pattArr[$i - 1] =~ /\s/
$i > 0 $pattArr[$i - 1] =~ /\s/
Truth table0%0/3
A and B
A= $i > 0B= $pattArr[$i - 1] =~ /\s/
ABresult
0X0
100
111
1072 0 $i --;
1073 }
1074 0 ▶ if ($i >0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 0 0 0
1075 0 ▶ while ($i > 0 && $pattArr[$i-1] =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0 and $pattArr[$i - 1] =~ /\S/) 0 0 0
Condition0%0/3
$i > 0 and $pattArr[$i - 1] =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$i > 0 and $pattArr[$i - 1] =~ /\S/
$i > 0 $pattArr[$i - 1] =~ /\S/
Truth table0%0/3
A and B
A= $i > 0B= $pattArr[$i - 1] =~ /\S/
ABresult
0X0
100
111
1076 0 $i--;
1077 }
1078 }
1079 0 $cursor = $i;
1080 }
1081 0 $tui->printQuery($runStatus{inputRow}, $cursor, \@pattArr);
1082 0 $shouldPrint = 0;
1083 }elsif($command == $tui->{COMMAND_BEGINNING_OF_LINE}) {
1084 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1085 0 $cursor = 0;
1086 0 $tui->printQuery($runStatus{inputRow}, $cursor, \@pattArr);
1087 0 $shouldPrint = 0;
1088 }elsif($command == $tui->{COMMAND_CANCEL}) {
1089 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1090  
1091 0 ▶ if (scalar(@pattArr) > 0){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @pattArr > 0) { } 0 0 0
1092 0 @pattArr = ();
1093 0 $cursor = 0;
1094 }else{
1095 0 $algo->sendExitSign;
1096 0 ▶ while(1) {last if $algo->getReaderStatus == 1};
Branch: 1 branch
BranchTrueFalseTotal
if $algo->getReaderStatus == 1 0 0 0
1097 0 exit 0;
1098 }
1099 }elsif($command == $tui->{COMMAND_CLEAR_SELECTION}) {
1100 0 $algo->unSetAllMarkLabel;
1101 0 $shouldPrint = 1;
1102 # }elsif($command == $tui->{COMMAND_CLOSE}) {
1103 ###########wait implement#####################################
1104 }elsif($command == $tui->{COMMAND_CLEAR_QUERY}) {
1105 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1106 0 @pattArr = ();
1107 0 $cursor = 0;
1108 0 $shouldPrint = 1;
1109 }elsif($command == $tui->{COMMAND_DELETE_CHAR}) {
1110 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1111  
1112 0 ▶ if ($cursor <= $#pattArr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor <= $#pattArr) { } 0 0 0
1113 0 splice(@pattArr, $cursor, 1);
1114 0 $shouldPrint = 1;
1115 }else {
1116 0 $shouldPrint = 0;
1117 }
1118 }elsif($command == $tui->{COMMAND_DELETE_CHAR_EOF}) {
1119 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1120 0 ▶ if (scalar(@pattArr) == 0){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @pattArr == 0) 0 0 0
1121 0 $algo->sendExitSign;
1122 0 ▶ while(1) {last if $algo->getReaderStatus == 1};
Branch: 1 branch
BranchTrueFalseTotal
if $algo->getReaderStatus == 1 0 0 0
1123 0 $tui->closeWin;
1124 0 ▶ close($inputs) if $isFile;
Branch: 1 branch
BranchTrueFalseTotal
if $isFile 0 0 0
1125 0 exit 0;
1126 }
1127  
1128 0 ▶ if ($cursor <= $#pattArr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor <= $#pattArr) { } 0 0 0
1129 0 splice(@pattArr, $cursor, 1);
1130 0 ▶ if (scalar(@pattArr) == 0){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @pattArr == 0) 0 0 0
1131 0 $algo->sendExitSign;
1132 0 ▶ while(1) {last if $algo->getReaderStatus == 1};
Branch: 1 branch
BranchTrueFalseTotal
if $algo->getReaderStatus == 1 0 0 0
1133 0 $tui->closeWin;
1134 0 ▶ close($inputs) if $isFile;
Branch: 1 branch
BranchTrueFalseTotal
if $isFile 0 0 0
1135 0 exit 0;
1136 }
1137 0 $shouldPrint = 1;
1138 }else {
1139 0 $shouldPrint = 0;
1140 }
1141 }elsif($command == $tui->{COMMAND_DESELECT}) {
1142 #取消选择键, 将字符串数组中的选择标记设置为0
1143 0 ▶ if ($CONFIG->{multi}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"multi"}) 0 0 0
1144 0 my $currItem = unpackList($currList->[$ptr]);
1145 0 my $no = $currItem->[3];
1146 0 $algo->unSetMarkLabel($no);
1147 }
1148 0 $shouldPrint = 1;
1149 }elsif($command == $tui->{COMMAND_DESELECT_ALL}) {
1150 0 ▶ if ($CONFIG->{multi}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"multi"}) 0 0 0
1151 0 $algo->unSetAllMarkLabel;
1152 }
1153 0 $shouldPrint = 1;
1154 }elsif($command == $tui->{COMMAND_DISABLE_SEARCH}) {
1155 0 $CONFIG->{disable} = 1;
1156 0 $shouldPrint = 1;
1157 }elsif($command == $tui->{COMMAND_DOWN}) { #向下滚动
1158 0 ▶ if ($CONFIG->{layout} == 0 || $CONFIG->{layout} == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CONFIG->{'layout'} == 0 or $CONFIG->{'layout'} == 2) { } 0 0 0
elsif ($CONFIG->{'layout'} == 1) { } 0 0 0
Condition0%0/3
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
$CONFIG->{"layout"} == 0 $CONFIG->{"layout"} == 2
Truth table0%0/3
A or B
A= $CONFIG->{"layout"} == 0B= $CONFIG->{"layout"} == 2
ABresult
1X1
011
000
1159 0 &movePointerDown($CONFIG, $currList, \$ptr);
1160 }elsif ($CONFIG->{layout} == 1) {
1161 0 &movePointerUp($CONFIG, $tui, $currList, \$ptr);
1162 }
1163 #preview out
1164 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1165 0 &setPreviewStatusOn;
1166 }
1167 0 $shouldPrint = 1;
1168 }elsif($command == $tui->{COMMAND_ENABLE_SEARCH}) {
1169 0 $CONFIG->{disable} = 0;
1170 0 $shouldPrint = 1;
1171 }elsif($command == $tui->{COMMAND_END_OF_LINE}) {
1172 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1173 0 $cursor = scalar(@pattArr);
1174 0 $tui->printQuery($runStatus{inputRow}, $cursor, \@pattArr);
1175 0 $shouldPrint = 0;
1176 }elsif($command == $tui->{COMMAND_EXECUTE}) {
1177 0 &execute($CONFIG, $algo, $currList, $ptr);
1178 0 $shouldPrint = 0;
1179 # }elsif($command == $tui->{COMMAND_EXECUTE_SILENT}) {
1180 ###########wait implement#####################################
1181 }elsif($command == $tui->{COMMAND_FIRST}) {
1182 0 $ptr = 0;
1183 #preview out
1184 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1185 0 &setPreviewStatusOn;
1186 }
1187 0 $shouldPrint = 1;
1188 }elsif($command == $tui->{COMMAND_FORWARD_CHAR}) {
1189 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1190 0 $cursor += 1;
1191 0 ▶ $cursor = scalar(@pattArr) if $cursor >= scalar(@pattArr);
Branch: 1 branch
BranchTrueFalseTotal
if $cursor >= scalar @pattArr 0 0 0
1192 0 $tui->printQuery($runStatus{inputRow}, $cursor, \@pattArr);
1193 0 $shouldPrint = 0;
1194 }elsif($command == $tui->{COMMAND_FORWARD_WORD}){
1195 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1196 0 ▶ if ($cursor < scalar(@pattArr)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor < scalar @pattArr) 0 0 0
1197 0 my $i = $cursor;
1198 0 ▶ while ($i <scalar(@pattArr) && $pattArr[$i+1] =~ /\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @pattArr and $pattArr[$i + 1] =~ /\s/) 0 0 0
Condition0%0/3
$i < scalar @pattArr and $pattArr[$i + 1] =~ /\s/
!ll&&!rl&&r
000
MC/DC0%0/2
$i < scalar @pattArr and $pattArr[$i + 1] =~ /\s/
$i < scalar @pattArr $pattArr[$i + 1] =~ /\s/
Truth table0%0/3
A and B
A= $i < scalar @pattArrB= $pattArr[$i + 1] =~ /\s/
ABresult
0X0
100
111
1199 0 $i ++;
1200 }
1201 0 ▶ if ($i < scalar(@pattArr)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @pattArr) 0 0 0
1202 0 ▶ while ($i < scalar(@pattArr) && $pattArr[$i+1] =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @pattArr and $pattArr[$i + 1] =~ /\S/) 0 0 0
Condition0%0/3
$i < scalar @pattArr and $pattArr[$i + 1] =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$i < scalar @pattArr and $pattArr[$i + 1] =~ /\S/
$i < scalar @pattArr $pattArr[$i + 1] =~ /\S/
Truth table0%0/3
A and B
A= $i < scalar @pattArrB= $pattArr[$i + 1] =~ /\S/
ABresult
0X0
100
111
1203 0 $i++;
1204 }
1205 }
1206 0 $cursor = $i;
1207 }
1208 0 $tui->printQuery($runStatus{inputRow}, $cursor, \@pattArr);
1209 0 $shouldPrint = 0;
1210 }elsif($command == $tui->{COMMAND_JUMP}) {
1211 #跳转
1212 0 $tui->showJumpLabel;
1213 0 $shouldPrint = 0;
1214 }elsif($command == $tui->{COMMAND_JUMP_ACCEPT}) {
1215 #跳转
1216 0 $tui->showJumpLabelAccept;
1217 0 $shouldPrint = 0;
1218 }elsif($command == $tui->{COMMAND_KILL_LINE}) {
1219 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1220 0 splice(@pattArr, $cursor);
1221 0 $shouldPrint = 1;
1222 }elsif($command == $tui->{COMMAND_KILL_WORD}) {
1223 0 ▶ next if $CONFIG->{disable};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"disable"} 0 0 0
1224 0 ▶ if ($cursor < scalar(@pattArr)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor < scalar @pattArr) { } 0 0 0
1225 0 my $i = $cursor;
1226 0 ▶ while ($i <scalar(@pattArr) && $pattArr[$i+1] =~ /\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @pattArr and $pattArr[$i + 1] =~ /\s/) 0 0 0
Condition0%0/3
$i < scalar @pattArr and $pattArr[$i + 1] =~ /\s/
!ll&&!rl&&r
000
MC/DC0%0/2
$i < scalar @pattArr and $pattArr[$i + 1] =~ /\s/
$i < scalar @pattArr $pattArr[$i + 1] =~ /\s/
Truth table0%0/3
A and B
A= $i < scalar @pattArrB= $pattArr[$i + 1] =~ /\s/
ABresult
0X0
100
111
1227 0 $i ++;
1228 }
1229 0 ▶ if ($i < scalar(@pattArr)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @pattArr) 0 0 0
1230 0 ▶ while ($i < scalar(@pattArr) && $pattArr[$i+1] =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @pattArr and $pattArr[$i + 1] =~ /\S/) 0 0 0
Condition0%0/3
$i < scalar @pattArr and $pattArr[$i + 1] =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$i < scalar @pattArr and $pattArr[$i + 1] =~ /\S/
$i < scalar @pattArr $pattArr[$i + 1] =~ /\S/
Truth table0%0/3
A and B
A= $i < scalar @pattArrB= $pattArr[$i + 1] =~ /\S/
ABresult
0X0
100
111
1231 0 $i++;
1232 }
1233 }
1234 0 splice(@pattArr, $cursor, $i - $cursor + 1);
1235 0 $shouldPrint = 1;
1236 }else{
1237 0 $shouldPrint = 0;
1238 }
1239 }elsif($command == $tui->{COMMAND_LAST}) {
1240 0 $ptr = $#{$currList};
1241 #preview out
1242 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1243 0 &setPreviewStatusOn;
1244 }
1245  
1246 0 $shouldPrint = 1;
1247 }elsif($command == $tui->{COMMAND_PAGE_DOWN}) { #向下翻动页
1248 0 ▶ if ($CONFIG->{layout} == 0 || $CONFIG->{layout} == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CONFIG->{'layout'} == 0 or $CONFIG->{'layout'} == 2) { } 0 0 0
elsif ($CONFIG->{'layout'} == 1) { } 0 0 0
Condition0%0/3
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
$CONFIG->{"layout"} == 0 $CONFIG->{"layout"} == 2
Truth table0%0/3
A or B
A= $CONFIG->{"layout"} == 0B= $CONFIG->{"layout"} == 2
ABresult
1X1
011
000
1249 0 &movePointerDown($CONFIG, $currList, \$ptr, ($tui->getHeight - 3));
1250 }elsif ($CONFIG->{layout} == 1) {
1251 0 &movePointerUp($CONFIG, $tui, $currList, \$ptr, ($tui->getHeight - 3));
1252 }
1253 #preview out
1254 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1255 0 &setPreviewStatusOn;
1256 }
1257 0 $shouldPrint = 1;
1258 }elsif($command == $tui->{COMMAND_PAGE_UP}) { #向上翻动页
1259 0 ▶ if ($CONFIG->{layout} == 0 || $CONFIG->{layout} == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CONFIG->{'layout'} == 0 or $CONFIG->{'layout'} == 2) { } 0 0 0
elsif ($CONFIG->{'layout'} == 1) { } 0 0 0
Condition0%0/3
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
$CONFIG->{"layout"} == 0 $CONFIG->{"layout"} == 2
Truth table0%0/3
A or B
A= $CONFIG->{"layout"} == 0B= $CONFIG->{"layout"} == 2
ABresult
1X1
011
000
1260 0 &movePointerUp($CONFIG, $tui, $currList, \$ptr, ($tui->getHeight - 3));
1261 }elsif ($CONFIG->{layout} == 1) {
1262 0 &movePointerDown($CONFIG, $currList, \$ptr, ($tui->getHeight - 3));
1263 }
1264 #preview out
1265 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1266 0 &setPreviewStatusOn;
1267 }
1268 0 $shouldPrint = 1;
1269 }elsif($command == $tui->{COMMAND_HALF_PAGE_DOWN}) { #向下翻动半页
1270 0 ▶ if ($CONFIG->{layout} == 0 || $CONFIG->{layout} == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CONFIG->{'layout'} == 0 or $CONFIG->{'layout'} == 2) { } 0 0 0
elsif ($CONFIG->{'layout'} == 1) { } 0 0 0
Condition0%0/3
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
$CONFIG->{"layout"} == 0 $CONFIG->{"layout"} == 2
Truth table0%0/3
A or B
A= $CONFIG->{"layout"} == 0B= $CONFIG->{"layout"} == 2
ABresult
1X1
011
000
1271 0 &movePointerDown($CONFIG, $currList, \$ptr, int($tui->getHeight / 2));
1272 }elsif ($CONFIG->{layout} == 1) {
1273 0 &movePointerUp($CONFIG, $tui, $currList, \$ptr, int($tui->getHeight / 2));
1274 }
1275 #preview out
1276 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1277 0 &setPreviewStatusOn;
1278 }
1279 0 $shouldPrint = 1;
1280 }elsif($command == $tui->{COMMAND_HALF_PAGE_UP}) { #向上翻动半页
1281 0 ▶ if ($CONFIG->{layout} == 0 || $CONFIG->{layout} == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CONFIG->{'layout'} == 0 or $CONFIG->{'layout'} == 2) { } 0 0 0
elsif ($CONFIG->{'layout'} == 1) { } 0 0 0
Condition0%0/3
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
$CONFIG->{"layout"} == 0 $CONFIG->{"layout"} == 2
Truth table0%0/3
A or B
A= $CONFIG->{"layout"} == 0B= $CONFIG->{"layout"} == 2
ABresult
1X1
011
000
1282 0 &movePointerUp($CONFIG, $tui, $currList, \$ptr, int($tui->getHeight / 2));
1283 }elsif ($CONFIG->{layout} == 1) {
1284 0 &movePointerDown($CONFIG, $currList, \$ptr, int($tui->getHeight / 2));
1285 }
1286 #preview out
1287 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1288 0 &setPreviewStatusOn;
1289 }
1290 0 $shouldPrint = 1;
1291 # }elsif($command == $tui->{COMMAND_PREVIEW}) {
1292 }elsif($command == $tui->{COMMAND_PREVIEW_DOWN}) {
1293 0 ▶ if ($CONFIG->{preview}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"}) 0 0 0
1294 0 $tui->setPreviewOff(1);
1295 # $tui->setCursor($cursor, \@pattArr);
1296 0 $tui->resetCursor;
1297 0 $shouldPrint = 0;
1298 }
1299 }elsif($command == $tui->{COMMAND_PREVIEW_UP}) {
1300 0 ▶ if ($CONFIG->{preview}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"}) 0 0 0
1301 0 $tui->setPreviewOff(-1);
1302 # $tui->setCursor($cursor, \@pattArr);
1303 0 $tui->resetCursor;
1304 0 $shouldPrint = 0;
1305 }
1306 }elsif($command == $tui->{COMMAND_PREVIEW_PAGE_DOWN}) {
1307 0 ▶ if ($CONFIG->{preview}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"}) 0 0 0
1308 0 my $lines = $tui->getPreviewLines - 1;
1309 0 $tui->setPreviewOff($lines);
1310 # $tui->setCursor($cursor, \@pattArr);
1311 0 $tui->resetCursor;
1312 0 $shouldPrint = 0;
1313 }
1314 }elsif($command == $tui->{COMMAND_PREVIEW_PAGE_UP}) {
1315 0 ▶ if ($CONFIG->{preview}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"}) 0 0 0
1316 0 my $lines = $tui->getPreviewLines - 1;
1317 0 $tui->setPreviewOff(-$lines);
1318 # $tui->setCursor($cursor, \@pattArr);
1319 0 $tui->resetCursor;
1320 0 $shouldPrint = 0;
1321 }
1322 }elsif($command == $tui->{COMMAND_PREVIEW_HALF_PAGE_DOWN}) {
1323 0 ▶ if ($CONFIG->{preview}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"}) 0 0 0
1324 0 my $lines = int ($tui->getPreviewLines/2);
1325 0 $tui->setPreviewOff($lines);
1326 # $tui->setCursor($cursor, \@pattArr);
1327 0 $tui->resetCursor;
1328 0 $shouldPrint = 0;
1329 }
1330 }elsif($command == $tui->{COMMAND_PREVIEW_HALF_PAGE_UP}) {
1331 0 ▶ if ($CONFIG->{preview}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"}) 0 0 0
1332 0 my $lines = int ($tui->getPreviewLines/2);
1333 0 $tui->setPreviewOff(- $lines);
1334 # $tui->setCursor($cursor, \@pattArr);
1335 0 $tui->resetCursor;
1336 0 $shouldPrint = 0;
1337 }
1338 }elsif($command == $tui->{COMMAND_PREVIEW_BOTTOM}) {
1339 0 ▶ if ($CONFIG->{preview}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"}) 0 0 0
1340 0 $tui->setPreviewTail;
1341 # $tui->setCursor($cursor, \@pattArr);
1342 0 $tui->resetCursor;
1343 0 $shouldPrint = 0;
1344 }
1345 }elsif($command == $tui->{COMMAND_PREVIEW_TOP}) {
1346 0 ▶ if ($CONFIG->{preview}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"}) 0 0 0
1347 0 $tui->setPreviewHead;
1348 # $tui->setCursor($cursor, \@pattArr);
1349 0 $tui->resetCursor;
1350 0 $shouldPrint = 0;
1351 }
1352 # }elsif($command == $tui->{COMMAND_RELOAD}) {
1353 }elsif($command == $tui->{COMMAND_SELECT}) {
1354 0 ▶ if ($CONFIG->{multi}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"multi"}) 0 0 0
1355 0 my $currItem = unpackList($currList->[$ptr]);
1356 0 my $no = $currItem->[3];
1357 0 $algo->setMarkLabel($no);
1358 }
1359 0 $shouldPrint = 1;
1360 }elsif($command == $tui->{COMMAND_SELECT_ALL}) {
1361 0 ▶ if ($CONFIG->{multi}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"multi"}) 0 0 0
1362 0 $algo->setAllMarkLabel;
1363 }
1364 0 $shouldPrint = 1;
1365 }elsif($command == $tui->{COMMAND_TOGGLE_ALGO}) {
1366 0 &toggleAlgo($CONFIG);
1367 0 $shouldPrint = 1;
1368 }elsif($command == $tui->{COMMAND_TOGGLE}) {
1369 0 ▶ if ($CONFIG->{multi}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"multi"}) 0 0 0
1370 0 my $currItem = unpackList($currList->[$ptr]);
1371 0 my $no = $currItem->[3];
1372 0 $algo->toggleMarkLabel($no);
1373 0 my $m = $algo->getMarkLabel($no);
1374 }
1375 0 $shouldPrint = 1;
1376 }elsif($command == $tui->{COMMAND_TOGGLE_ALL}) {
1377 0 ▶ if ($CONFIG->{multi}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"multi"}) 0 0 0
1378 0 $algo->toggleAllMarkLabel();
1379 }
1380 0 $shouldPrint = 1;
1381 }elsif($command == $tui->{COMMAND_TOGGLE_DOWN}) {
1382 0 ▶ if ($CONFIG->{multi}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"multi"}) 0 0 0
1383 0 my $currItem = unpackList($currList->[$ptr]);
1384 0 my $no = $currItem->[3];
1385 0 $algo->toggleMarkLabel($no);
1386 }
1387 0 ▶ if ($CONFIG->{layout} == 0 || $CONFIG->{layout} == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CONFIG->{'layout'} == 0 or $CONFIG->{'layout'} == 2) { } 0 0 0
elsif ($CONFIG->{'layout'} == 1) { } 0 0 0
Condition0%0/3
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
$CONFIG->{"layout"} == 0 $CONFIG->{"layout"} == 2
Truth table0%0/3
A or B
A= $CONFIG->{"layout"} == 0B= $CONFIG->{"layout"} == 2
ABresult
1X1
011
000
1388 0 &movePointerDown($CONFIG, $currList, \$ptr);
1389 }elsif ($CONFIG->{layout} == 1) {
1390 0 &movePointerUp($CONFIG, $tui, $currList, \$ptr);
1391 }
1392 #preview out
1393 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1394 0 &setPreviewStatusOn;
1395 }
1396 0 $shouldPrint = 1;
1397 # }elsif($command == $tui->{COMMAND_TOGGLE_IN}) {
1398 # }elsif($command == $tui->{COMMAND_TOGGLE_OUT}) {
1399 }elsif($command == $tui->{COMMAND_TOGGLE_PREVIEW}) {
1400 0 &togglePreview($CONFIG, $tui);
1401 0 $shouldPrint = 1;
1402 }elsif($command == $tui->{COMMAND_TOGGLE_PREVIEW_POSITION}) {
1403 0 &togglePreviewPosition($CONFIG, $tui);
1404 0 $shouldPrint = 1;
1405 }elsif($command == $tui->{COMMAND_TOGGLE_PREVIEW_WRAP}) {
1406 0 $CONFIG->{previewWrap} = ($CONFIG->{previewWrap} + 1) % 2;
1407 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1408 0 &setPreviewStatusOn;
1409 }
1410 0 $shouldPrint = 0;
1411 }elsif($command == $tui->{COMMAND_TOGGLE_SEARCH}) {
1412 0 $CONFIG->{disable} = ($CONFIG->{disable} + 1) % 2;
1413 0 $shouldPrint = 1;
1414 }elsif($command == $tui->{COMMAND_TOGGLE_SORT}) {
1415 0 $CONFIG->{sort} = ($CONFIG->{sort} + 1) % 2;
1416 0 $algo->clearMatchResult;
1417 0 $shouldPrint = 1;
1418 }elsif($command == $tui->{COMMAND_TOGGLE_UP}) {
1419 0 ▶ if ($CONFIG->{multi}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"multi"}) 0 0 0
1420 0 my $currItem = unpackList($currList->[$ptr]);
1421 0 my $no = $currItem->[3];
1422 0 $algo->toggleMarkLabel($no);
1423 }
1424  
1425 0 ▶ if ($CONFIG->{layout} == 0 || $CONFIG->{layout} == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CONFIG->{'layout'} == 0 or $CONFIG->{'layout'} == 2) { } 0 0 0
elsif ($CONFIG->{'layout'} == 1) { } 0 0 0
Condition0%0/3
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
$CONFIG->{"layout"} == 0 $CONFIG->{"layout"} == 2
Truth table0%0/3
A or B
A= $CONFIG->{"layout"} == 0B= $CONFIG->{"layout"} == 2
ABresult
1X1
011
000
1426 0 &movePointerUp($CONFIG, $tui, $currList, \$ptr);
1427 }elsif ($CONFIG->{layout} == 1) {
1428 0 &movePointerDown($CONFIG, $currList, \$ptr);
1429 }
1430 #preview out
1431 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1432 0 &setPreviewStatusOn;
1433 }
1434 0 $shouldPrint = 1;
1435 }elsif($command == $tui->{COMMAND_UP}) { #向上滚动
1436 0 ▶ if ($CONFIG->{layout} == 0 || $CONFIG->{layout} == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CONFIG->{'layout'} == 0 or $CONFIG->{'layout'} == 2) { } 0 0 0
elsif ($CONFIG->{'layout'} == 1) { } 0 0 0
Condition0%0/3
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$CONFIG->{"layout"} == 0 or $CONFIG->{"layout"} == 2
$CONFIG->{"layout"} == 0 $CONFIG->{"layout"} == 2
Truth table0%0/3
A or B
A= $CONFIG->{"layout"} == 0B= $CONFIG->{"layout"} == 2
ABresult
1X1
011
000
1437 0 &movePointerUp($CONFIG, $tui, $currList, \$ptr);
1438 }elsif ($CONFIG->{layout} == 1) {
1439 0 &movePointerDown($CONFIG, $currList, \$ptr);
1440 }
1441 #preview out
1442 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1443 0 &setPreviewStatusOn;
1444 }
1445 0 $shouldPrint = 1;
1446 }elsif($command == $tui->{COMMAND_LEFT}) { #向左滚动
1447 0 ▶ if ($CONFIG->{hScroll}) {$move = -1;};
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"hScroll"}) 0 0 0
1448 0 $shouldPrint = 1;
1449 }elsif($command == $tui->{COMMAND_RIGHT}) { #向右滚动
1450 0 ▶ if ($CONFIG->{hScroll}) {$move = 1;};
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"hScroll"}) 0 0 0
1451 0 $shouldPrint = 1;
1452 }elsif($command == $tui->{COMMAND_HOME}) { #滚动到最左侧
1453 0 ▶ if ($CONFIG->{hScroll}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"hScroll"}) 0 0 0
1454 0 &resetLeftRight($CONFIG, 1);
1455 }
1456 0 $shouldPrint = 1;
1457 }elsif($command == $tui->{COMMAND_END}) { #滚动到最右侧
1458 0 ▶ if ($CONFIG->{hScroll}){
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"hScroll"}) 0 0 0
1459 0 &resetLeftRight($CONFIG, 0);
1460 }
1461 0 $shouldPrint = 1;
1462 }elsif($command == $tui->{COMMAND_CLICKED}) {
1463 #鼠标点击
1464 0 ▶ if ($CONFIG->{layout} == 0){
Branch: 3 branches
BranchTrueFalseTotal
if ($CONFIG->{'layout'} == 0) { } 0 0 0
elsif ($CONFIG->{'layout'} == 1) { } 0 0 0
elsif ($CONFIG->{'layout'} == 2) { } 0 0 0
1465 0 $ptr = $clickrow + $runStatus{bottom};
1466 }elsif ($CONFIG->{layout} == 1) {
1467 0 $ptr = $clickrow - $runStatus{bottom};
1468 }elsif($CONFIG->{layout} == 2){ #reverse list
1469 0 $ptr = $clickrow + $runStatus{bottom};
1470 }
1471 #preview out
1472 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1473 0 &setPreviewStatusOn;
1474 }
1475 0 $shouldPrint = 1;
1476 }elsif($command == $tui->{COMMAND_CLICKED_ACCEPT}) {
1477 #鼠标点击
1478 0 ▶ if ($CONFIG->{layout} == 0){
Branch: 3 branches
BranchTrueFalseTotal
if ($CONFIG->{'layout'} == 0) { } 0 0 0
elsif ($CONFIG->{'layout'} == 1) { } 0 0 0
elsif ($CONFIG->{'layout'} == 2) { } 0 0 0
1479 0 $ptr = $clickrow + $runStatus{bottom};
1480 }elsif ($CONFIG->{layout} == 1) {
1481 0 $ptr = $clickrow - $runStatus{bottom};
1482 }elsif($CONFIG->{layout} == 2){ #reverse list
1483 0 $ptr = $clickrow + $runStatus{bottom};
1484 }
1485 0 $algo->sendExitSign;
1486 0 ▶ while(1) {last if $algo->getReaderStatus == 1};
Branch: 1 branch
BranchTrueFalseTotal
if $algo->getReaderStatus == 1 0 0 0
1487 0 last;
1488 }elsif($command == $tui->{COMMAND_RESIZE}) {
1489 0 resize($CONFIG, $tui);
1490 0 $shouldPrint = 1;
1491 }elsif($command == $tui->{COMMAND_CHECK}) {
1492 #check preview
1493 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1494 0 ▶ &setPreviewStatusOn if $CONFIG->{previewFollow};
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"previewFollow"} 0 0 0
1495 0 ▶ if (&getPreviewStatus == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (&getPreviewStatus == 1) 0 0 0
1496 0 &showPreview($CONFIG, $algo, $tui, $currList, $ptr);
1497 0 &setPreviewStatusOff;
1498 0 $tui->resetCursor;
1499 # $shouldPrint = 0;
1500 }
1501 }
1502 #check inputs
1503 0 ▶ if(($CONFIG->{asynRead} == 1) && ($isFile == 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"asynRead"} == 1 and $isFile == 1) 0 0 0
Condition0%0/3
$CONFIG->{"asynRead"} == 1 and $isFile == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$CONFIG->{"asynRead"} == 1 and $isFile == 1
$CONFIG->{"asynRead"} == 1 $isFile == 1
Truth table0%0/3
A and B
A= $CONFIG->{"asynRead"} == 1B= $isFile == 1
ABresult
0X0
100
111
1504 0 ▶ if ($algo->getReaderStatus == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($algo->getReaderStatus == 0) 0 0 0
1505 0 $shouldPrint = 1;
1506 0 $runStatus{isSpinner} = 1;
1507 }
1508 }
1509 }else{ #COMMAND_IDLE
1510 0 $shouldPrint = 0;
1511 }
1512 }
1513
1514 ##screen out
1515 #调用后端算法模块, 获得匹配列表, 匹配列表中每项为一串整数编码
1516 #若模式字符串为"", 着返回全量的NULL匹配列表, 但仅包括行号信息
1517 0 ▶ if (not $shouldPrint) {next;}
Branch: 1 branch
BranchTrueFalseTotal
unless ($shouldPrint) 0 0 0
1518 0 my $strLen = scalar @pattArr;
1519 0 ▶ if ($strLen > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($strLen > 0) { } 0 0 0
1520 0 ▶ $iPattern = reduce {$a . $b} @pattArr;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1521 0 $currList = &matchList($CONFIG, $algo, $iPattern);
1522 }else{
1523 0 $iPattern = "";
1524 0 $currList = $algo->getNullMatchList;
1525 }
1526  
1527 #根据匹配列表长度, 判断pointer指针是否越界
1528 #判断当前指针是否越界
1529 0 $currLen = scalar @{$currList};
1530 0 ▶ $ptr = $currLen-1 if $ptr > $currLen - 1;
Branch: 1 branch
BranchTrueFalseTotal
if $ptr > $currLen - 1 0 0 0
1531 0 ▶ $ptr = 0 if $ptr <0;
Branch: 1 branch
BranchTrueFalseTotal
if $ptr < 0 0 0 0
1532 #根据光标位置设置输出到屏幕的底部和头部信息
1533 0 &setPointer($CONFIG, $ptr, $move);
1534  
1535 #生成显示缓冲, 由于currList数量可能很大, 为加快显示速度, 仅对显示尺寸内的列表对象生成显示信息
1536 0 $tui->setBuffer(&bufferOutputWithFormat($CONFIG, $algo, $currList, $iPattern));
1537  
1538 #若没有输入, 重置为靠右显示
1539 # &resetLeftRight(0) if ($CONFIG->{keepRight} && $strLen > 0);
1540 0 ▶ &resetLeftRight($CONFIG, 0) if ($CONFIG->{keepRight});
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"keepRight"} 0 0 0
1541 #对输入匹配的位置靠右跟随滚动
1542 0 ▶ if ($currLen > 0 && $strLen > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($currLen > 0 and $strLen > 0) 0 0 0
Condition0%0/3
$currLen > 0 and $strLen > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$currLen > 0 and $strLen > 0
$currLen > 0 $strLen > 0
Truth table0%0/3
A and B
A= $currLen > 0B= $strLen > 0
ABresult
0X0
100
111
1543 0 my $currItem = unpackList($currList->[$ptr]);
1544 0 ▶ &alignRight($CONFIG, $currItem->[2][-1]) if($CONFIG->{hScrollOff} >= 0) ;
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIG->{"hScrollOff"} >= 0 0 0 0
1545 }
1546  
1547 # 显示部分包括, 显示正文列表, 高亮显示当前行, 重绘显示查询行
1548 0 $tui->print($runStatus{left}, $runStatus{right});
1549 0 $tui->printPointer($runStatus{before}, $runStatus{location}, $runStatus{left}, $runStatus{right});
1550 # #preview out
1551 0 ▶ if($CONFIG->{preview} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CONFIG->{"preview"} == 1) 0 0 0
1552 0 &setPreviewStatusOn;
1553 }
1554 # #设置输入的光标
1555 0 $tui->printQuery($runStatus{inputRow}, $cursor, \@pattArr, &getSpinnerChar);
1556 0 $shouldPrint = 0;
1557 } #end loop
1558 0 $tui->closeWin();
1559  
1560 #返回选中的字符串
1561 0 my $retArr;
1562 0 ▶ if ($algo->getMarkedCount > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($algo->getMarkedCount > 0) { } 0 0 0
1563 0 my $sls = $algo->getMarkedCount;
1564 0 $retArr = $algo->getMarkedStr();
1565 }else{
1566 #返回当前指针指向的记录
1567 0 ▶ if (scalar @{$currList} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$currList;} > 0) { } 0 0 0
1568 0 my $currItem = unpackList($currList->[$ptr]);
1569 0 my $id = $currItem->[3];
1570 0 $retArr = [$algo->getStr($id)];
1571 }else {
1572 0 $retArr = [];
1573 }
1574 }
1575 0 ▶ unshift @{$retArr}, $CONFIG->{expect} if $isExpect;
Branch: 1 branch
BranchTrueFalseTotal
if $isExpect 0 0 0
1576 0 return $retArr;
1577 }
1578  
1579 1;
↑ Summary AlgoCpp/t/00-load.t »