| 1 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Curses::UI::Common | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # (c) 2001-2002 by Maurice Makaay. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # (c) 2003-2005 by Marcus Thiesen et al. | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # This file is part of Curses::UI. Curses::UI is free software. | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # You can redistribute it and/or modify it under the same terms | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # as perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # Currently maintained by Marcus Thiesen | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # e-mail: marcus@cpan.thiesenweb.de | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | # TODO: fix dox | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | package Curses::UI::Common; | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | ▶ | use Term::ReadKey; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 11 | ▶ | use Curses; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | require Exporter; | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 8 | ▶ | use vars qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | @ISA | ||||||||||||||||||||||||||||||||||||||||||
| 25 | @EXPORT_OK | ||||||||||||||||||||||||||||||||||||||||||
| 26 | @EXPORT | ||||||||||||||||||||||||||||||||||||||||||
| 27 | $VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 8 | ); | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | $VERSION = '1.10'; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | @ISA = qw( | ||||||||||||||||||||||||||||||||||||||||||
| 33 | Exporter | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | @EXPORT = qw( | ||||||||||||||||||||||||||||||||||||||||||
| 37 | keys_to_lowercase | ||||||||||||||||||||||||||||||||||||||||||
| 38 | text_wrap | ||||||||||||||||||||||||||||||||||||||||||
| 39 | text_draw | ||||||||||||||||||||||||||||||||||||||||||
| 40 | text_length | ||||||||||||||||||||||||||||||||||||||||||
| 41 | text_chop | ||||||||||||||||||||||||||||||||||||||||||
| 42 | scrlength | ||||||||||||||||||||||||||||||||||||||||||
| 43 | split_to_lines | ||||||||||||||||||||||||||||||||||||||||||
| 44 | text_dimension | ||||||||||||||||||||||||||||||||||||||||||
| 45 | CUI_ESCAPE CUI_SPACE CUI_TAB | ||||||||||||||||||||||||||||||||||||||||||
| 46 | WORDWRAP NO_WORDWRAP | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 50 | # Misc. routines | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | sub parent() | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 7 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 7 | $this->{-parent}; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | sub root() | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 27 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
root: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 27 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 27 | my $root = $this; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 27 | ▶ | while (defined $root->{-parent}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 30 | $root = $root->{-parent}; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 27 | return $root; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | sub accessor($;$) | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 25 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
accessor: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 25 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 25 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 25 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 25 | ▶ | $this->{$key} = $value if defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 25 | return $this->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | sub keys_to_lowercase($;) | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 70 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys_to_lowercase: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 70 | my $hash = shift; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 70 | my $copy = {%$hash}; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 70 | ▶ | while (my ($k,$v) = each %$copy) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 708 | $hash->{lc $k} = $v; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 70 | return $hash; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # Text processing | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | sub split_to_lines($;) | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split_to_lines: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | # Make $this->split_to_lines() possible. | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 5 | ▶ | shift if ref $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 5 | my $text = shift; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | # Break up the text in lines. IHATEBUGS is | ||||||||||||||||||||||||||||||||||||||||||
| 102 | # because a split with /\n/ on "\n\n\n" would | ||||||||||||||||||||||||||||||||||||||||||
| 103 | # return zero result :-( | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 5 | my @lines = split /\n/, $text . "IHATEBUGS"; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 5 | $lines[-1] =~ s/IHATEBUGS$//g; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 5 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | sub scrlength($;) | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scrlength: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | # Make $this->scrlength() possible. | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 4 | ▶ | shift if ref $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | my $line = shift; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | ▶ | return 0 unless defined $line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | my $scrlength = 0; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | ▶ | for (my $i=0; $i < length($line); $i++) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 460 | my $chr = substr($line, $i, 1); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 460 | $scrlength++; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 460 | ▶ | if ($chr eq "\t") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | while ($scrlength%8) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 4 | $scrlength++; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | return $scrlength; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | # Contstants for text_wrap() | ||||||||||||||||||||||||||||||||||||||||||
| 133 | sub NO_WORDWRAP() { 1 } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | sub WORDWRAP() { 0 } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | sub text_wrap($$;) | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text_wrap: called CC=19 SCAR=46.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | # Make $this->text_wrap() possible. | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | ▶ | shift if ref $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | my ($line, $maxlen, $wordwrap) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | ▶ | $wordwrap = WORDWRAP unless defined $wordwrap; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | $maxlen = int $maxlen; | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | ▶ | return [""] if $line eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | my @wrapped = (); | |||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | my $len = 0; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | my $wrap = ''; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | # Special wrapping is needed if the line contains tab | ||||||||||||||||||||||||||||||||||||||||||
| 151 | # characters. These should be expanded to the TAB-stops. | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | ▶ | if ($line =~ /\t/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | CHAR: for (my $i = 0; $i <= length($line); $i++) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | { | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $nextchar = substr($line, $i, 1); | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | # Find the length of the string in case the | ||||||||||||||||||||||||||||||||||||||||||
| 159 | # next character is added. | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $newlen = $len + 1; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if ($nextchar eq "\t") { while($newlen%8) { $newlen++ } } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | # Would that go beyond the end of the available width? | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if ($newlen > $maxlen) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if ($wordwrap == WORDWRAP | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$wordwrap == 0 and $wrap =~ /^(.*)([\s])(\S+)$/
MC/DC0%0/2
$wordwrap == 0 and $wrap =~ /^(.*)([\s])(\S+)$/
$wordwrap == 0
$wrap =~ /^(.*)([\s])(\S+)$/
Truth table0%0/3
A and B
A= $wordwrap == 0B= $wrap =~ /^(.*)([\s])(\S+)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | and $wrap =~ /^(.*)([\s])(\S+)$/) | ||||||||||||||||||||||||||||||||||||||||||
| 168 | { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | push @wrapped, $1 . $2; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $wrap = $3; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $len = scrlength($wrap) + 1; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $len = 1; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | push @wrapped, $wrap; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $wrap = ''; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $len = $newlen; | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $wrap .= $nextchar; | |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | push @wrapped, $wrap if defined $wrap; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | # No tab characters in the line? Then life gets a bit easier. We can | ||||||||||||||||||||||||||||||||||||||||||
| 185 | # process large chunks at once. | ||||||||||||||||||||||||||||||||||||||||||
| 186 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | my $idx = 0; | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | # Line shorter than allowed? Then return immediately. | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | ▶ | return [$line] if length($line) < $maxlen; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | ▶ | return ["internal wrap error: wraplength undefined"] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | unless defined $maxlen; | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | ▶ | CHUNK: while ($idx < length($line)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | { | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 6 | my $next = substr($line, $idx, $maxlen); | |||||||||||||||||||||||||||||||||||||||||
| 197 | 6 | ▶ | if (length($next) < $maxlen) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | { | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | push @wrapped, $next; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | last CHUNK; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | elsif ($wordwrap == WORDWRAP) | ||||||||||||||||||||||||||||||||||||||||||
| 203 | { | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $space_idx = rindex($next, " "); | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | if ($space_idx == -1 or $space_idx == 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$space_idx == -1 or $space_idx == 0
MC/DC0%0/2
$space_idx == -1 or $space_idx == 0
$space_idx == -1
$space_idx == 0
Truth table0%0/3
A or B
A= $space_idx == -1B= $space_idx == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | { | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | push @wrapped, $next; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $idx += $maxlen; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | push @wrapped, substr($next, 0, $space_idx + 1); | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $idx += $space_idx + 1; | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 5 | push @wrapped, $next; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 5 | $idx += $maxlen; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | return \@wrapped; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | sub text_tokenize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text_tokenize: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my @tokens = (); | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | while ($text ne '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | if ($text =~ m/^<\/?[a-zA-Z0-9_]+>/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | push(@tokens, $&); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $text = $'; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | elsif ($text =~ m/^.+?(?=<\/?[a-zA-Z0-9_]+>)/s) { | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | push(@tokens, $&); | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $text = $'; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | push(@tokens, $text); | |||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | return @tokens; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | sub text_draw($$;) | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text_draw: not called CC=19 SCAR=58.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my ($y, $x, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if ($this->{-htmltext}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my @tokens = &text_tokenize($text); | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | foreach my $token (@tokens) { | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if ($token =~ m/^<(standout|reverse|bold|underline|blink|dim)>$/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my $type = $1; | |||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if ($type eq 'standout') { $this->{-canvasscr}->attron(A_STANDOUT); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | elsif ($type eq 'reverse') { $this->{-canvasscr}->attron(A_REVERSE); } | |||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | elsif ($type eq 'bold') { $this->{-canvasscr}->attron(A_BOLD); } | |||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | elsif ($type eq 'underline') { $this->{-canvasscr}->attron(A_UNDERLINE); } | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | elsif ($type eq 'blink') { $this->{-canvasscr}->attron(A_BLINK); } | |||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | elsif ($type eq 'dim') { $this->{-canvasscr}->attron(A_DIM); } | |||||||||||||||||||||||||||||||||||||||||
| 260 | } elsif ($token =~ m/^<\/(standout|reverse|bold|underline|blink|dim)>$/s) { | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my $type = $1; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if ($type eq 'standout') { $this->{-canvasscr}->attroff(A_STANDOUT); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | elsif ($type eq 'reverse') { $this->{-canvasscr}->attroff(A_REVERSE); } | |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | elsif ($type eq 'bold') { $this->{-canvasscr}->attroff(A_BOLD); } | |||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | elsif ($type eq 'underline') { $this->{-canvasscr}->attroff(A_UNDERLINE); } | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | elsif ($type eq 'blink') { $this->{-canvasscr}->attroff(A_BLINK); } | |||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | elsif ($type eq 'dim') { $this->{-canvasscr}->attroff(A_DIM); } | |||||||||||||||||||||||||||||||||||||||||
| 268 | # Tags: (see, man 5 terminfo) | ||||||||||||||||||||||||||||||||||||||||||
| 269 | # | <4_ACS_VLINE> -- Vertical line (4 items). | ||||||||||||||||||||||||||||||||||||||||||
| 270 | # -- <5_ACS_HLINE> -- Horizontal line (5 items). | ||||||||||||||||||||||||||||||||||||||||||
| 271 | # ` <12_ACS_TTEE> -- Tee pointing down (12 items). | ||||||||||||||||||||||||||||||||||||||||||
| 272 | # ~ <ACS_BTEE> -- Tee pointing up (1 item). | ||||||||||||||||||||||||||||||||||||||||||
| 273 | # + <ACS_PLUS> -- Large plus or crossover (1 item). | ||||||||||||||||||||||||||||||||||||||||||
| 274 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 275 | } elsif ($token =~ m/^<(\d*)_?(ACS_HLINE|ACS_VLINE|ACS_TTEE|ACS_BTEE|ACS_PLUS)>$/s) { | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 8 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | my $scrlen = ($1 || 1); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$1 || 1
MC/DC0%0/1
$1 || 1
$1
Truth table0%0/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | my $type = &{ $2 }; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $this->{-canvasscr}->hline( $y, $x, $type, $scrlen ); | |||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $x += $scrlen; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $this->{-canvasscr}->addstr($y, $x, $token); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | $x += length($token); | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $this->{-canvasscr}->addstr($y, $x, $text); | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | sub text_length { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text_length: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my $length = 0; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if ($this->{-htmltext}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my @tokens = &text_tokenize($text); | |||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | foreach my $token (@tokens) { | |||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if ($token !~ m/^<\/?(reverse|bold|underline|blink|dim)>$/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $length += length($token); | |||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $length = length($text); | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | return $length; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | sub text_chop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text_chop: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my ($text, $max_length) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | if ($this->{-htmltext}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my @open = (); | |||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my @tokens = &text_tokenize($text); | |||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $length = 0; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $text = ''; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | foreach my $token (@tokens) { | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | if ($token =~ m/^<(\/?)(reverse|bold|underline|blink|dim)>/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my ($type, $name) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | if (defined($type) and $type eq '/') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $type and $type eq "/"
MC/DC0%0/2
defined $type and $type eq "/"
defined $type
$type eq "/"
Truth table0%0/3
A and B
A= defined $typeB= $type eq "/"
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | pop(@open); | |||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | push(@open, $name); | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $text .= $token; | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $text .= $token; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | $length += length($token); | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | if ($length > $max_length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $text = substr($text, 0, $max_length); | |||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $text =~ s/.$/\$/; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | while (defined($token = pop(@open))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $text .= "</$token>"; | |||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | if (length($text) > $max_length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | $text = substr($text, 0, $max_length); | |||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | sub text_dimension ($;) | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text_dimension: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | # Make $this->text_wrap() possible. | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | shift if ref $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my $text = shift; | |||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my $lines = split_to_lines($text); | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my $height = scalar @$lines; | |||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my $width = 0; | |||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | foreach (@$lines) | |||||||||||||||||||||||||||||||||||||||||
| 365 | { | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $l = length($_); | |||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | $width = $l if $l > $width; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | return ($width, $height); | |||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 374 | # Keyboard input | ||||||||||||||||||||||||||||||||||||||||||
| 375 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | # Constants: | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | # Keys that are not defined in curses.h, but which might come in handy. | ||||||||||||||||||||||||||||||||||||||||||
| 380 | sub CUI_ESCAPE() { "\x1b" } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | sub CUI_TAB() { "\t" } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | sub CUI_SPACE() { " " } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | # Make ascii representation of a key. | ||||||||||||||||||||||||||||||||||||||||||
| 385 | sub key_to_ascii($;) | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
key_to_ascii: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | if ($key eq CUI_ESCAPE()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $key = '<Esc>'; | |||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | # Control characters. Change them into something printable | ||||||||||||||||||||||||||||||||||||||||||
| 394 | # via Curses' unctrl function. | ||||||||||||||||||||||||||||||||||||||||||
| 395 | ▶ | elsif ($key lt ' ' and $key ne "\n" and $key ne "\t") { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$key lt " " and $key ne "\n" and $key ne "\t"
$key lt " " and $key ne "\n"
MC/DC0%0/3
$key lt " " and $key ne "\n" and $key ne "\t"
$key lt " "
$key ne "\n"
$key ne "\t"
Truth table0%0/4
A and B and C
A= $key lt " "B= $key ne "\n"C= $key ne "\t"
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $key = '<' . uc(unctrl($key)) . '>'; | |||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | # Extended keys get translated into their names via Curses' | ||||||||||||||||||||||||||||||||||||||||||
| 400 | # keyname function. | ||||||||||||||||||||||||||||||||||||||||||
| 401 | elsif ($key =~ /^\d{2,}$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $key = '<' . uc(keyname($key)) . '>'; | |||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | return $key; | |||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | # For the select() syscall in char_read(). | ||||||||||||||||||||||||||||||||||||||||||
| 409 | my $rin = ''; | ||||||||||||||||||||||||||||||||||||||||||
| 410 | my $fno = fileno(STDIN); | ||||||||||||||||||||||||||||||||||||||||||
| 411 | $fno = 0 unless $fno >= 0; | ||||||||||||||||||||||||||||||||||||||||||
| 412 | vec($rin, $fno , 1) = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | sub char_read(;$) | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
char_read: called CC=5 SCAR=16.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 1 | my $blocktime = shift; | |||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | # Initialize the toplevel window for | ||||||||||||||||||||||||||||||||||||||||||
| 420 | # reading a key. | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 1 | my $s = $this->root->{-canvasscr}; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 1 | noecho(); | |||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | raw(); | |||||||||||||||||||||||||||||||||||||||||
| 424 | 1 | $s->keypad(1); | |||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | # Read input on STDIN. | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 1 | my $key = '-1'; | |||||||||||||||||||||||||||||||||||||||||
| 428 | 1 | ▶ | $blocktime = undef if $blocktime < 0; # Wait infinite | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | my $crin = $rin; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 1 | $! = 0; | |||||||||||||||||||||||||||||||||||||||||
| 431 | 1 | my $found = select($crin, undef, undef, $blocktime); | |||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 1 | ▶ | if ($found < 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | print STDERR "DEBUG: get_key() -> select() -> $!\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | if $Curses::UI::debug; | ||||||||||||||||||||||||||||||||||||||||||
| 436 | } elsif ($found) { | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 1 | $key = $s->getch(); | |||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 1 | return $key; | |||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | sub get_key(;$) | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_key: called CC=31 SCAR=62.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | ▶ | my $blocktime = shift || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 1 | my $key = $this->char_read($blocktime); | |||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | # ------------------------------------ # | ||||||||||||||||||||||||||||||||||||||||||
| 451 | # Hacks for broken termcaps / curses # | ||||||||||||||||||||||||||||||||||||||||||
| 452 | # ------------------------------------ # | ||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | ▶ | $key = KEY_BACKSPACE if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ord $key == 127 or $key eq "\b"
MC/DC0%0/2
ord $key == 127 or $key eq "\b"
ord $key == 127
$key eq "\b"
Truth table33%1/3
A or B
A= ord $key == 127B= $key eq "\b"
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | ord($key) == 127 or | ||||||||||||||||||||||||||||||||||||||||||
| 456 | $key eq "\cH" | ||||||||||||||||||||||||||||||||||||||||||
| 457 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | 1 | ▶ | $key = KEY_DC if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "\177" or $key eq "\4"
MC/DC0%0/2
$key eq "\177" or $key eq "\4"
$key eq "\177"
$key eq "\4"
Truth table33%1/3
A or B
A= $key eq "\177"B= $key eq "\4"
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | $key eq "\c?" or | ||||||||||||||||||||||||||||||||||||||||||
| 461 | $key eq "\cD" | ||||||||||||||||||||||||||||||||||||||||||
| 462 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 1 | ▶ | $key = KEY_ENTER if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key eq "\n" or $key eq "\r"
MC/DC0%0/2
$key eq "\n" or $key eq "\r"
$key eq "\n"
$key eq "\r"
Truth table33%1/3
A or B
A= $key eq "\n"B= $key eq "\r"
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | $key eq "\n" or | ||||||||||||||||||||||||||||||||||||||||||
| 466 | $key eq "\cM" | ||||||||||||||||||||||||||||||||||||||||||
| 467 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | # Catch ESCape sequences. | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 1 | my $ESC = CUI_ESCAPE(); | |||||||||||||||||||||||||||||||||||||||||
| 471 | 1 | ▶ | if ($key eq $ESC) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | { | ||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | $key .= $this->char_read(0); | |||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | # Only ESC pressed? | ||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | $key = $ESC if $key eq "${ESC}-1" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key eq "$ESC-1" or $key eq "$ESC$ESC"
MC/DC0%0/2
$key eq "$ESC-1" or $key eq "$ESC$ESC"
$key eq "$ESC-1"
$key eq "$ESC$ESC"
Truth table0%0/3
A or B
A= $key eq "$ESC-1"B= $key eq "$ESC$ESC"
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | or $key eq "${ESC}${ESC}"; | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | return $key if $key eq $ESC; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | # Not only a single ESC? | ||||||||||||||||||||||||||||||||||||||||||
| 481 | # Then get extra keypresses. | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | $key .= $this->char_read(0); | |||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | while ($key =~ /\[\d+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | $key .= $this->char_read(0); | |||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | # Function keys on my Sun Solaris box. | ||||||||||||||||||||||||||||||||||||||||||
| 488 | # I have no idea of the portability of | ||||||||||||||||||||||||||||||||||||||||||
| 489 | # this stuff, but it works for me... | ||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if ($key =~ /\[(\d+)\~/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | { | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my $digit = $1; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | if ($digit >= 11 and $digit <= 15) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$digit >= 11 and $digit <= 15
MC/DC0%0/2
$digit >= 11 and $digit <= 15
$digit >= 11
$digit <= 15
Truth table0%0/3
A and B
A= $digit >= 11B= $digit <= 15
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | $key = KEY_F($digit-10); | |||||||||||||||||||||||||||||||||||||||||
| 495 | ▶ | } elsif ($digit >= 17 and $digit <= 21) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$digit >= 17 and $digit <= 21
MC/DC0%0/2
$digit >= 17 and $digit <= 21
$digit >= 17
$digit <= 21
Truth table0%0/3
A and B
A= $digit >= 17B= $digit <= 21
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | $key = KEY_F($digit-11); | |||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | $key = KEY_HOME if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$key eq $ESC . 'OH' or $key eq $ESC . '[7~' or $key eq $ESC . '[1~'
$key eq $ESC . 'OH' or $key eq $ESC . '[7~'
MC/DC0%0/3
$key eq $ESC . 'OH' or $key eq $ESC . '[7~' or $key eq $ESC . '[1~'
$key eq $ESC . 'OH'
$key eq $ESC . '[7~'
$key eq $ESC . '[1~'
Truth table0%0/4
A or B or C
A= $key eq $ESC . 'OH'B= $key eq $ESC . '[7~'C= $key eq $ESC . '[1~'
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | $key eq $ESC . "OH" or | ||||||||||||||||||||||||||||||||||||||||||
| 502 | $key eq $ESC . "[7~" or | ||||||||||||||||||||||||||||||||||||||||||
| 503 | $key eq $ESC . "[1~" | ||||||||||||||||||||||||||||||||||||||||||
| 504 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | ▶ | $key = KEY_BTAB if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key eq $ESC . 'OI' or $key eq $ESC . '[Z'
MC/DC0%0/2
$key eq $ESC . 'OI' or $key eq $ESC . '[Z'
$key eq $ESC . 'OI'
$key eq $ESC . '[Z'
Truth table0%0/3
A or B
A= $key eq $ESC . 'OI'B= $key eq $ESC . '[Z'
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | $key eq $ESC . "OI" or # My xterm under solaris | ||||||||||||||||||||||||||||||||||||||||||
| 508 | $key eq $ESC . "[Z" # My xterm under Redhat Linux | ||||||||||||||||||||||||||||||||||||||||||
| 509 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | $key = KEY_DL if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | $key eq $ESC . "[2K" | ||||||||||||||||||||||||||||||||||||||||||
| 513 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | $key = KEY_END if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key eq $ESC . 'OF' or $key eq $ESC . '[4~'
MC/DC0%0/2
$key eq $ESC . 'OF' or $key eq $ESC . '[4~'
$key eq $ESC . 'OF'
$key eq $ESC . '[4~'
Truth table0%0/3
A or B
A= $key eq $ESC . 'OF'B= $key eq $ESC . '[4~'
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | $key eq $ESC . "OF" or | ||||||||||||||||||||||||||||||||||||||||||
| 517 | $key eq $ESC . "[4~" | ||||||||||||||||||||||||||||||||||||||||||
| 518 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | $key = KEY_PPAGE if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | $key eq $ESC . "[5~" | ||||||||||||||||||||||||||||||||||||||||||
| 522 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | ▶ | $key = KEY_NPAGE if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | $key eq $ESC . "[6~" | ||||||||||||||||||||||||||||||||||||||||||
| 526 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | # ----------# | ||||||||||||||||||||||||||||||||||||||||||
| 530 | # Debugging # | ||||||||||||||||||||||||||||||||||||||||||
| 531 | # ----------# | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | 1 | ▶ | if ($Curses::UI::debug and $key ne "-1") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Curses::UI::debug and $key ne -1
MC/DC0%0/2
$Curses::UI::debug and $key ne -1
$Curses::UI::debug
$key ne -1
Truth table33%1/3
A and B
A= $Curses::UI::debugB= $key ne -1
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | { | ||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | my $k = ''; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | my @k = split //, $key; | |||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | foreach (@k) { $k .= $this->key_to_ascii($_) } | |||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | print STDERR "DEBUG: get_key() -> [$k]\n" | |||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 1 | return $key; | |||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | 1; | ||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | Curses::UI::Common - Common methods for Curses::UI | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | =head1 CLASS HIERARCHY | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | Curses::UI::Common - base class | ||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | package MyPackage; | ||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||
| 562 | use Curses::UI::Common; | ||||||||||||||||||||||||||||||||||||||||||
| 563 | use vars qw(@ISA); | ||||||||||||||||||||||||||||||||||||||||||
| 564 | @ISA = qw(Curses::UI::Common); | ||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | Curses::UI::Common is a collection of methods that is | ||||||||||||||||||||||||||||||||||||||||||
| 569 | shared between Curses::UI classes. | ||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||
| 574 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | =head2 Various methods | ||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | =item * B<parent> ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||
| 582 | Returns the data member $this->{B<-parent>}. | ||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | =item * B<root> ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | Returns the topmost B<-parent> (the Curses::UI instance). | ||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||
| 588 | =item * B<delallwin> ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | This method will walk through all the data members of the | ||||||||||||||||||||||||||||||||||||||||||
| 591 | class intance. Each data member that is a Curses::Window | ||||||||||||||||||||||||||||||||||||||||||
| 592 | descendant will be removed. | ||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | =item * B<accessor> ( NAME, [VALUE] ) | ||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | If VALUE is set, the value for the data member $this->{NAME} | ||||||||||||||||||||||||||||||||||||||||||
| 597 | will be changed. The method will return the current value for | ||||||||||||||||||||||||||||||||||||||||||
| 598 | data member $this->{NAME}. | ||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||
| 600 | =item * B<keys_to_lowercase> ( HASHREF ) | ||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | All keys in the hash referred to by HASHREF will be | ||||||||||||||||||||||||||||||||||||||||||
| 603 | converted to lower case. | ||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | =head2 Text processing | ||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||
| 610 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||
| 612 | =item B<split_to_lines> ( TEXT ) | ||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | This method will split TEXT into a list of separate lines. | ||||||||||||||||||||||||||||||||||||||||||
| 615 | It returns a reference to this list. | ||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | =item B<scrlength> ( LINE ) | ||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | Returns the screenlength of the string LINE. The difference | ||||||||||||||||||||||||||||||||||||||||||
| 620 | with the perl function length() is that this method will | ||||||||||||||||||||||||||||||||||||||||||
| 621 | expand TAB characters. It is exported by this class and it may | ||||||||||||||||||||||||||||||||||||||||||
| 622 | be called as a stand-alone routine. | ||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | =item B<text_dimension> ( TEXT ) | ||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | This method will return an array containing the width | ||||||||||||||||||||||||||||||||||||||||||
| 627 | (the length of the longest line) and the height (the | ||||||||||||||||||||||||||||||||||||||||||
| 628 | number of lines) of the TEXT. | ||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||
| 630 | =item B<text_wrap> ( LINE, LENGTH, WORDWRAP ) | ||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||
| 632 | =item B<WORDWRAP> ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||
| 634 | =item B<NO_WORDWRAP> ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | This method will wrap a line of text (LINE) to a | ||||||||||||||||||||||||||||||||||||||||||
| 637 | given length (LENGTH). If the WORDWRAP argument is | ||||||||||||||||||||||||||||||||||||||||||
| 638 | true, wordwrap will be enabled (this is the default | ||||||||||||||||||||||||||||||||||||||||||
| 639 | for WORDWRAP). It will return a reference to a list | ||||||||||||||||||||||||||||||||||||||||||
| 640 | of wrapped lines. It is exported by this class and it may | ||||||||||||||||||||||||||||||||||||||||||
| 641 | be called as a stand-alone routine. | ||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | The B<WORDWRAP> and B<NO_WORDWRAP> routines will | ||||||||||||||||||||||||||||||||||||||||||
| 644 | return the correct value vor the WORDWRAP argument. | ||||||||||||||||||||||||||||||||||||||||||
| 645 | These routines are exported by this class. | ||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | Example: | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | $this->text_wrap($line, 50, NO_WORDWRAP); | ||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||
| 651 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||
| 655 | =head2 Reading key input | ||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||
| 659 | =item B<CUI_ESCAPE> ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | =item B<CUI_TAB> ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | =item B<CUI_SPACE> ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||
| 665 | These are a couple of routines that are not defined by the | ||||||||||||||||||||||||||||||||||||||||||
| 666 | L<Curses|Curses> module, but which might be useful anyway. | ||||||||||||||||||||||||||||||||||||||||||
| 667 | These routines are exported by this class. | ||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||
| 669 | =item B<get_key> ( BLOCKTIME, CURSOR ) | ||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||
| 671 | This method will try to read a key from the keyboard. | ||||||||||||||||||||||||||||||||||||||||||
| 672 | It will return the key pressed or -1 if no key was | ||||||||||||||||||||||||||||||||||||||||||
| 673 | pressed. It is exported by this class and it may | ||||||||||||||||||||||||||||||||||||||||||
| 674 | be called as a stand-alone routine. | ||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||
| 676 | The BLOCKTIME argument can be used to set | ||||||||||||||||||||||||||||||||||||||||||
| 677 | the curses halfdelay (the time to wait before the | ||||||||||||||||||||||||||||||||||||||||||
| 678 | routine decides that no key was pressed). BLOCKTIME is | ||||||||||||||||||||||||||||||||||||||||||
| 679 | given in tenths of seconds. The default is 0 (non-blocking | ||||||||||||||||||||||||||||||||||||||||||
| 680 | key read). | ||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | Example: | ||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | my $key = $this->get_key(5) | ||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||
| 686 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | L<Curses::UI|Curses::UI> | ||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | Copyright (c) 2001-2002 Maurice Makaay. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | Maintained by Marcus Thiesen (marcus@cpan.thiesenweb.de) | ||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||
| 704 | This package is free software and is provided "as is" without express | ||||||||||||||||||||||||||||||||||||||||||
| 705 | or implied warranty. It may be used, redistributed and/or modified | ||||||||||||||||||||||||||||||||||||||||||
| 706 | under the same terms as perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||