-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathmh_windowfill.pl
191 lines (165 loc) · 4.63 KB
/
mh_windowfill.pl
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
##############################################################################
#
# mh_windowfill.pl v1.07 (20160207)
#
# Copyright (c) 2015, 2016 Michael Hansen
#
# Permission to use, copy, modify, and distribute this software
# for any purpose with or without fee is hereby granted, provided
# that the above copyright notice and this permission notice
# appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
##############################################################################
#
# fill windows so scrolling starts bottom-up instead of top-down
#
# screenshots:
#
# without script: http://escaflowne.hro.nl/~mh/mh_windowfill_without.png
# or
# http://rud0lf.webatu.com/mh_windowfill_without.png
#
# with script: http://escaflowne.hro.nl/~mh/mh_windowfill_with.png
# or
# http://rud0lf.webatu.com/mh_windowfill_with.png
#
# history:
#
# v1.07 (20160207)
# changed url of screenshots because picpaste have a weird definition of forever
# added namespace to MSGLEVEL
# v1.06 (20151220)
# added changed field to irssi header
# v1.05 (20151206)
# added a few comments
# v1.04 (20151128)
# call windowfill* directly from signals
# removed on load timeout
# v1.03 (20151125)
# cleaned up /clear
# added view()->redraw() to windowfill()
# optimistically changed url
# v1.02 (20151118)
# new windowfill routine
# fixed /clear
# v1.01 (20151116)
# source cleanup
# v1.00 (20151116)
# initial release
#
use v5.14.2;
use strict;
##############################################################################
#
# irssi head
#
##############################################################################
use Irssi 20100403;
use Irssi::TextUI;
our $VERSION = '1.07';
our %IRSSI =
(
'name' => 'mh_windowfill',
'description' => 'fill windows so scrolling starts bottom-up instead of top-down (screenshots linked in source)',
'license' => 'BSD',
'authors' => 'Michael Hansen',
'contact' => 'mh on IRCnet #help',
'url' => 'http://scripts.irssi.org / https://github.com/mh-source/irssi-scripts',
'changed' => 'Sun Feb 7 18:24:50 CET 2016',
);
##############################################################################
#
# script functions
#
##############################################################################
sub windowfill_fill
{
my ($window) = @_;
while ($window->view()->{'empty_linecount'})
{
$window->print('', Irssi::MSGLEVEL_NEVER);
}
}
sub windowfill_fill_all
{
for my $window (Irssi::windows())
{
windowfill_fill($window);
}
}
sub windowfill
{
my ($window) = @_;
#
# fill window with empty lines and move already printed lines to the bottom
#
if ($window->view()->{'empty_linecount'})
{
my $line = $window->view()->get_lines();
my $linecount = 0;
#
# count lines we need to move
#
while ($line)
{
$linecount++;
$line = $line->next();
}
windowfill_fill($window);
$line = $window->view()->get_lines();
#
# move lines down
#
while ($linecount)
{
my $linetext = $line->get_text(1);
$line = $line->next();
$window->print($linetext, Irssi::MSGLEVEL_NEVER);
$window->view()->remove_line($line->prev());
$linecount--;
}
$window->view()->redraw();
}
}
sub windowfill_all
{
for my $window (Irssi::windows())
{
windowfill($window);
}
}
##############################################################################
#
# irssi command functions
#
##############################################################################
sub command_clear
{
my ($data, $server, $windowitem) = @_;
Irssi::signal_continue($data, $server, $windowitem);
windowfill_fill_all();
}
##############################################################################
#
# script on load
#
##############################################################################
Irssi::signal_add_last('mainwindow resized', 'windowfill_all');
Irssi::signal_add_last('window created', 'windowfill');
Irssi::command_bind('clear', 'command_clear');
windowfill_all();
1;
##############################################################################
#
# eof mh_windowfill.pl
#
##############################################################################