aboutsummaryrefslogtreecommitdiffstats
path: root/feature-tests/hide_password.pl
blob: 2fe01fc4831e92ab22237fb1ffdc48c5aff8f22e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
=pod

=head1 NAME

hide_password.pl

=head1 DESCRIPTION

A minimalist template useful for basing actual scripts on.

=head1 INSTALLATION

Copy into your F<~/.irssi/scripts/> directory and load with
C</SCRIPT LOAD F<filename>>.

=head1 USAGE

None, since it doesn't actually do anything.

=head1 AUTHORS

Copyright E<copy> 2011 Tom Feist C<E<lt>shabble+irssi@metavore.orgE<gt>>

=head1 LICENCE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

=head1 BUGS

=head1 TODO

Use this template to make an actual script.

=cut

use strict;
use warnings;

use Irssi;
use Irssi::Irc;
use Irssi::TextUI;

use Data::Dumper;

our $VERSION = '0.1';
our %IRSSI = (
              authors     => 'shabble',
              contact     => 'shabble+irssi@metavore.org',
              name        => '',
              description => '',
              license     => 'MIT',
              updated     => '$DATE'
             );


my $password_active;
my $password_buffer;

sub PASSWORD_CHAR () { ord('#') }

sub init {
    Irssi::command_bind('password', \&cmd_password);
    $password_active = 0;
    $password_buffer = '';

}

sub cmd_password {
    # Hmm, broken.
    #Irssi::gui_input_set('Password: ');
    begin_entry_redirect();
}

sub begin_entry_redirect {
    $password_active = 1;
    $password_buffer = '';

    Irssi::signal_add_first('gui key pressed', 'sig_key_pressed');

}

sub end_entry_redirect {
    Irssi::signal_remove('gui key pressed', 'sig_key_pressed');
    $password_active = 0;
}

sub password_complete {
    Irssi::active_win->command("/echo Your password is: $password_buffer");
    Irssi::gui_input_set('');
}

sub sig_key_pressed {
    my ($key) = @_;

    return unless $password_active;

    my $char = chr $key;
    if ($char =~ m/\r|\n/) {
        end_entry_redirect();
        password_complete();
        Irssi::signal_stop;
    } else {
        # TODO: Test if the char is printable, and abort otherwise?
        $password_buffer .= $char;
        Irssi::signal_continue(PASSWORD_CHAR);
    }
}

init();