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
|
use strictures 1;
package Test::Irssi::Callbacks;
use Moose;
use Data::Dump qw/dump/;
has 'parent'
=> (
is => 'ro',
isa => 'Test::Irssi',
required => 1,
);
sub register_vt_callbacks {
my ($self) = @_;
$self->log("Callbacks registered");
my $vt = $self->parent->vt;
# callbacks
$self->log("VT is " . ref($vt));
$vt->callback_set(OUTPUT => sub { \&vt_output }, $self);
$vt->callback_set(ROWCHANGE => sub { \&vt_rowchange }, $self);
$vt->callback_set(CLEAR => sub { \&vt_clear }, $self);
$vt->callback_set(SCROLL_DOWN => sub { \&vt_scr_dn }, $self);
$vt->callback_set(SCROLL_UP => sub { \&vt_scr_up }, $self);
$vt->callback_set(GOTO => sub { \&vt_goto }, $self);
}
sub vt_output {
my ($vt, $cb_name, $cb_data, $self) = @_;
$self->log( "OUTPUT: " . dump([@_[1..$#_]]));
}
sub vt_rowchange {
my ($vt, $cb_name, $arg1, $arg2, $self) = @_;
$self->log("Type of param is: " . ref($_)) for (@_);
$arg1 //= '?';
$arg2 //= '?';
$self->log( "-" x 100);
$self->log( "Row $arg1 changed: ");
my $bottom_line = $vt->rows();
$self->log( "-" x 100);
$self->log( "Window Line");
$self->log( "-" x 100);
$self->log( $vt->row_plaintext($bottom_line - 1));
$self->log( "-" x 100);
$self->log( "Prompt line");
$self->log( "-" x 100);
$self->log( $vt->row_plaintext($bottom_line));
}
sub vt_clear {
my ($vt, $cb_name, $arg1, $arg2, $self) = @_;
$arg1 //= '?';
$arg2 //= '?';
$self->log( "VT Cleared");
}
sub vt_scr_dn {
my ($vt, $cb_name, $arg1, $arg2, $self) = @_;
$arg1 //= '?';
$arg2 //= '?';
$self->log( "Scroll Down");
}
sub vt_scr_up {
my ($vt, $cb_name, $arg1, $arg2, $self) = @_;
$arg1 //= '?';
$arg2 //= '?';
$self->log( "Scroll Up");
}
sub vt_goto {
my ($vt, $cb_name, $arg1, $arg2, $self) = @_;
$arg1 //= '?';
$arg2 //= '?';
$self->log( "Goto: $arg1, $arg2");
}
sub vt_dump {
my ($self) = @_;
my $vt = $self->parent->vt;
my $rows = $self->parent->terminal_height;
my $str = '';
for my $y (1..$rows) {
$str .= $vt->row_sgrtext($y) . "\n";
}
return $str;
}
sub log {
my ($self, $msg) = @_;
$self->parent->_logfile_fh->say($msg);
}
__PACKAGE__->meta->make_immutable;
no Moose;
|