aboutsummaryrefslogtreecommitdiffstats
path: root/feature-tests/augment_inputline.pl
blob: 577f756c199dd108330a88c98fc60cddecab9e97 (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
use strict;
use Irssi;
use Irssi::TextUI; # for sbar_items_redraw
use Term::Size;

use vars qw($VERSION %IRSSI);
$VERSION = "1.0.1";
%IRSSI = (
	authors         => "shabble",
	contact         => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode',
	name            => "",
	description     => "",
	license         => "Public Domain",
	changed         => ""
);


my $buf = '';

Irssi::command_bind('dogui', \&print_to_input);
Irssi::signal_add_last('gui key pressed', \&key_pressed);

sub stuff {
    my $win = Irssi::active_win;
    my ($w, $h);
    $w = $win->{width};
    $h = $win->{height};

    my ($term_w, $term_h) = Term::Size::chars *STDOUT{IO};
    print "win size is $w,$h, term is $term_w, $term_h";
    print "Prompt len is: ", Irssi::format_get_length("{prompt foo bar}");
}

sub key_pressed {
    my ($key) = @_;
    my $char = chr($key);
    $buf .= $char;
    my $str = Irssi::parse_special('$L');

    print_to_input($str);
    
}

sub print_to_input {
    my ($str) = @_;
    $str = "%8$str%8";

    my ($term_w, $term_h) = Term::Size::chars *STDOUT{IO};

    my $prompt_offset = 11;
    my $theme = Irssi::current_theme();
    my $prompt = $theme->format_expand('{prompt $itemname $winname}',
                                       Irssi::EXPAND_FLAG_RECURSIVE_MASK);
    #print "Prompt is $prompt";
    Irssi::gui_printtext($prompt_offset, $term_h, $str);
}


sub parse_theme_file {
    my ($file) = @_;
    open my $fh, '<', $file or die "Couldn't open $file for reading: $!";
    while (my $line = <$fh>) {
        next if $line =~ m/^\s*#/; # comment
        if ($line =~ m/^\s*prompt\s*=\s*"([^"]+)";\s*$/) {
            my $prompt = $1;
        }
    }
    close $fh or die "Couldn't close fh for $file: $!";
}