| 1 | package Zuzu::Module::TUI; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = '0.007002'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Zuzu::Error; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Zuzu::Util::NativeHelpers qw( native_function ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Zuzu::Value::Array; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Zuzu::Value::Boolean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Zuzu::Value::Function; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | my $TERM; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub _readline_term { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_readline_term: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | return undef if !-t STDIN; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | return $TERM if defined $TERM; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | return undef if !eval { require Term::ReadLine; 1 }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $TERM = Term::ReadLine->new('zuzu'); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | return $TERM; | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub _supports_ansi { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_supports_ansi: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | return 0 if $ENV{NO_COLOR}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | return 0 if !-t STDOUT; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ( $^O eq 'MSWin32' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | return 1 if $ENV{ANSICON} or $ENV{WT_SESSION} or $ENV{ConEmuANSI}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$ENV{"ANSICON"} or $ENV{"WT_SESSION"} or $ENV{"ConEmuANSI"}
$ENV{"ANSICON"} or $ENV{"WT_SESSION"}
MC/DC0%0/3
$ENV{"ANSICON"} or $ENV{"WT_SESSION"} or $ENV{"ConEmuANSI"}
$ENV{"ANSICON"}
$ENV{"WT_SESSION"}
$ENV{"ConEmuANSI"}
Truth table0%0/4
A or B or C
A= $ENV{"ANSICON"}B= $ENV{"WT_SESSION"}C= $ENV{"ConEmuANSI"}
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | return 1 if ( $ENV{TERM_PROGRAM} // '' ) ne ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$ENV{"TERM_PROGRAM"} // ""
MC/DC0%0/1
$ENV{"TERM_PROGRAM"} // ""
$ENV{"TERM_PROGRAM"}
Truth table0%0/2
A
A= $ENV{"TERM_PROGRAM"}
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my $term = $ENV{TERM} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{"TERM"} // ""
MC/DC0%0/1
$ENV{"TERM"} // ""
$ENV{"TERM"}
Truth table0%0/2
A
A= $ENV{"TERM"}
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | return 0 if $term eq '' or $term eq 'dumb'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$term eq "" or $term eq "dumb"
MC/DC0%0/2
$term eq "" or $term eq "dumb"
$term eq ""
$term eq "dumb"
Truth table0%0/3
A or B
A= $term eq ""B= $term eq "dumb"
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub _bool { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bool: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return Zuzu::Value::Boolean->new( value => $value ? 1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub _ansi_code { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ansi_code: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my ( $colour ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 48 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | black => 30, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | red => 31, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | green => 32, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | yellow => 33, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | blue => 34, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | magenta => 35, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | cyan => 36, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | white => 37, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | }->{ lc( defined $colour ? "$colour" : '' ) }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub _colour_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_colour_text: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my ( $runtime, $text, $colour ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $text = '' if !defined $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $text = $runtime->_to_String($text) if ref($text); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $code = _ansi_code($colour); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | return "$text" if !$code or !_supports_ansi(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$code and _supports_ansi()
MC/DC0%0/2
$code and _supports_ansi()
$code
_supports_ansi()
Truth table0%0/3
A and B
A= $codeB= _supports_ansi()
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return "\e[${code}m$text\e[0m"; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub _readline_supports_completion { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_readline_supports_completion: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | my $term = _readline_term() or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | return 0 if ref($term) eq 'Term::ReadLine::Stub'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return 1 if ref($term) eq 'Term::ReadLine::Perl'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $attribs = eval { $term->Attribs }; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return $attribs ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub _path_completions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_path_completions: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my ( $text, $directory_only ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $text = '' if !defined $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my ( $dir, $base ) = $text =~ m{\A(.*[/\\])([^/\\]*)\z} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | ? ( $1, $2 ) | ||||||||||||||||||||||||||||||||||||||||||
| 82 | : ( '', $text ); | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | my $search_dir = length($dir) ? $dir : '.'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | opendir my $dh, $search_dir or return []; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | while ( defined( my $entry = readdir($dh) ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | next if $entry eq '.' or $entry eq '..'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$entry eq "." or $entry eq ".."
MC/DC0%0/2
$entry eq "." or $entry eq ".."
$entry eq "."
$entry eq ".."
Truth table0%0/3
A or B
A= $entry eq "."B= $entry eq ".."
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | next if index( $entry, $base ) != 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $candidate = $dir . $entry; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $path = length($dir) ? $candidate : File::Spec->catfile( '.', $entry ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my $is_dir = -d $path ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | next if $directory_only and !$is_dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$directory_only and not $is_dir
MC/DC0%0/2
$directory_only and not $is_dir
$directory_only
not $is_dir
Truth table0%0/3
A and not(B)
A= $directory_onlyB= not $is_dir
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | push @out, $candidate . ( $is_dir ? '/' : '' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | closedir $dh; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return [ sort @out ]; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub _callback_completions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_callback_completions: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my ( $runtime, $callback, $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | return [] if !blessed($callback) or !$callback->isa('Zuzu::Value::Function'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($callback) and $callback->isa("Zuzu::Value::Function")
MC/DC0%0/2
builtin::blessed($callback) and $callback->isa("Zuzu::Value::Function")
builtin::blessed($callback)
$callback->isa("Zuzu::Value::Function")
Truth table0%0/3
A and B
A= builtin::blessed($callback)B= $callback->isa("Zuzu::Value::Function")
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $value = $runtime->_call_function( | |||||||||||||||||||||||||||||||||||||||||
| 103 | $callback, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | [ $text ], | ||||||||||||||||||||||||||||||||||||||||||
| 105 | {}, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | [], | ||||||||||||||||||||||||||||||||||||||||||
| 107 | '<std/tui>', | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | return [] if !blessed($value) or !$value->isa('Zuzu::Value::Array'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::Array")
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::Array")
builtin::blessed($value)
$value->isa("Zuzu::Value::Array")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::Array")
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | return [ map { $runtime->_to_String($_) } @{ $value->items } ]; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub _install_perl_readline_completion_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_install_perl_readline_completion_key: not called CC=2 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $installed = eval { | |||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | *{'readline::F_ZuzuComplete'} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | readline::complete_internal("\t") or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | readline::complete_internal('?') if @readline::matches > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | readline::rl_bind( 'Tab', 'ZuzuComplete' ); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 124 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | return $installed ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub _restore_perl_readline_completion_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_restore_perl_readline_completion_key: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | readline::rl_bind( 'Tab', 'Complete' ); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 132 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub _readline { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_readline: not called CC=19 SCAR=59.4
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my ( $runtime, $prompt, $default, $completion_callback ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | $prompt = '' if !defined $prompt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | $prompt = $runtime->_to_String($prompt) if ref($prompt); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | $default = '' if !defined $default; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | $default = $runtime->_to_String($default) if ref($default); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $completion_callback and not builtin::blessed($completion_callback) and "$completion_callback" ne ""
defined $completion_callback and not builtin::blessed($completion_callback)
MC/DC0%0/3
defined $completion_callback and not builtin::blessed($completion_callback) and "$completion_callback" ne ""
defined $completion_callback
not builtin::blessed($completion_callback)
"$completion_callback" ne ""
Truth table0%0/4
A and not(B) and C
A= defined $completion_callbackB= not builtin::blessed($completion_callback)C= "$completion_callback" ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | defined $completion_callback | ||||||||||||||||||||||||||||||||||||||||||
| 144 | and !blessed($completion_callback) | ||||||||||||||||||||||||||||||||||||||||||
| 145 | and "$completion_callback" ne '' | ||||||||||||||||||||||||||||||||||||||||||
| 146 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | die Zuzu::Error->new_runtime( | |||||||||||||||||||||||||||||||||||||||||
| 148 | message => 'readline completion must be Function or null', | ||||||||||||||||||||||||||||||||||||||||||
| 149 | file => '<std/tui>', | ||||||||||||||||||||||||||||||||||||||||||
| 150 | line => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 151 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $line; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if ( my $term = _readline_term() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $attribs = eval { $term->Attribs }; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $old_completion; | |||||||||||||||||||||||||||||||||||||||||
| 158 | my $old_completion_function; | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $state = 0; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $matches = []; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if ( $attribs and blessed($completion_callback) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attribs and builtin::blessed($completion_callback)
MC/DC0%0/2
$attribs and builtin::blessed($completion_callback)
$attribs
builtin::blessed($completion_callback)
Truth table0%0/3
A and B
A= $attribsB= builtin::blessed($completion_callback)
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | if ( ref($term) eq 'Term::ReadLine::Perl' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $old_completion_function = $attribs->{completion_function}; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | $attribs->{completion_function} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my ( $text, $line, $start ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $so_far = substr( $line, 0, $start ) . $text; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $matches = _callback_completions( | |||||||||||||||||||||||||||||||||||||||||
| 168 | $runtime, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | $completion_callback, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | $so_far, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ( @$matches == 1 and $matches->[0] =~ m{[/\\]\z} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$matches == 1 and $matches->[0] =~ m([/\\]\z)
MC/DC0%0/2
@$matches == 1 and $matches->[0] =~ m([/\\]\z)
@$matches == 1
$matches->[0] =~ m([/\\]\z)
Truth table0%0/3
A and B
A= @$matches == 1B= $matches->[0] =~ m([/\\]\z)
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $readline::rl_completer_terminator_character = ''; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | return @$matches; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | _install_perl_readline_completion_key(); | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $old_completion = $attribs->{completion_entry_function}; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | $attribs->{completion_entry_function} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my ( $text, $state_arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ( !$state_arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $matches = _callback_completions( | |||||||||||||||||||||||||||||||||||||||||
| 185 | $runtime, | ||||||||||||||||||||||||||||||||||||||||||
| 186 | $completion_callback, | ||||||||||||||||||||||||||||||||||||||||||
| 187 | $text, | ||||||||||||||||||||||||||||||||||||||||||
| 188 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $state = 0; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | return $matches->[ $state++ ]; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $line = $term->readline($prompt); | |||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | $attribs->{completion_entry_function} = $old_completion | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attribs and defined $old_completion
MC/DC0%0/2
$attribs and defined $old_completion
$attribs
defined $old_completion
Truth table0%0/3
A and B
A= $attribsB= defined $old_completion
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | if $attribs and defined $old_completion; | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | $attribs->{completion_function} = $old_completion_function | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attribs and defined $old_completion_function
MC/DC0%0/2
$attribs and defined $old_completion_function
$attribs
defined $old_completion_function
Truth table0%0/3
A and B
A= $attribsB= defined $old_completion_function
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | if $attribs and defined $old_completion_function; | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | _restore_perl_readline_completion_key() | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | if ref($term) eq 'Term::ReadLine::Perl'; | ||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | CORE::print $prompt; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | $line = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | return "$default" if !defined $line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | return length($line) ? $line : "$default"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 4 | ▶ | sub IMPORT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
IMPORT: called CC=1 SCAR=2.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 4 | my ( $class, $runtime ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | my $ansi_esc = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 217 | name => 'ansi_esc', | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | native => sub { return chr 27 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | my $supports_ansi = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 222 | name => 'supports_ansi', | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | native => sub { return _bool( _supports_ansi() ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | my $colour_text = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 227 | name => 'colour_text', | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my ( $text, $colour ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | return _colour_text( $runtime, $text, $colour ); | |||||||||||||||||||||||||||||||||||||||||
| 231 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | my $write = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 235 | name => 'write', | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my ( $text, $colour ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | CORE::print _colour_text( $runtime, $text, $colour ); | |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 240 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | my $write_line = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 244 | name => 'write_line', | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | my ( $text, $colour ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | CORE::print _colour_text( $runtime, $text, $colour ), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 249 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | my $readline = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 253 | name => 'readline', | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my ( $prompt, $default, $completion ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | return _readline( $runtime, $prompt, $default, $completion ); | |||||||||||||||||||||||||||||||||||||||||
| 257 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | my $readline_supports_completion = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 261 | name => 'readline_supports_completion', | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | native => sub { return _bool( _readline_supports_completion() ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | my $filename_completions = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 266 | name => 'filename_completions', | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my ( $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | return Zuzu::Value::Array->new( items => [] ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | if $runtime->is_denied('fs'); | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | return Zuzu::Value::Array->new( | |||||||||||||||||||||||||||||||||||||||||
| 272 | items => _path_completions( $text, 0 ), | ||||||||||||||||||||||||||||||||||||||||||
| 273 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 274 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | my $directory_completions = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 278 | name => 'directory_completions', | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my ( $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | return Zuzu::Value::Array->new( items => [] ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | if $runtime->is_denied('fs'); | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | return Zuzu::Value::Array->new( | |||||||||||||||||||||||||||||||||||||||||
| 284 | items => _path_completions( $text, 1 ), | ||||||||||||||||||||||||||||||||||||||||||
| 285 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 286 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 4 | ansi_esc => $ansi_esc, | |||||||||||||||||||||||||||||||||||||||||
| 291 | supports_ansi => $supports_ansi, | ||||||||||||||||||||||||||||||||||||||||||
| 292 | colour_text => $colour_text, | ||||||||||||||||||||||||||||||||||||||||||
| 293 | write => $write, | ||||||||||||||||||||||||||||||||||||||||||
| 294 | write_line => $write_line, | ||||||||||||||||||||||||||||||||||||||||||
| 295 | readline => $readline, | ||||||||||||||||||||||||||||||||||||||||||
| 296 | readline_supports_completion => $readline_supports_completion, | ||||||||||||||||||||||||||||||||||||||||||
| 297 | filename_completions => $filename_completions, | ||||||||||||||||||||||||||||||||||||||||||
| 298 | directory_completions => $directory_completions, | ||||||||||||||||||||||||||||||||||||||||||
| 299 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | B<< Zuzu::Module::TUI >> is copyright Toby Inkster. | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | It is free software; you may redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 311 | the terms of either the Artistic License 1.0 or the GNU General Public | ||||||||||||||||||||||||||||||||||||||||||
| 312 | License version 2. | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | =cut | ||||||||||||||||||||||||||||||||||||||||||