blib/lib/Curses/UI/TextEditor.pm

filter: Statementstmt 31.2% 176 / 564 Branchbran 21.7% 60 / 276 Conditioncond 24.5% 15 / 61 MC/DCmcdc 0.0% 0 / 37 Subroutinesub 29.8% 17 / 57 Podpod 25.4% 13 / 51 totaltotal 26.8% 281 / 1046 CC 168 SCAR 42.3
CC
168
Cov
28%
event_keypress
240.0
draw_text
156.7
layout_content
107.1
CRAP 68.7
« blib/lib/Curses/UI/Calendar.pm ↑ Summary blib/lib/Curses/UI/Dialog/Question.pm »
1 # ----------------------------------------------------------------------
2 # Curses::UI::TextEditor
3 #
4 # (c) 2001-2002 by Maurice Makaay. All rights reserved.
5 # This file is part of Curses::UI. Curses::UI is free software.
6 # You can redistribute it and/or modify it under the same terms
7 # as perl itself.
8 #
9 # Currently maintained by Marcus Thiesen
10 # e-mail: marcus@cpan.thiesenweb.de
11 # ----------------------------------------------------------------------
12  
13 # TODO: fix dox
14  
15 package Curses::UI::TextEditor;
16  
17 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use Curses;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Curses::UI::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use Curses::UI::Widget;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Curses::UI::Searchable;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
24 $VERSION
25 @ISA
26 2 );
27  
28 2 $VERSION = '1.5';
29  
30 2 @ISA = qw(
31 Curses::UI::Widget
32 Curses::UI::Common
33 Curses::UI::Searchable
34 );
35
36 # Configuration: routine name to subroutine mapping.
37 2 my %routines = (
38 'loose-focus' => \&loose_focus,
39 'undo' => \&undo,
40 'paste' => \&paste,
41 'delete-till-eol' => \&delete_till_eol,
42 'delete-line' => \&delete_line,
43 'delete-character' => \&delete_character,
44 'add-string' => \&add_string,
45 'clear-line' => \&clear_line,
46 'backspace' => \&backspace,
47 'newline' => \&newline,
48 'toggle-showhardreturns' => \&toggle_showhardreturns,
49 'toggle-showoverflow' => \&toggle_showoverflow,
50 'toggle-wrapping' => \&toggle_wrapping,
51 'cursor-right' => \&cursor_right,
52 'cursor-left' => \&cursor_left,
53 'cursor-up' => \&cursor_up,
54 'cursor-down' => \&cursor_down,
55 'cursor-pageup' => \&cursor_pageup,
56 'cursor-pagedown' => \&cursor_pagedown,
57 'cursor-scrlinestart' => \&cursor_to_scrlinestart,
58 'cursor-scrlineend' => \&cursor_to_scrlineend,
59 'cursor-home' => \&cursor_to_home,
60 'cursor-end' => \&cursor_to_end,
61 'search-forward' => \&search_forward,
62 'search-backward' => \&search_backward,
63 'mouse-button1' => \&mouse_button1,
64 );
65  
66 # Configuration: binding to routine name mapping.
67 2 my %basebindings = (
68 CUI_TAB() => 'loose-focus',
69 KEY_BTAB() => 'loose-focus',
70 KEY_LEFT() => 'cursor-left',
71 "\cB" => 'cursor-left',
72 KEY_RIGHT() => 'cursor-right',
73 "\cF" => 'cursor-right',
74 KEY_DOWN() => 'cursor-down',
75 "\cN" => 'cursor-down',
76 KEY_UP() => 'cursor-up',
77 "\cP" => 'cursor-up',
78 KEY_PPAGE() => 'cursor-pageup',
79 KEY_NPAGE() => 'cursor-pagedown',
80 KEY_HOME() => 'cursor-home',
81 KEY_END() => 'cursor-end',
82 "\cA" => 'cursor-scrlinestart',
83 "\cE" => 'cursor-scrlineend',
84 "\cW" => 'toggle-wrapping',
85 "\cR" => 'toggle-showhardreturns',
86 "\cT" => 'toggle-showoverflow',
87 );
88  
89 2 my %viewbindings = (
90 "/" => 'search-forward',
91 "?" => 'search-backward',
92 CUI_SPACE() => 'cursor-pagedown',
93 "-" => 'cursor-pageup',
94 "]" => 'cursor-pagedown',
95 "[" => 'cursor-pageup',
96 );
97  
98 2 my %editbindings = (
99 '' => 'add-string',
100 "\cZ" => 'undo',
101 KEY_DL() => 'delete-line',
102 "\cY" => 'delete-line',
103 "\cX" => 'delete-line',
104 "\cK" => 'delete-till-eol',
105 KEY_DC() => 'delete-character',
106 "\cV" => 'paste',
107 "\cU" => 'clear-line',
108 KEY_BACKSPACE() => 'backspace',
109 KEY_ENTER() => 'newline',
110 );
111  
112 # Some viewbindings that should not be available in %bindings;
113 2 $viewbindings{'h'} = 'cursor-left';
114 2 $viewbindings{'j'} = 'cursor-down';
115 2 $viewbindings{'k'} = 'cursor-up';
116 2 $viewbindings{'l'} = 'cursor-right';
117  
118 sub new ()
119 1 ▶{
Subroutine new: called CC=10 SCAR=26.0
Pod documented
120 1 my $class = shift;
121  
122 1 my %userargs = @_;
123 1 keys_to_lowercase(\%userargs);
124  
125 1 my %args = (
126 # Parent info
127 -parent => undef, # the parent object
128  
129 # Position and size
130 -x => 0, # horizontal position (rel. to -window)
131 -y => 0, # vertical position (rel. to -window)
132 -width => undef, # horizontal editsize, undef = stretch
133 -height => undef, # vertical editsize, undef = stretch
134 -singleline => 0, # single line mode or not?
135  
136 # Initial state
137 -text => '', # data
138 -pos => 0, # cursor position
139  
140 # General options
141 -border => undef, # use border?
142 -showlines => undef, # underline lines?
143 -sbborder => undef, # square bracket border?
144 -undolevels => 10, # number of undolevels. 0 = infinite
145 -maxlength => 0, # the maximum length. 0 = infinite
146 -showoverflow => 1, # show overflow characters.
147 -regexp => undef, # regexp to match the text against
148 -toupper => 0, # convert text to uppercase?
149 -tolower => 0, # convert text to lowercase?
150 -homeonblur => 0, # cursor to homepos on blur?
151 -vscrollbar => 0, # show vertical scrollbar
152 -hscrollbar => 0, # show horizontal scrollbar
153 -readonly => 0, # only used as viewer?
154 -reverse => 0, # show in reverse
155  
156 # Single line options
157 -password => undef, # masquerade chars with given char
158  
159 # Multiple line options
160 -showhardreturns => 0, # show hard returns with diamond char?
161 -wrapping => 0, # do wrap?
162 -maxlines => undef, # max lines. undef = infinite
163
164  
165 # Events
166 -onchange => undef, # onChange event handler
167
168 # Color
169 -bg => -1,
170 -fg => -1,
171  
172  
173 %userargs,
174
175 -routines => {%routines}, # binding routines
176 -bindings => {}, # these are set by readonly()
177  
178 # Init values
179 -nocursor => 0,
180 -scr_lines => [],
181 -yscrpos => 0,
182 -xscrpos => 0,
183 -ypos => 0,
184 -xpos => 0,
185 -focus => 0,
186 );
187  
188 # Let -text always be defined.
189 1 ▶ $args{-text} = '' unless defined $args{-text};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"-text"} 0 1 1
190  
191 # If initially wrapping is on, then we do not use
192 # overflow chars.
193 1 ▶ $args{-showoverflow} = 0 if $args{-wrapping};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"-wrapping"} 0 1 1
194  
195 # Single line mode? Compute the needed height and set it.
196 1 ▶ if ($args{-singleline})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"-singleline"}) 0 1 1
197 {
198 0 my $height = height_by_windowscrheight(1,%args);
199 0 $args{-height} = $height;
200 }
201
202 # Create the Widget.
203 1 my $this = $class->SUPER::new( %args );
204  
205 # Check if we should wrap or not.
206 1 ▶ $this->{-wrapping} = 0 if $this->{-singleline};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-singleline"} 0 1 1
207  
208 1 $this->{-undotext} = [$this->{-text}];
209 1 $this->{-undopos} = [$this->{-pos}];
210 1 $this->{-xscrpos} = 0; # X position for cursor on screen
211 1 $this->{-yscrpos} = 0; # Y position for cursor on screen
212 1 $this->{-xpos} = 0; # X position for cursor in the document
213 1 $this->{-ypos} = 0; # Y position for cursor in the document
214  
215 # Restrict the password character to a single character.
216 1 ▶ $this->set_password_char($this->{-password}) if defined $this->{-password};
Branch: 1 branch
BranchTrueFalseTotal
if defined $this->{"-password"} 0 1 1
217  
218 # Single line? Then initial text may only be singleline.
219 1 ▶ if ($this->{-singleline} and
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-singleline"} and defined $this->{"-text"} and $this->{"-text"} =~ /\n/) 0 1 1
Condition33%2/6
$this->{"-singleline"} and defined $this->{"-text"} and $this->{"-text"} =~ /\n/
!ll&&!rl&&r
100
$this->{"-singleline"} and defined $this->{"-text"}
!ll&&!rl&&r
100
MC/DC0%0/3
$this->{"-singleline"} and defined $this->{"-text"} and $this->{"-text"} =~ /\n/
$this->{"-singleline"} defined $this->{"-text"} $this->{"-text"} =~ /\n/
Truth table25%1/4
A and B and C
A= $this->{"-singleline"}B= defined $this->{"-text"}C= $this->{"-text"} =~ /\n/
ABCresult
0XX0
10X0
1100
1111
220 defined $this->{-text} and $this->{-text} =~ /\n/)
221 {
222 0 my $lines = $this->split_to_lines($this->{-text});
223 0 $this->{-text} = $lines->[0];
224 }
225  
226 1 $this->readonly($this->{-readonly});
227 1 $this->layout_content;
228  
229 1 ▶ if ($Curses::UI::ncurses_mouse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Curses::UI::ncurses_mouse) 1 0 1
230 1 $this->set_mouse_binding('mouse-button1', BUTTON1_CLICKED());
231 }
232  
233 1 return $this;
234 }
235  
236 sub getrealxpos()
237 4 ▶{
Subroutine getrealxpos: called CC=2 SCAR=9.2
Pod undocumented
238 4 my $this = shift;
239  
240 4 my $offset = $this->{-xscrpos};
241 4 my $length = $this->{-xpos} - $this->{-xscrpos};
242 4 ▶ return 0 if $length <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $length <= 0 4 0 4
243  
244 0 my $current_line = $this->{-scr_lines}->[$this->{-ypos}];
245 my $before_cursor = substr(
246 $current_line,
247 $this->{-xscrpos}, # Screen's x position
248 $this->{-xpos} - $this->{-xscrpos} # Space up to the cursor
249 0 );
250  
251 0 my $realxpos = scrlength($before_cursor);
252  
253 0 return $realxpos;
254 }
255  
256 sub layout()
257 1 ▶{
Subroutine layout: called CC=6 SCAR=22.5
Pod documented
258 1 my $this = shift;
259 1 ▶ $this->SUPER::layout() or return;
Branch: 1 branch
BranchTrueFalseTotal
$this->SUPER::layout or return 1 0 1
260  
261 # Scroll up if we can and the number of visible lines
262 # is smaller than the number of available lines in the screen.
263 my $inscreen = ($this->canvasheight
264 - ($this->number_of_lines
265 1 - $this->{-yscrpos}));
266 1 ▶ while ($this->{-yscrpos} > 0 and
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-yscrpos"} > 0 and $inscreen < $this->canvasheight) 0 1 1
Condition33%1/3
$this->{"-yscrpos"} > 0 and $inscreen < $this->canvasheight
!ll&&!rl&&r
100
MC/DC0%0/2
$this->{"-yscrpos"} > 0 and $inscreen < $this->canvasheight
$this->{"-yscrpos"} > 0 $inscreen < $this->canvasheight
Truth table33%1/3
A and B
A= $this->{"-yscrpos"} > 0B= $inscreen < $this->canvasheight
ABresult
0X0
100
111
267 $inscreen < $this->canvasheight)
268 {
269 0 $this->{-yscrpos}--;
270 $inscreen = ($this->canvasheight
271 - ($this->number_of_lines
272 0 - $this->{-yscrpos}));
273 }
274
275 # Scroll left if we can and the number of visible columns
276 # is smaller than the number of available columns in the screen.
277 $inscreen = ($this->canvaswidth
278 - ($this->number_of_columns
279 1 - $this->{-xscrpos}));
280 1 ▶ while ($this->{-xscrpos} > 0 and $inscreen < $this->canvaswidth)
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-xscrpos"} > 0 and $inscreen < $this->canvaswidth) 0 1 1
Condition33%1/3
$this->{"-xscrpos"} > 0 and $inscreen < $this->canvaswidth
!ll&&!rl&&r
100
MC/DC0%0/2
$this->{"-xscrpos"} > 0 and $inscreen < $this->canvaswidth
$this->{"-xscrpos"} > 0 $inscreen < $this->canvaswidth
Truth table33%1/3
A and B
A= $this->{"-xscrpos"} > 0B= $inscreen < $this->canvaswidth
ABresult
0X0
100
111
281 {
282 0 $this->{-xscrpos}--;
283 $inscreen = ($this->canvaswidth
284 - ($this->number_of_columns
285 0 - $this->{-xscrpos}));
286 }
287  
288 1 $this->layout_content();
289 1 return $this;
290 }
291  
292 sub layout_content()
293 4 ▶{
Subroutine layout_content: called CC=34 SCAR=46.7
Pod documented
294 4 my $this = shift;
295 4 ▶ return $this if $Curses::UI::screen_too_small;
Branch: 1 branch
BranchTrueFalseTotal
if $Curses::UI::screen_too_small 0 4 4
296
297 # ----------------------------------------------------------------------
298 # Build an array of lines to display and determine the cursor position
299 # ----------------------------------------------------------------------
300  
301 4 my $lines_src = $this->split_to_lines($this->{-text});
302 4 foreach (@$lines_src) {$_ .= "\n"}
303 4 $lines_src->[-1] =~ s/\n$/ /;
304
305 # No lines available? Then create an array.
306 4 ▶ $lines_src = [""] unless @$lines_src;
Branch: 1 branch
BranchTrueFalseTotal
unless @$lines_src 0 4 4
307  
308 # No out of bound values for -pos.
309 4 ▶ $this->{-pos} = 0 unless defined $this->{-pos};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{"-pos"} 0 4 4
310 4 ▶ $this->{-pos} = 0 if $this->{-pos} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-pos"} < 0 0 4 4
311 $this->{-pos} = length($this->{-text})
312 4 ▶ if $this->{-pos} >= length($this->{-text});
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-pos"} >= length $this->{"-text"} 2 2 4
313  
314 # Do line wrapping if needed and store the lines
315 # to display in -scr_lines. Compute the x- and
316 # y-position of the cursor in the text.
317 4 my $lines = [];
318 4 my ($xpos, $ypos, $trackpos) = (undef, 0, 0);
319 4 foreach my $line (@$lines_src)
320 {
321 4 my $add = [];
322 4 ▶ if ($this->{-wrapping}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-wrapping'}) { } 0 4 4
323 0 $add = $this->text_wrap($line, $this->canvaswidth, WORDWRAP);
324 } else {
325 4 $add = [$line];
326 }
327 4 push @$lines, @$add;
328
329 4 ▶ unless (defined $xpos)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $xpos) 4 0 4
330 {
331 4 foreach (@$add)
332 {
333 4 my $newtrackpos = $trackpos + length($_);
334 4 ▶ if ( $this->{-pos} < $newtrackpos )
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-pos"} < $newtrackpos) 4 0 4
335 {
336 4 $xpos = length(substr($_, 0, ($this->{-pos}-$trackpos)));
337 }
338 4 $trackpos = $newtrackpos;
339 4 ▶ last if defined $xpos;
Branch: 1 branch
BranchTrueFalseTotal
if defined $xpos 4 0 4
340 0 $ypos++;
341 }
342 }
343 }
344
345 4 $this->{-scr_lines} = $lines;
346 4 ▶ unless ($this->{-readonly})
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->{"-readonly"}) 4 0 4
347 {
348 4 $this->{-xpos} = $xpos;
349 4 $this->{-ypos} = $ypos;
350 }
351  
352 # ----------------------------------------------------------------------
353 # Handle vertical scrolling of the screen
354 # ----------------------------------------------------------------------
355  
356 # Scroll down if needed.
357 4 ▶ if ( ($this->{-ypos}-$this->{-yscrpos}) >= $this->canvasheight ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($this->{'-ypos'} - $this->{'-yscrpos'} >= $this->canvasheight) { } 0 4 4
elsif ($this->{'-ypos'} < $this->{'-yscrpos'}) { } 0 4 4
358 0 $this->{-yscrpos} = $this->{-ypos} - $this->canvasheight + 1;
359 }
360  
361 # Scroll up if needed.
362 elsif ( $this->{-ypos} < $this->{-yscrpos} ) {
363 0 $this->{-yscrpos} = $this->{-ypos};
364 }
365  
366 # Check bounds.
367 4 ▶ $this->{-yscrpos} = 0 if $this->{-yscrpos} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-yscrpos"} < 0 0 4 4
368 4 ▶ $this->{-yscrpos} = @$lines if $this->{-yscrpos} > @$lines;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-yscrpos"} > @$lines 0 4 4
369  
370  
371 # ----------------------------------------------------------------------
372 # Handle horizontal scrolling of the screen
373 # ----------------------------------------------------------------------
374  
375 # If wrapping is enabled, then check for horizontal scrolling.
376 # Else make the -xscrpos fixed to 0.
377 4 ▶ unless ($this->{-readonly})
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->{"-readonly"}) 4 0 4
378 {
379 4 ▶ unless ($this->{-wrapping})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-wrapping'}) { } 0 4 4
380 {
381 4 my $realxpos = $this->getrealxpos;
382
383 # If overflows have to be shown, the cursor may not
384 # be set to the first or the last position of the
385 # screen.
386 my $wrapborder =
387 (not $this->{-wrapping} and $this->{-showoverflow})
388 4 ▶ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!$this->{'-wrapping'} && $this->{'-showoverflow'} ? : 4 0 4
Condition33%1/3
not $this->{"-wrapping"} and $this->{"-showoverflow"}
!ll&&!rl&&r
004
MC/DC0%0/2
not $this->{"-wrapping"} and $this->{"-showoverflow"}
not $this->{"-wrapping"} $this->{"-showoverflow"}
Truth table33%1/3
not(A) and B
A= not $this->{"-wrapping"}B= $this->{"-showoverflow"}
ABresult
0X0
100
111
389
390 # Scroll left if needed.
391 4 ▶ if ($realxpos < $wrapborder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($realxpos < $wrapborder) 4 0 4
392 4 ▶ while ($realxpos < ($wrapborder + int($this->canvaswidth/3))
Branch: 1 branch
BranchTrueFalseTotal
if ($realxpos < $wrapborder + int($this->canvaswidth / 3) and $this->{"-xscrpos"} > 0) 0 4 4
Condition33%1/3
$realxpos < $wrapborder + int($this->canvaswidth / 3) and $this->{"-xscrpos"} > 0
!ll&&!rl&&r
040
MC/DC0%0/2
$realxpos < $wrapborder + int($this->canvaswidth / 3) and $this->{"-xscrpos"} > 0
$realxpos < $wrapborder + int($this->canvaswidth / 3) $this->{"-xscrpos"} > 0
Truth table33%1/3
A and B
A= $realxpos < $wrapborder + int($this->canvaswidth / 3)B= $this->{"-xscrpos"} > 0
ABresult
0X0
100
111
393 and $this->{-xscrpos} > 0) {
394 0 $this->{-xscrpos}--;
395 0 $realxpos = $this->getrealxpos;
396 }
397 }
398
399 # Scroll right if needed.
400 4 ▶ if ($realxpos > ($this->canvaswidth - 1 - $wrapborder)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($realxpos > $this->canvaswidth - 1 - $wrapborder) 0 4 4
401 0 ▶ while ($realxpos > 2*int($this->canvaswidth/3) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($realxpos > 2 * int($this->canvaswidth / 3)) 0 0 0
402 0 $this->{-xscrpos}++;
403 0 $realxpos = $this->getrealxpos;
404 }
405 }
406 }
407 else
408 {
409 0 $this->{-xscrpos} = 0;
410 }
411 }
412  
413 # Check bounds.
414 4 ▶ $this->{-xscrpos} = 0 if $this->{-xscrpos} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-xscrpos"} < 0 0 4 4
415 4 ▶ $this->{-xscrpos} = $this->{-xpos} if $this->{-xscrpos} > $this->{-xpos};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-xscrpos"} > $this->{"-xpos"} 0 4 4
416  
417 # ----------------------------------------------------------------------
418 # Layout horizontal scrollbar.
419 # ----------------------------------------------------------------------
420  
421 4 ▶ if (($this->{-hscrollbar} and not $this->{-wrapping}) or $this->{-readonly})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-hscrollbar'} and not $this->{'-wrapping'} or $this->{'-readonly'}) { } 0 4 4
Condition33%2/6
$this->{"-hscrollbar"} and not $this->{"-wrapping"} or $this->{"-readonly"}
l!l&&r!l&&!r
004
$this->{"-hscrollbar"} and not $this->{"-wrapping"}
!ll&&!rl&&r
400
MC/DC0%0/3
$this->{"-hscrollbar"} and not $this->{"-wrapping"} or $this->{"-readonly"}
$this->{"-hscrollbar"} not $this->{"-wrapping"} $this->{"-readonly"}
Truth table20%1/5
A and not(B) or C
A= $this->{"-hscrollbar"}B= not $this->{"-wrapping"}C= $this->{"-readonly"}
ABCresult
11X1
0X11
1011
0X00
1000
422 {
423 0 my $longest_line = $this->number_of_columns;
424 0 $this->{-hscrolllen} = $longest_line + 1;
425 0 $this->{-hscrollpos} = $this->{-xscrpos};
426 } else {
427 4 $this->{-hscrolllen} = 0;
428 4 $this->{-hscrollpos} = 0;
429 }
430  
431
432 # ----------------------------------------------------------------------
433 # Layout vertical scrollbar
434 # ----------------------------------------------------------------------
435  
436 4 ▶ if ($this->{-vscrollbar} or $this->{-readonly})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-vscrollbar'} or $this->{'-readonly'}) { } 0 4 4
Condition33%1/3
$this->{"-vscrollbar"} or $this->{"-readonly"}
l!l&&r!l&&!r
004
MC/DC0%0/2
$this->{"-vscrollbar"} or $this->{"-readonly"}
$this->{"-vscrollbar"} $this->{"-readonly"}
Truth table33%1/3
A or B
A= $this->{"-vscrollbar"}B= $this->{"-readonly"}
ABresult
1X1
011
000
437 {
438 0 $this->{-vscrolllen} = @{$this->{-scr_lines}};
439 0 $this->{-vscrollpos} = $this->{-yscrpos};
440 } else {
441 4 $this->{-vscrolllen} = 0;
442 4 $this->{-vscrollpos} = 0;
443 }
444  
445 4 return $this;
446 }
447  
448 sub draw_text(;$)
449 1 ▶{
Subroutine draw_text: called CC=32 SCAR=50.5
Pod undocumented
450 1 my $this = shift;
451 1 ▶ my $no_doupdate = shift || 0;
Condition50%1/2
shift() || 0
l!l
10
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
452 1 ▶ return $this if $Curses::UI::screen_too_small;
Branch: 1 branch
BranchTrueFalseTotal
if $Curses::UI::screen_too_small 0 1 1
453  
454 # Return immediately if this object is hidden.
455 1 ▶ return $this if $this->hidden;
Branch: 1 branch
BranchTrueFalseTotal
if $this->hidden 0 1 1
456  
457 # Turn on underlines and fill the screen with lines
458 # if neccessary.
459 1 ▶ if ($this->{-showlines} or $this->{-reverse})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-showlines"} or $this->{"-reverse"}) 0 1 1
Condition33%1/3
$this->{"-showlines"} or $this->{"-reverse"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$this->{"-showlines"} or $this->{"-reverse"}
$this->{"-showlines"} $this->{"-reverse"}
Truth table33%1/3
A or B
A= $this->{"-showlines"}B= $this->{"-reverse"}
ABresult
1X1
011
000
460 {
461 0 ▶ $this->{-canvasscr}->attron(A_UNDERLINE) if ($this->{-showlines});;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-showlines"} 0 0 0
462 0 ▶ $this->{-canvasscr}->attron(A_REVERSE) if ($this->{-reverse});
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-reverse"} 0 0 0
463 0 for my $y (0..$this->canvasheight-1) {
464 0 $this->{-canvasscr}->addstr($y, 0, " "x($this->canvaswidth));
465 }
466 }
467  
468 # Draw the text.
469 1 for my $id (0 .. $this->canvasheight - 1)
470 {
471 # Let there be color
472 2 ▶ if ($Curses::UI::color_support) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Curses::UI::color_support) 0 2 2
473 0 my $co = $Curses::UI::color_object;
474 my $pair = $co->get_color_pair(
475 $this->{-fg},
476 0 $this->{-bg});
477  
478 0 $this->{-canvasscr}->attron(COLOR_PAIR($pair));
479  
480 }
481  
482 2 ▶ if (defined $this->{-search_highlight}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this->{'-search_highlight'} and $this->{'-search_highlight'} == $id + $this->{'-yscrpos'}) { } 0 2 2
Condition33%1/3
defined $this->{"-search_highlight"} and $this->{"-search_highlight"} == $id + $this->{"-yscrpos"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $this->{"-search_highlight"} and $this->{"-search_highlight"} == $id + $this->{"-yscrpos"}
defined $this->{"-search_highlight"} $this->{"-search_highlight"} == $id + $this->{"-yscrpos"}
Truth table33%1/3
A and B
A= defined $this->{"-search_highlight"}B= $this->{"-search_highlight"} == $id + $this->{"-yscrpos"}
ABresult
0X0
100
111
483 and $this->{-search_highlight} == ($id+$this->{-yscrpos})) {
484 0 ▶ $this->{-canvasscr}->attron(A_REVERSE) if (not $this->{-reverse});
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"-reverse"} 0 0 0
485 0 ▶ $this->{-canvasscr}->attroff(A_REVERSE) if ($this->{-reverse});
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-reverse"} 0 0 0
486 } else {
487 2 ▶ $this->{-canvasscr}->attroff(A_REVERSE) if (not $this->{-reverse});
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"-reverse"} 2 0 2
488 2 ▶ $this->{-canvasscr}->attron(A_REVERSE) if ($this->{-reverse});
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-reverse"} 0 2 2
489 }
490  
491 2 my $l = $this->{-scr_lines}->[$id + $this->{-yscrpos}];
492 2 ▶ if (defined $l)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $l) { } 1 1 2
493 {
494 # Get the part of the line that is in view.
495 1 my $inscreen = '';
496 1 my $fromxscr = '';
497 1 ▶ if ($this->{-xscrpos} < length($l))
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-xscrpos"} < length $l) 1 0 1
498 {
499 1 $fromxscr = substr($l, $this->{-xscrpos}, length($l));
500 1 $inscreen = ($this->text_wrap(
501 $fromxscr,
502 $this->canvaswidth,
503 NO_WORDWRAP))->[0];
504 }
505  
506 # Masquerading of password fields.
507 1 ▶ if ($this->{-singleline} and defined $this->{-password})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-singleline"} and defined $this->{"-password"}) 0 1 1
Condition33%1/3
$this->{"-singleline"} and defined $this->{"-password"}
!ll&&!rl&&r
100
MC/DC0%0/2
$this->{"-singleline"} and defined $this->{"-password"}
$this->{"-singleline"} defined $this->{"-password"}
Truth table33%1/3
A and B
A= $this->{"-singleline"}B= defined $this->{"-password"}
ABresult
0X0
100
111
508 {
509 # Don't masq the endspace which we
510 # added ourselves.
511 0 $inscreen =~ s/\s$//;
512
513 # Substitute characters.
514 0 $inscreen =~ s/[^\n]/$this->{-password}/g;
515 }
516  
517 # Clear line.
518 $this->{-canvasscr}->addstr(
519 1 $id, 0,
520 " "x$this->canvaswidth
521 );
522  
523 # Strip newline and replace by diamond character
524 # if the showhardreturns option is on.
525 1 ▶ if ($inscreen =~ /\n/)
Branch: 1 branch
BranchTrueFalseTotal
if ($inscreen =~ /\n/) { } 0 1 1
526 {
527 0 $inscreen =~ s/\n//;
528 0 $this->{-canvasscr}->addstr($id, 0, $inscreen);
529 0 ▶ if ($this->{-showhardreturns})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-showhardreturns"}) 0 0 0
530 {
531 0 ▶ if ($this->root->compat)
Branch: 1 branch
BranchTrueFalseTotal
if ($this->root->compat) { } 0 0 0
532 {
533 0 $this->{-canvasscr}->addch($id, scrlength($inscreen),'@');
534 } else {
535 0 $this->{-canvasscr}->attron(A_ALTCHARSET);
536 0 $this->{-canvasscr}->addch($id, scrlength($inscreen),'`');
537 0 $this->{-canvasscr}->attroff(A_ALTCHARSET);
538 }
539 }
540 } else {
541 1 $this->{-canvasscr}->addstr($id, 0, $inscreen);
542 }
543
544 # Draw overflow characters.
545 1 ▶ if (not $this->{-wrapping} and $this->{-showoverflow})
Branch: 1 branch
BranchTrueFalseTotal
if (not $this->{"-wrapping"} and $this->{"-showoverflow"}) 1 0 1
Condition33%1/3
not $this->{"-wrapping"} and $this->{"-showoverflow"}
!ll&&!rl&&r
001
MC/DC0%0/2
not $this->{"-wrapping"} and $this->{"-showoverflow"}
not $this->{"-wrapping"} $this->{"-showoverflow"}
Truth table33%1/3
not(A) and B
A= not $this->{"-wrapping"}B= $this->{"-showoverflow"}
ABresult
0X0
100
111
546 {
547 1 ▶ $this->{-canvasscr}->addch($id, $this->canvaswidth-1, '$')
Branch: 1 branch
BranchTrueFalseTotal
if $this->canvaswidth < &scrlength($fromxscr) 1 0 1
548 if $this->canvaswidth < scrlength($fromxscr);
549 $this->{-canvasscr}->addch($id, 0, '$')
550 1 ▶ if $this->{-xscrpos} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-xscrpos"} > 0 0 1 1
551 }
552  
553 } else {
554 1 last;
555 }
556 }
557  
558 # Move the cursor.
559 # Take care of TAB's
560 1 ▶ if ($this->{-readonly})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-readonly'}) { } 0 1 1
561 {
562 $this->{-canvasscr}->move(
563 0 $this->canvasheight-1,
564 $this->canvaswidth-1
565 );
566 } else {
567 1 my $l = $this->{-scr_lines}->[$this->{-ypos}];
568 my $precursor = substr(
569 $l,
570 $this->{-xscrpos},
571 $this->{-xpos} - $this->{-xscrpos}
572 1 );
573  
574 1 my $realxpos = scrlength($precursor);
575 $this->{-canvasscr}->move(
576 $this->{-ypos} - $this->{-yscrpos},
577 1 $realxpos
578 );
579 }
580
581 1 ▶ $this->{-canvasscr}->attroff(A_UNDERLINE) if $this->{-showlines};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-showlines"} 0 1 1
582 1 ▶ $this->{-canvasscr}->attroff(A_REVERSE) if $this->{-reverse};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-reverse"} 0 1 1
583 1 $this->{-canvasscr}->noutrefresh();
584 1 ▶ doupdate() unless $no_doupdate;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_doupdate 0 1 1
585 1 return $this;
586 }
587  
588 sub draw(;$)
589 1 ▶{
Subroutine draw: called CC=4 SCAR=14.3
Pod documented
590 1 my $this = shift;
591 1 ▶ my $no_doupdate = shift || 0;
Condition50%1/2
shift() || 0
l!l
10
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
592  
593 1 ▶ $this->SUPER::draw(1) or return $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->SUPER::draw(1) or return $this 1 0 1
594  
595 1 $this->layout_content;
596 1 $this->draw_text(1);
597 1 ▶ doupdate() unless $no_doupdate;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_doupdate 0 1 1
598  
599 1 return $this;
600 }
601  
602 sub event_onblur()
603 0 ▶{
Subroutine event_onblur: not called CC=2 SCAR=17.9
Pod undocumented
604 0 my $this = shift;
605
606 0 $this->SUPER::event_onblur;
607  
608 # Set the cursor position to the startposition
609 # if -homeonblur is set.
610 0 ▶ if ($this->{-homeonblur}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-homeonblur"}) 0 0 0
611 0 $this->cursor_to_home;
612 0 $this->layout_content;
613 }
614  
615 0 return $this;
616 }
617  
618 sub event_keypress ($;)
619 0 ▶{
Subroutine event_keypress: not called CC=15 SCAR=54.8
Pod undocumented
620 0 my $this = shift;
621 0 my $key = shift;
622  
623 # Reset the field that tracks if undoinfo has already
624 # been saved or not.
625 0 $this->resetsetundo();
626  
627 # Pasting more than one char/line is possible. As long
628 # as you do it at once (no other actions in between are
629 # allowed).
630 0 ▶ if (defined $this->{-prevkey} and $this->{-prevkey} ne $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this->{'-prevkey'} and $this->{'-prevkey'} ne $key) { } 0 0 0
Condition0%0/3
defined $this->{"-prevkey"} and $this->{"-prevkey"} ne $key
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this->{"-prevkey"} and $this->{"-prevkey"} ne $key
defined $this->{"-prevkey"} $this->{"-prevkey"} ne $key
Truth table0%0/3
A and B
A= defined $this->{"-prevkey"}B= $this->{"-prevkey"} ne $key
ABresult
0X0
100
111
631 0 $this->do_new_pastebuffer(1);
632 } else {
633 0 $this->do_new_pastebuffer(0);
634 }
635  
636 # Backup, in case illegal input is done.
637 0 my %backup = %{$this};
638  
639 # Process bindings.
640 0 my $ret = $this->process_bindings($key);
641
642 # Did the widget loose focus, due to the keypress?
643 0 ▶ return $this unless $this->{-focus};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"-focus"} 0 0 0
644  
645 # To upper or to lower?
646 0 ▶ if ($this->{-toupper}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($this->{'-toupper'}) { } 0 0 0
elsif ($this->{'-tolower'}) { } 0 0 0
647 0 $this->{-text} = uc $this->{-text};
648 } elsif ($this->{-tolower}) {
649 0 $this->{-text} = lc $this->{-text};
650 }
651  
652 # Check for illegal input.
653 0 my $is_illegal = 0;
654 0 ▶ if ($this->{-maxlength}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-maxlength"}) 0 0 0
655 0 ▶ $is_illegal = 1 if length($this->{-text}) > $this->{-maxlength};
Branch: 1 branch
BranchTrueFalseTotal
if length $this->{"-text"} > $this->{"-maxlength"} 0 0 0
656 }
657 0 ▶ if (not $is_illegal and defined $this->{-maxlines}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_illegal and defined $this->{"-maxlines"}) 0 0 0
Condition0%0/3
not $is_illegal and defined $this->{"-maxlines"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $is_illegal and defined $this->{"-maxlines"}
not $is_illegal defined $this->{"-maxlines"}
Truth table0%0/3
not(A) and B
A= not $is_illegalB= defined $this->{"-maxlines"}
ABresult
0X0
100
111
658 0 my $lines = $this->split_to_lines($this->{-text});
659 0 ▶ $is_illegal = 1 if @$lines > $this->{-maxlines};
Branch: 1 branch
BranchTrueFalseTotal
if @$lines > $this->{"-maxlines"} 0 0 0
660 }
661 0 ▶ if (not $is_illegal and defined $this->{-regexp}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_illegal and defined $this->{"-regexp"}) 0 0 0
Condition0%0/3
not $is_illegal and defined $this->{"-regexp"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $is_illegal and defined $this->{"-regexp"}
not $is_illegal defined $this->{"-regexp"}
Truth table0%0/3
not(A) and B
A= not $is_illegalB= defined $this->{"-regexp"}
ABresult
0X0
100
111
662 0 my $e = '$is_illegal = (not $this->{-text} =~ ' . $this->{-regexp} . ')';
663 0 eval $e;
664 }
665
666 0 ▶ if ($is_illegal) # Illegal input? Then restore and bail out.
Branch: 1 branch
BranchTrueFalseTotal
if ($is_illegal) { } 0 0 0
667 {
668 0 ▶ while (my ($k,$v) = each %backup) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %backup) 0 0 0
669 0 $this->{$k} = $v;
670 }
671 0 $this->dobeep();
672 } else { # Legal input? Redraw the text.
673 0 $this->run_event('-onchange');
674 0 $this->draw(1);
675 }
676  
677 # Save the current key.
678 0 $this->{-prevkey} = $key;
679  
680 0 return $ret;
681 }
682  
683 sub add_string($;)
684 0 ▶{
Subroutine add_string: not called CC=6 SCAR=37.4
Pod undocumented
685 0 my $this = shift;
686 0 my $ch = shift;
687  
688 0 my @ch = split //, $ch;
689 0 $ch = '';
690 0 foreach (@ch) {
691 0 $ch .= $this->key_to_ascii($_);
692 }
693  
694 0 $this->set_undoinfo;
695  
696 0 PASTED: for (;;)
697 {
698 0 my $binding = $this->{-bindings}->{$ch};
699 0 ▶ $binding = 'add-string' unless defined $binding;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $binding 0 0 0
700  
701 0 ▶ if ($ch eq "-1") {
Branch: 3 branches
BranchTrueFalseTotal
if ($ch eq '-1') { } 0 0 0
elsif ($binding eq 'add-string') { } 0 0 0
elsif ($binding eq 'newline') { } 0 0 0
702 0 last PASTED;
703 } elsif ( $binding eq 'add-string' ) {
704 0 substr($this->{-text}, $this->{-pos}, 0) = $ch;
705 0 $this->{-pos} += length($ch);
706 } elsif ( $binding eq 'newline' ) {
707 0 $this->process_bindings($ch);
708 }
709  
710 # Multiple characters at input? This is probably a
711 # pasted string. Get it and process it. Don't do
712 # special bindings, but only add-string and newline.
713 0 $ch = $this->get_key(0);
714 }
715  
716 0 $this->layout_content;
717 0 $this->set_curxpos;
718 0 return $this;
719 }
720  
721 sub toggle_showoverflow()
722 0 ▶{
Subroutine toggle_showoverflow: not called CC=1 SCAR=6.9
Pod documented
723 0 my $this = shift;
724 0 $this->{-showoverflow} = ! $this->{-showoverflow};
725 0 return $this;
726 }
727  
728 sub toggle_wrapping()
729 0 ▶{
Subroutine toggle_wrapping: not called CC=2 SCAR=17.9
Pod documented
730 0 my $this = shift;
731 0 ▶ return $this->dobeep if $this->{-singleline};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-singleline"} 0 0 0
732 0 $this->{-wrapping} = ! $this->{-wrapping};
733 0 $this->layout;
734 0 return $this;
735 }
736  
737 sub toggle_showhardreturns()
738 0 ▶{
Subroutine toggle_showhardreturns: not called CC=2 SCAR=17.9
Pod documented
739 0 my $this = shift;
740 0 ▶ return $this->dobeep if $this->{-singleline};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-singleline"} 0 0 0
741 0 $this->{-showhardreturns} = ! $this->{-showhardreturns};
742 0 return $this;
743 }
744  
745 sub cursor_right()
746 0 ▶{
Subroutine cursor_right: not called CC=5 SCAR=34.0
Pod undocumented
747 0 my $this = shift;
748
749 # Handle cursor_right for read only mode.
750 0 ▶ if ($this->{-readonly})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-readonly"}) 0 0 0
751 {
752 return $this->dobeep
753 0 ▶ unless defined $this->{-hscrolllen};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{"-hscrolllen"} 0 0 0
754  
755 return $this->dobeep
756 if $this->{-xscrpos}
757 0 ▶ >= $this->{-hscrolllen} - $this->canvaswidth;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-xscrpos"} >= $this->{"-hscrolllen"} - $this->canvaswidth 0 0 0
758  
759 0 $this->{-xscrpos} += 1;
760 0 $this->{-hscrollpos} = $this->{-xscrpos};
761 0 $this->{-xpos} = $this->{-xscrpos};
762  
763 0 return $this;
764 }
765  
766 0 ▶ if ($this->{-pos} == length($this->{-text})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-pos'} == length $this->{'-text'}) { } 0 0 0
767 0 $this->dobeep;
768 } else {
769 0 $this->{-pos}++;
770 }
771 0 $this->layout_content;
772 0 $this->set_curxpos;
773 0 return $this;
774 }
775  
776 sub cursor_left()
777 0 ▶{
Subroutine cursor_left: not called CC=4 SCAR=30.0
Pod undocumented
778 0 my $this = shift;
779
780 # Handle cursor_left for read only mode.
781 0 ▶ if ($this->{-readonly})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-readonly"}) 0 0 0
782 {
783 0 ▶ return $this->dobeep if $this->{-xscrpos} <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-xscrpos"} <= 0 0 0 0
784 0 $this->{-xscrpos} -= 1;
785 0 $this->{-xpos} = $this->{-xscrpos};
786 0 return $this;
787 }
788  
789 0 ▶ if ($this->{-pos} <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-pos'} <= 0) { } 0 0 0
790 0 $this->dobeep;
791 } else {
792 0 $this->{-pos}--;
793 }
794 0 $this->layout_content;
795 0 $this->set_curxpos;
796 0 return $this;
797 }
798
799 sub set_curxpos()
800 0 ▶{
Subroutine set_curxpos: not called CC=1 SCAR=6.9
Pod undocumented
801 0 my $this = shift;
802 0 $this->{-curxpos} = $this->{-xpos};
803 0 return $this;
804 }
805
806 sub cursor_up(;$)
807 0 ▶{
Subroutine cursor_up: not called CC=9 SCAR=45.0
Pod undocumented
808 0 my $this = shift;
809 0 shift; # stub for bindings handling.
810 0 ▶ my $amount = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
811
812 0 ▶ return $this->dobeep if $this->{-singleline};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-singleline"} 0 0 0
813
814 # Handle cursor_up for read only mode.
815 0 ▶ if ($this->{-readonly})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-readonly"}) 0 0 0
816 {
817 0 ▶ return $this->dobeep if $this->{-yscrpos} <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-yscrpos"} <= 0 0 0 0
818 0 $this->{-yscrpos} -= $amount;
819 0 ▶ $this->{-yscrpos} = 0 if $this->{-yscrpos} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-yscrpos"} < 0 0 0 0
820 0 $this->{-ypos} = $this->{-yscrpos};
821 0 return $this;
822 }
823  
824 0 my $maymove = $this->{-ypos};
825 0 ▶ return $this->dobeep unless $maymove;
Branch: 1 branch
BranchTrueFalseTotal
unless $maymove 0 0 0
826 0 ▶ $amount = $maymove if $amount > $maymove;
Branch: 1 branch
BranchTrueFalseTotal
if $amount > $maymove 0 0 0
827  
828 0 my $l = $this->{-scr_lines};
829 0 $this->cursor_to_scrlinestart;
830 0 $this->{-ypos} -= $amount;
831 0 ▶ while ($amount)
Branch: 1 branch
BranchTrueFalseTotal
if ($amount) 0 0 0
832 {
833 0 my $idx = $this->{-ypos} + $amount - 1;
834 0 my $line = $l->[$idx];
835 0 my $line_length = length($line);
836 0 $this->{-pos} -= $line_length;
837 0 $amount--;
838 }
839 0 $this->cursor_to_curxpos;
840  
841 0 return $this;
842 }
843  
844 sub cursor_pageup()
845 0 ▶{
Subroutine cursor_pageup: not called CC=2 SCAR=17.9
Pod undocumented
846 0 my $this = shift;
847  
848 0 ▶ return $this->dobeep if $this->{-singleline};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-singleline"} 0 0 0
849 0 $this->cursor_up(undef, $this->canvasheight - 1);
850  
851 0 return $this;
852 }
853
854 sub cursor_down($;)
855 0 ▶{
Subroutine cursor_down: not called CC=9 SCAR=45.0
Pod undocumented
856 0 my $this = shift;
857 0 shift; # stub for bindings handling.
858 0 ▶ my $amount = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
859
860 0 ▶ return $this->dobeep if $this->{-singleline};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-singleline"} 0 0 0
861
862 # Handle cursor_down for read only mode.
863 0 ▶ if ($this->{-readonly})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-readonly"}) 0 0 0
864 {
865 0 my $max = @{$this->{-scr_lines}} - $this->canvasheight;
866 return $this->dobeep
867 0 ▶ if $this->{-yscrpos} >= $max;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-yscrpos"} >= $max 0 0 0
868  
869 0 $this->{-yscrpos} += $amount;
870 0 ▶ $this->{-yscrpos} = $max if $this->{-yscrpos} > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-yscrpos"} > $max 0 0 0
871 0 $this->{-ypos} = $this->{-yscrpos};
872 0 return $this;
873 }
874
875 0 my $l = $this->{-scr_lines};
876 0 my $maymove = (@$l-1) - $this->{-ypos};
877 0 ▶ return $this->dobeep unless $maymove;
Branch: 1 branch
BranchTrueFalseTotal
unless $maymove 0 0 0
878 0 ▶ $amount = $maymove if $amount > $maymove;
Branch: 1 branch
BranchTrueFalseTotal
if $amount > $maymove 0 0 0
879
880 0 $this->cursor_to_scrlinestart;
881 0 $this->{-ypos} += $amount;
882 0 ▶ while ($amount)
Branch: 1 branch
BranchTrueFalseTotal
if ($amount) 0 0 0
883 {
884 0 my $idx = $this->{-ypos} - $amount;
885 0 my $line = $l->[$idx];
886 0 my $line_length = length($line);
887 0 $this->{-pos} += $line_length;
888 0 $amount--;
889 }
890 0 $this->cursor_to_curxpos;
891  
892 0 return $this;
893 }
894  
895 sub cursor_pagedown()
896 0 ▶{
Subroutine cursor_pagedown: not called CC=2 SCAR=17.9
Pod undocumented
897 0 my $this = shift;
898 0 ▶ return $this->dobeep if $this->{-singleline};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-singleline"} 0 0 0
899
900 0 $this->cursor_down(undef, $this->canvasheight - 1);
901  
902 0 return $this;
903 }
904  
905 sub cursor_to_home()
906 0 ▶{
Subroutine cursor_to_home: not called CC=2 SCAR=17.9
Pod undocumented
907 0 my $this = shift;
908
909 0 ▶ if ($this->{-readonly})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-readonly"}) 0 0 0
910 {
911 0 $this->{-xscrpos} = $this->{-xpos} = 0;
912 0 $this->{-yscrpos} = $this->{-ypos} = 0;
913 0 return $this;
914 }
915
916 0 $this->{-pos} = 0;
917 0 $this->set_curxpos;
918 0 return $this;
919 }
920  
921 sub cursor_to_end()
922 0 ▶{
Subroutine cursor_to_end: not called CC=2 SCAR=17.9
Pod undocumented
923 0 my $this = shift;
924  
925 0 ▶ if ($this->{-readonly})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-readonly"}) 0 0 0
926 {
927 0 $this->{-xscrpos} = $this->{-xpos} = 0;
928 $this->{-yscrpos} = $this->{-ypos} =
929 0 $this->{-vscrolllen}-$this->canvasheight;
930 0 return $this;
931 }
932
933 0 $this->{-pos} = length($this->{-text});
934 0 $this->set_curxpos;
935 0 return $this;
936 }
937  
938 sub cursor_to_scrlinestart()
939 0 ▶{
Subroutine cursor_to_scrlinestart: not called CC=3 SCAR=24.8
Pod undocumented
940 0 my $this = shift;
941 # Key argument is set if called from binding.
942 0 my $from_binding = shift;
943
944 0 ▶ if ($this->{-readonly})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-readonly"}) 0 0 0
945 {
946 0 $this->{-xscrpos} = $this->{-xpos} = 0;
947 0 return $this;
948 }
949  
950 0 $this->{-pos} -= $this->{-xpos};
951 0 $this->{-xpos} = 0;
952 0 ▶ $this->set_curxpos if defined $from_binding;
Branch: 1 branch
BranchTrueFalseTotal
if defined $from_binding 0 0 0
953 0 return $this;
954 }
955
956 sub cursor_to_scrlineend()
957 0 ▶{
Subroutine cursor_to_scrlineend: not called CC=3 SCAR=24.8
Pod undocumented
958 0 my $this = shift;
959 0 my $from_binding = shift;
960
961 0 ▶ if ($this->{-readonly})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-readonly"}) 0 0 0
962 {
963 $this->{-xscrpos} = $this->{-xpos} =
964 0 $this->{-hscrolllen} - $this->canvaswidth ;
965 0 return $this;
966 }
967  
968 0 my $newpos = $this->{-pos};
969 0 my $l = $this->{-scr_lines};
970 0 my $len = length($l->[$this->{-ypos}]) - 1;
971 0 $newpos += $len - $this->{-xpos};
972 0 $this->{-pos} = $newpos;
973 0 $this->layout_content;
974 0 ▶ $this->set_curxpos if defined $from_binding;
Branch: 1 branch
BranchTrueFalseTotal
if defined $from_binding 0 0 0
975 0 return $this;
976 }
977  
978 sub cursor_to_linestart()
979 0 ▶{
Subroutine cursor_to_linestart: not called CC=5 SCAR=34.0
Pod undocumented
980 0 my $this = shift;
981  
982 # Move cursor back, until \n is found. That is
983 # the previous line. Then go one position to the
984 # right to find the start of the line.
985 0 my $newpos = $this->{-pos};
986 0 for(;;)
987 {
988 0 ▶ last if $newpos <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $newpos <= 0 0 0 0
989 0 $newpos--;
990 0 ▶ last if substr($this->{-text}, $newpos, 1) eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if substr($this->{"-text"}, $newpos, 1) eq "\n" 0 0 0
991 }
992 0 ▶ $newpos++ unless $newpos == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $newpos == 0 0 0 0
993 0 ▶ $newpos = length($this->{-text}) if $newpos > length($this->{-text});
Branch: 1 branch
BranchTrueFalseTotal
if $newpos > length $this->{"-text"} 0 0 0
994 0 $this->{-pos} = $newpos;
995 0 $this->layout_content;
996 0 return $this;
997 }
998  
999 sub cursor_to_curxpos()
1000 0 ▶{
Subroutine cursor_to_curxpos: not called CC=3 SCAR=24.8
Pod undocumented
1001 0 my $this = shift;
1002 0 my $right = $this->{-curxpos};
1003 0 ▶ $right = 0 unless defined $right;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $right 0 0 0
1004 0 my $len = length($this->{-scr_lines}->[$this->{-ypos}]) - 1;
1005 0 ▶ if ($right > $len) { $right = $len }
Branch: 1 branch
BranchTrueFalseTotal
if ($right > $len) 0 0 0
1006 0 $this->{-pos} += $right;
1007 0 $this->layout_content;
1008 0 return $this;
1009 }
1010  
1011 sub clear_line()
1012 0 ▶{
Subroutine clear_line: not called CC=1 SCAR=6.9
Pod undocumented
1013 0 my $this = shift;
1014 0 $this->cursor_to_linestart;
1015 0 $this->delete_till_eol;
1016 0 return $this;
1017 }
1018  
1019 sub delete_line()
1020 0 ▶{
Subroutine delete_line: not called CC=3 SCAR=24.8
Pod undocumented
1021 0 my $this = shift;
1022 0 ▶ return $this->dobeep if $this->{-singleline};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-singleline"} 0 0 0
1023  
1024 0 my $len = length($this->{-text});
1025 0 ▶ if ($len == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($len == 0) 0 0 0
1026 {
1027 0 $this->dobeep;
1028 0 return $this;
1029 }
1030  
1031 $this->beep_off
1032 ->cursor_to_linestart
1033 ->delete_till_eol
1034 ->cursor_left
1035 ->delete_character
1036 ->cursor_right
1037 ->cursor_to_linestart
1038 ->set_curxpos
1039 0 ->beep_on;
1040 0 return $this;
1041 }
1042  
1043 sub delete_till_eol()
1044 0 ▶{
Subroutine delete_till_eol: not called CC=4 SCAR=30.0
Pod undocumented
1045 0 my $this = shift;
1046
1047 0 $this->set_undoinfo;
1048
1049 # Cursor is at newline. No action needed.
1050 0 ▶ return $this if substr($this->{-text}, $this->{-pos}, 1) eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if substr($this->{"-text"}, $this->{"-pos"}, 1) eq "\n" 0 0 0
1051  
1052 # Find the next newline. Delete the content up to that newline.
1053 0 my $pos = $this->{-pos};
1054 0 for(;;)
1055 {
1056 0 $pos++;
1057 0 ▶ last if $pos >= length($this->{-text});
Branch: 1 branch
BranchTrueFalseTotal
if $pos >= length $this->{"-text"} 0 0 0
1058 0 ▶ last if substr($this->{-text}, $pos, 1) eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if substr($this->{"-text"}, $pos, 1) eq "\n" 0 0 0
1059 }
1060  
1061 $this->add_to_pastebuffer(
1062 substr($this->{-text}, $this->{-pos}, $pos - $this->{-pos})
1063 0 );
1064 0 substr($this->{-text}, $this->{-pos}, $pos - $this->{-pos}, '');
1065 0 return $this;
1066 }
1067
1068 sub delete_character()
1069 0 ▶{
Subroutine delete_character: not called CC=2 SCAR=17.9
Pod undocumented
1070 0 my $this = shift;
1071 0 shift(); # stub for bindings handling.
1072 0 my $is_backward = shift;
1073
1074 0 ▶ if ($this->{-pos} >= length($this->{-text})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-pos'} >= length $this->{'-text'}) { } 0 0 0
1075 0 $this->dobeep;
1076 } else {
1077 0 $this->set_undoinfo;
1078 $this->add_to_pastebuffer(
1079 0 substr($this->{-text}, $this->{-pos}, 1),
1080 $is_backward
1081 );
1082 0 substr($this->{-text}, $this->{-pos}, 1, ''),
1083 }
1084 0 return $this;
1085 }
1086  
1087 sub backspace()
1088 0 ▶{
Subroutine backspace: not called CC=2 SCAR=17.9
Pod undocumented
1089 0 my $this = shift;
1090
1091 0 ▶ if ($this->{-pos} <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-pos'} <= 0) { } 0 0 0
1092 0 $this->dobeep;
1093 } else {
1094 0 $this->set_undoinfo;
1095 0 $this->{-pos}--;
1096 0 $this->delete_character(undef,1);
1097 0 $this->layout_content;
1098 0 $this->set_curxpos;
1099 }
1100 0 return $this;
1101 }
1102  
1103 sub newline()
1104 0 ▶{
Subroutine newline: not called CC=2 SCAR=17.9
Pod undocumented
1105 0 my $this = shift;
1106 0 ▶ return $this->dobeep if $this->{-singleline};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-singleline"} 0 0 0
1107 0 $this->add_string("\n");
1108 }
1109  
1110 sub mouse_button1($$$$;)
1111 0 ▶{
Subroutine mouse_button1: not called CC=3 SCAR=24.8
Pod undocumented
1112 0 my $this = shift;
1113 0 my $event = shift;
1114 0 my $x = shift;
1115 0 my $y = shift;
1116  
1117 0 ▶ return unless $this->{-focusable};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"-focusable"} 0 0 0
1118  
1119 # TODO: make this possible for multi line widgets.
1120 0 ▶ if ($this->{-singleline})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-singleline"}) 0 0 0
1121 {
1122 0 $this->{-pos} = $this->{-xscrpos} + $x;
1123 0 $this->layout_content;
1124 0 $this->set_curxpos;
1125 }
1126 0 $this->focus();
1127  
1128 0 return $this;
1129 }
1130  
1131 0 ▶sub resetsetundo() { shift()->{-didsetundo} = 0}
Subroutine resetsetundo: not called CC=1 SCAR=6.9
Pod undocumented
1132 0 ▶sub didsetundo() { shift()->{-didsetundo} }
Subroutine didsetundo: not called CC=1 SCAR=6.9
Pod undocumented
1133  
1134 sub set_undoinfo()
1135 0 ▶{
Subroutine set_undoinfo: not called CC=4 SCAR=30.0
Pod undocumented
1136 0 my $this = shift;
1137  
1138 0 ▶ return $this if $this->didsetundo;
Branch: 1 branch
BranchTrueFalseTotal
if $this->didsetundo 0 0 0
1139  
1140 0 push @{$this->{-undotext}}, $this->{-text};
1141 0 push @{$this->{-undopos}}, $this->{-pos};
1142  
1143 0 my $l = $this->{-undolevels};
1144 0 ▶ if ($l and @{$this->{-undotext}} > $l) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l and @{$this->{"-undotext"};} > $l) 0 0 0
Condition0%0/3
$l and @{$this->{"-undotext"};} > $l
!ll&&!rl&&r
000
MC/DC0%0/2
$l and @{$this->{"-undotext"};} > $l
$l @{$this->{"-undotext"};} > $l
Truth table0%0/3
A and B
A= $lB= @{$this->{"-undotext"};} > $l
ABresult
0X0
100
111
1145 0 splice(@{$this->{-undotext}}, 0, @{$this->{-undotext}}-$l, ());
1146 0 splice(@{$this->{-undopos}}, 0, @{$this->{-undopos}}-$l, ());
1147 }
1148  
1149 0 $this->{-didsetundo} = 1;
1150 0 return $this;
1151 }
1152  
1153 sub undo()
1154 0 ▶{
Subroutine undo: not called CC=2 SCAR=17.9
Pod undocumented
1155 0 my $this = shift;
1156  
1157 0 ▶ if (@{$this->{-undotext}})
Branch: 1 branch
BranchTrueFalseTotal
if (@{$this->{"-undotext"};}) 0 0 0
1158 {
1159 0 my $text = pop @{$this->{-undotext}};
1160 0 my $pos = pop @{$this->{-undopos}};
1161 0 $this->{-text} = $text;
1162 0 $this->{-pos} = $pos;
1163 }
1164 0 return $this;
1165 }
1166  
1167 sub do_new_pastebuffer(;$)
1168 0 ▶{
Subroutine do_new_pastebuffer: not called CC=3 SCAR=24.8
Pod undocumented
1169 0 my $this = shift;
1170 0 my $value = shift;
1171 0 ▶ $this->{-do_new_pastebuffer} = $value
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 0 0
1172 if defined $value;
1173 0 ▶ $this->{-pastebuffer} = '' unless defined $this->{-pastebuffer};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{"-pastebuffer"} 0 0 0
1174 0 return $this->{-do_new_pastebuffer};
1175 }
1176  
1177 sub clear_pastebuffer()
1178 0 ▶{
Subroutine clear_pastebuffer: not called CC=1 SCAR=6.9
Pod undocumented
1179 0 my $this = shift;
1180 0 $this->{-pastebuffer} = '';
1181 0 return $this;
1182 }
1183  
1184 sub add_to_pastebuffer($;)
1185 0 ▶{
Subroutine add_to_pastebuffer: not called CC=4 SCAR=30.0
Pod undocumented
1186 0 my $this = shift;
1187 0 my $add = shift;
1188 0 ▶ my $is_backward = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1189  
1190 0 ▶ $this->clear_pastebuffer if $this->do_new_pastebuffer;
Branch: 1 branch
BranchTrueFalseTotal
if $this->do_new_pastebuffer 0 0 0
1191 0 ▶ if ($is_backward) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_backward) { } 0 0 0
1192 0 $this->{-pastebuffer} = $add . $this->{-pastebuffer};
1193 } else {
1194 0 $this->{-pastebuffer} .= $add;
1195 }
1196 0 $this->do_new_pastebuffer(0);
1197 0 return $this;
1198 }
1199  
1200 sub paste()
1201 0 ▶{
Subroutine paste: not called CC=2 SCAR=17.9
Pod undocumented
1202 0 my $this = shift;
1203
1204 0 ▶ if ($this->{-pastebuffer} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-pastebuffer"} ne "") 0 0 0
1205 0 $this->add_string($this->{-pastebuffer});
1206 }
1207 0 return $this;
1208 }
1209  
1210 sub readonly($;)
1211 1 ▶{
Subroutine readonly: called CC=2 SCAR=7.5
Pod undocumented
1212 1 my $this = shift;
1213 1 my $readonly = shift;
1214  
1215 1 $this->{-readonly} = $readonly;
1216
1217 1 ▶ if ($readonly)
Branch: 1 branch
BranchTrueFalseTotal
if ($readonly) { } 0 1 1
1218 {
1219 0 my %mybindings = (
1220 %basebindings,
1221 %viewbindings
1222 );
1223 0 $this->{-bindings} = \%mybindings;
1224 0 $this->{-nocursor} = 1;
1225 } else {
1226 1 my %mybindings = (
1227 %basebindings,
1228 %editbindings
1229 );
1230 1 $this->{-bindings} = \%mybindings;
1231 1 $this->{-nocursor} = 0;
1232 }
1233  
1234 1 return $this;
1235 }
1236  
1237 1 ▶sub get() {shift()->text}
Subroutine get: called CC=1 SCAR=0.0
Pod documented
1238  
1239 sub pos(;$)
1240 0 ▶{
Subroutine pos: not called CC=2 SCAR=17.9
Pod undocumented
1241 0 my $this = shift;
1242 0 my $pos = shift;
1243 0 ▶ if (defined $pos)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) 0 0 0
1244 {
1245 0 $this->{-pos} = $pos;
1246 0 $this->layout_content;
1247 0 $this->intellidraw;
1248 0 return $this;
1249 }
1250 0 return $this->{-pos};
1251 }
1252  
1253 sub text(;$)
1254 2 ▶{
Subroutine text: called CC=2 SCAR=6.9
Pod documented
1255 2 my $this = shift;
1256 2 my $text = shift;
1257 2 ▶ if (defined $text)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text) 1 1 2
1258 {
1259 1 $this->{-text} = $text;
1260 1 $this->layout_content;
1261 1 $this->intellidraw;
1262 1 return $this;
1263 }
1264 1 return $this->{-text};
1265 }
1266  
1267 0 ▶sub onChange(;$) { shift()->set_event('-onchange', shift()) }
Subroutine onChange: not called CC=1 SCAR=6.9
Pod documented
1268  
1269 0 ▶sub set_password_char {
Subroutine set_password_char: not called CC=2 SCAR=17.9
Pod documented
1270 0 my ($this, $char) = @_;
1271 0 ▶ $char = substr($char, 0, 1) if defined $char;
Branch: 1 branch
BranchTrueFalseTotal
if defined $char 0 0 0
1272 0 $this->{-password} = $char;
1273 }
1274  
1275 # ----------------------------------------------------------------------
1276 # Routines for search support
1277 # ----------------------------------------------------------------------
1278  
1279 1 ▶sub number_of_lines() { @{shift()->{-scr_lines}} }
Subroutine number_of_lines: called CC=1 SCAR=0.0
Pod documented
1280 sub number_of_columns()
1281 1 ▶{
Subroutine number_of_columns: called CC=3 SCAR=12.5
Pod undocumented
1282 1 my $this = shift;
1283 1 my $columns = 0;
1284 1 foreach (@{$this->{-scr_lines}}) {
1285 0 ▶ $columns = length($_)
Branch: 1 branch
BranchTrueFalseTotal
if length $_ > $columns 0 0 0
1286 if length($_) > $columns;
1287 }
1288 1 return $columns;
1289 }
1290 0 ▶sub getline_at_ypos($;) { shift()->{-scr_lines}->[shift()] }
Subroutine getline_at_ypos: not called CC=1 SCAR=6.9
Pod documented
1291  
1292 #
1293 # Color
1294 #
1295  
1296 0 ▶sub set_color_fg {
Subroutine set_color_fg: not called CC=1 SCAR=6.9
Pod undocumented
1297 0 my $this = shift;
1298 0 $this->{-fg} = shift;
1299 0 $this->intellidraw;
1300 }
1301  
1302 0 ▶sub set_color_bg {
Subroutine set_color_bg: not called CC=1 SCAR=6.9
Pod undocumented
1303 0 my $this = shift;
1304 0 $this->{-bg} = shift;
1305 0 $this->intellidraw;
1306 }
1307  
1308  
1309 2 1;
1310  
1311 =pod
1312  
1313 =head1 NAME
1314  
1315 Curses::UI::TextEditor - Create and manipulate texteditor widgets
1316  
1317 =head1 CLASS HIERARCHY
1318  
1319 Curses::UI::Widget
1320 Curses::UI::Searchable
1321 |
1322 +----Curses::UI::TextEditor
1323  
1324  
1325 =head1 SYNOPSIS
1326  
1327 use Curses::UI;
1328 my $cui = new Curses::UI;
1329 my $win = $cui->add('window_id', 'Window');
1330  
1331 my $editor = $win->add(
1332 'myeditor', 'TextEditor',
1333 -vscrollbar => 1,
1334 -wrapping => 1,
1335 );
1336  
1337 $editor->focus();
1338 my $text = $editor->get();
1339  
1340  
1341 =head1 DESCRIPTION
1342  
1343 Curses::UI::TextEditor is a widget that can be used to create
1344 a couple of different kinds of texteditors. These are:
1345  
1346 =over 4
1347  
1348 =item * B<multi-line texteditor>
1349  
1350 This is a multi-line text editor with features like word-wrapping,
1351 maximum textlength and undo.
1352  
1353 =item * B<single-line texteditor>
1354  
1355 The texteditor can be created as a single-line editor.
1356 Most of the features of the default texteditor will remain.
1357 Only the multi-line specific options will not be
1358 available (like moving up and down in the text).
1359  
1360 =item * B<read only texteditor>
1361  
1362 The texteditor can also be used in read only mode.
1363 In this mode, the texteditor will function as a text
1364 viewer. The user can walk through the text and
1365 search trough it.
1366  
1367 =back
1368  
1369 See exampes/demo-Curses::UI::TextEditor in the distribution
1370 for a short demo of these.
1371  
1372  
1373  
1374 =head1 STANDARD OPTIONS
1375  
1376 B<-parent>, B<-x>, B<-y>, B<-width>, B<-height>,
1377 B<-pad>, B<-padleft>, B<-padright>, B<-padtop>, B<-padbottom>,
1378 B<-ipad>, B<-ipadleft>, B<-ipadright>, B<-ipadtop>, B<-ipadbottom>,
1379 B<-title>, B<-titlefullwidth>, B<-titlereverse>, B<-onfocus>,
1380 B<-onblur>
1381  
1382 For an explanation of these standard options, see
1383 L<Curses::UI::Widget|Curses::UI::Widget>.
1384  
1385  
1386  
1387  
1388 =head1 WIDGET-SPECIFIC OPTIONS
1389  
1390 =over 4
1391  
1392 =item * B<-text> < TEXT >
1393  
1394 This sets the initial text for the widget to TEXT.
1395  
1396 =item * B<-pos> < CURSOR_POSITION >
1397  
1398 This sets the initial cursor position for the widget
1399 to CURSOR_POSITION. B<-pos> represents the character index within
1400 B<-text>. By default this option is set to 0.
1401  
1402 =item * B<-readonly> < BOOLEAN >
1403  
1404 The texteditor widget will be created as a read only
1405 texteditor (which is also called a textviewer) if
1406 BOOLEAN is true. By default BOOLEAN is false.
1407  
1408 =item * B<-singleline> < BOOLEAN >
1409  
1410 The texteditor widget will be created as a single line
1411 texteditor (which is also called a textentry) if
1412 BOOLEAN is true. By default BOOLEAN is false.
1413  
1414 =item * B<-wrapping> < BOOLEAN >
1415  
1416 If BOOLEAN is true, the texteditor will have text wrapping
1417 enabled. By default BOOLEAN is false.
1418  
1419 =item * B<-showlines> < BOOLEAN >
1420  
1421 If BOOLEAN is set to a true value, each editable line
1422 in the editor will show a line to type on. By default
1423 BOOLEAN is set to false.
1424  
1425 =item * B<-maxlength> < VALUE >
1426  
1427 This sets the maximum allowed length of the text to
1428 VALUE. By default VALUE is set to 0,
1429 which means that the text may be infinitely long.
1430  
1431 =item * B<-maxlines> < VALUE >
1432  
1433 This sets the maximum allowed number of lines for the text
1434 to SCALAR. By default VALUE is set to 0, which means that
1435 the text may contain an infinite number of lines.
1436  
1437 =item * B<-password> < CHARACTER >
1438  
1439 Instead of showing the real text in the widget, every
1440 character of the text will (on the screen) be replaced
1441 by CHARACTER. So creating a standard password field
1442 can be done by setting:
1443  
1444 -password => '*'
1445  
1446 =item * B<-regexp> < REGEXP >
1447  
1448 If characters are added to the texteditor, the new text
1449 will be matched against REGEXP. If the text does not match,
1450 the change will be denied. This can for example be used to
1451 force digit-only input on the texteditor:
1452  
1453 -regexp => '/^\d*$/'
1454  
1455 =item * B<-undolevels> < VALUE >
1456  
1457 This option determines how many undolevels should be kept
1458 in memory for the texteditor widget. By default 10 levels
1459 are kept. If this value is set to 0, the number of levels
1460 is infinite.
1461  
1462 =item * B<-showoverflow> < BOOLEAN >
1463  
1464 If BOOLEAN is true, the text in the texteditor will be
1465 padded by an overflow character ($) if there is text
1466 outside the screen (like 'pico' does). By default
1467 BOOLEAN is true.
1468  
1469 =item * B<-showhardreturns> < BOOLEAN >
1470  
1471 If BOOLEAN is true, hard returns will be made visible
1472 by a diamond character. By default BOOLEAN is false.
1473  
1474 =item * B<-homeonblur> < BOOLEAN >
1475  
1476 If BOOLEAN is set to a true value, the cursor will move
1477 to the start of the text if the widget loses focus.
1478  
1479 =item * B<-toupper> < BOOLEAN >
1480  
1481 If BOOLEAN is true, all entered text will be converted
1482 to uppercase. By default BOOLEAN is false.
1483  
1484 =item * B<-tolower> < BOOLEAN >
1485  
1486 If BOOLEAN is true, all entered text will be converted
1487 to lowercase. By default BOOLEAN is false.
1488  
1489 =item * B<-onchange> < CODEREF >
1490  
1491 This sets the onChange event handler for the texteditor widget.
1492 If the text is changed by typing, the code in CODEREF will
1493 be executed. It will get the widget reference as its argument.
1494  
1495 =item * B<-reverse> < BOOLEAN >
1496  
1497 Makes the text drawn in reverse font.
1498  
1499 =back
1500  
1501  
1502  
1503  
1504 =head1 METHODS
1505  
1506 =over 4
1507  
1508 =item * B<new> ( OPTIONS )
1509  
1510 =item * B<layout> ( )
1511  
1512 =item * B<draw> ( BOOLEAN )
1513  
1514 =item * B<focus> ( )
1515  
1516 =item * B<onFocus> ( CODEREF )
1517  
1518 =item * B<onBlur> ( CODEREF )
1519  
1520 These are standard methods. See L<Curses::UI::Widget|Curses::UI::Widget>
1521 for an explanation of these.
1522  
1523 =item * B<text> ( [TEXT] )
1524  
1525 If TEXT is defined, this will set the text of the widget to TEXT.
1526 To see the change, the widget needs to be redrawn by the B<draw> method.
1527 If TEXT is not defined, this method will return the current contents
1528 of the texteditor.
1529  
1530 =item * B<get> ( )
1531  
1532 This method will call B<text> without any arguments, so it
1533 will return the contents of the texteditor.
1534  
1535 =item * B<onChange> ( CODEREF )
1536  
1537 This method can be used to set the B<-onchange> event handler
1538 (see above) after initialization of the texteditor.
1539  
1540 =item * B<set_password_char> ( $char )
1541  
1542 This method can be used to change the password property. The password
1543 character will be set to $char, or turned off in $char is undef.
1544  
1545 =item * B<toggle_showhardreturns>
1546  
1547 Toggles the -showhardreturns option.
1548  
1549 =item * B<toggle_showoverflow>
1550  
1551 Toggles the -showoverflow option.
1552  
1553 =item * B<toggle_wrapping>
1554  
1555 Toggles the -wrapping option.
1556  
1557 =back
1558  
1559  
1560  
1561  
1562  
1563 =head1 DEFAULT BINDINGS
1564  
1565 There are different sets of bindings for each mode in which
1566 this widget can be used.
1567  
1568  
1569  
1570 =head2 All modes (editor, single line and read only)
1571  
1572  
1573  
1574 =over 4
1575  
1576 =item * <B<tab>>
1577  
1578 Call the 'returreturnn' routine. This will have the widget
1579 loose its focus.
1580  
1581 =item * <B<cursor-left>>, <B<CTRL+B>>
1582  
1583 Call the 'cursor-left' routine: move the
1584 cursor one position to the left.
1585  
1586 =item * <B<cursor-right>>, <B<CTRL+F>>
1587  
1588 Call the 'cursor-right' routine: move the
1589 cursor one position to the right.
1590  
1591 =item * <B<cursor-down>>, <B<CTRL+N>>
1592  
1593 Call the 'cursor-down' routine: move the
1594 cursor one line down.
1595  
1596 =item * <B<cursor-up>>, <B<CTRL+P>>
1597  
1598 Call the 'cursor-up' routine: move the
1599 cursor one line up.
1600  
1601 =item * <B<page-up>>
1602  
1603 Call the 'cursor-pageup' routine: move the
1604 cursor to the previous page.
1605  
1606 =item * <B<page-down>>
1607  
1608 Call the 'cursor-pagedown' routine: move
1609 the cursor to the next page.
1610  
1611 =item * <B<home>>
1612  
1613 Call the 'cursor-home' routine: go to the
1614 start of the text.
1615  
1616 =item * <B<end>>
1617  
1618 Call the 'cursor-end' routine: go to the
1619 end of the text.
1620  
1621 =item * <B<CTRL+A>>
1622  
1623 Call the 'cursor-scrlinestart' routine: move the
1624 cursor to the start of the current line.
1625  
1626 =item * <B<CTRL+E>>
1627  
1628 Call the 'cursor-scrlineend' routine: move the
1629 cursor to the end of the current line.
1630  
1631 =item * <B<CTRL+W>>
1632  
1633 Call the 'toggle-wrapping' routine: toggle the
1634 -wrapping option of the texteditor.
1635  
1636 =item * <B<CTRL+R>>
1637  
1638 Call the 'toggle-showhardreturns' routine: toggle the
1639 -showhardreturns option of the texteditor.
1640  
1641 =item * <B<CTRL+T>>
1642  
1643 Call the 'toggle-showoverflow' routine: toggle the
1644 -showoverflow option of the texteditor.
1645  
1646 =back
1647  
1648  
1649  
1650 =head2 All edit modes (all but read only mode)
1651  
1652  
1653  
1654 =over 4
1655  
1656 =item * <B<CTRL+Y>>, <B<CTRL+X>>
1657  
1658 Call the 'delete-line' routine: Delete the current
1659 line.
1660  
1661 =item * <B<CTRL+K>>
1662  
1663 Call the 'delete-till-eol' routine: delete the text
1664 from the current cursor position up to the end of
1665 the current line.
1666  
1667 =item * <B<CTRL+U>>
1668  
1669 Call the 'clear-line' routine: clear the
1670 current line and move the cursor to the
1671 start of this line.
1672  
1673 =item * <B<CTRL+D>>
1674  
1675 Call the 'delete-character' routine: delete the
1676 character that currently is under the cursor.
1677  
1678 =item * <B<backspace>>
1679  
1680 Call the 'backspace' routine: delete the character
1681 this is before the current cursor position.
1682  
1683 =item * <B<CTRL+Z>>
1684  
1685 Call the 'undo' routine: undo the last change to
1686 the text, up to B<-undolevels> levels.
1687  
1688 =item * <B<CTRL+V>>
1689  
1690 Call the 'paste' routine: this will paste the
1691 last deleted text at the current cursor position.
1692  
1693 =item * <B<any other key>>
1694  
1695 Call the 'add-string' routine: the character
1696 will be inserted in the text at the current
1697 cursor position.
1698  
1699 =back
1700  
1701  
1702  
1703 =head2 Only for the read only mode
1704  
1705  
1706  
1707 =over 4
1708  
1709 =item * <B<h>>
1710  
1711 Call the 'cursor-left' routine: move the
1712 cursor one position to the left.
1713  
1714 =item * <B<l>>
1715  
1716 Call the 'cursor-right' routine: move the
1717 cursor one position to the right.
1718  
1719 =item * b<<k>>
1720  
1721 Call the 'cursor-up' routine: move the
1722 cursor one line up.
1723  
1724 =item * b<<j>>
1725  
1726 Call the 'cursor-down' routine: move the
1727 cursor one line down.
1728  
1729 =item * <B<space>>, <B<]>>
1730  
1731 Call the 'cursor-pagedown' routine: move
1732 the cursor to the next page.
1733  
1734 =item * <B<->>, <B<[>>
1735  
1736 Call the 'cursor-pageup' routine: move the
1737 cursor to the previous page.
1738  
1739 =item * <B</>>
1740  
1741 Call the 'search-forward' routine. This will make a 'less'-like
1742 search system appear in the textviewer. A searchstring can be
1743 entered. After that the user can search for the next occurance
1744 using the 'n' key or the previous occurance using the 'N' key.
1745  
1746 =item * <B<?>>
1747  
1748 Call the 'search-backward' routine. This will do the same as
1749 the 'search-forward' routine, only it will search in the
1750 opposite direction.
1751  
1752 =back
1753  
1754  
1755  
1756  
1757 =head1 SEE ALSO
1758  
1759 L<Curses::UI>,
1760 L<Curses::UI::TextViewer>
1761 L<Curses::UI::TextEntry>
1762 L<Curses::UI::Widget>,
1763 L<Curses::UI::Common>
1764  
1765  
1766  
1767  
1768 =head1 AUTHOR
1769  
1770 Copyright (c) 2001-2002 Maurice Makaay. All rights reserved.
1771  
1772 Maintained by Marcus Thiesen (marcus@cpan.thiesenweb.de)
1773  
1774  
1775 This package is free software and is provided "as is" without express
1776 or implied warranty. It may be used, redistributed and/or modified
1777 under the same terms as perl itself.
1778  
« blib/lib/Curses/UI/Calendar.pm ↑ Summary blib/lib/Curses/UI/Dialog/Question.pm »