From 2a287818ea73d54593ca140d36fb8af5c0c44862 Mon Sep 17 00:00:00 2001 From: mh Date: Mon, 16 Nov 2015 08:57:37 +0100 Subject: Create mh_windowfill.pl fill windows so scrolling starts bottom-up instead of top-down--- scripts/mh_windowfill.pl | 244 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 scripts/mh_windowfill.pl (limited to 'scripts') diff --git a/scripts/mh_windowfill.pl b/scripts/mh_windowfill.pl new file mode 100644 index 0000000..deee063 --- /dev/null +++ b/scripts/mh_windowfill.pl @@ -0,0 +1,244 @@ +############################################################################## +# +# mh_windowfill.pl v1.00 (20151116) +# +# Copyright (c) 2015 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 +# +# known issues: +# - /CLEAR will reset to top-down +# - it is possible to confuse the script into not filling with a combination +# of script load/unloads and window resizes. but it requires effort +# +# history: +# v1.00 (20151116) +# initial release +# + +use v5.14.2; + +use strict; + +############################################################################## +# +# irssi head +# +############################################################################## + +use Irssi 20100403; +use Irssi::TextUI; + +our $VERSION = '1.00'; +our %IRSSI = +( + 'name' => 'mh_windowfill', + 'description' => 'fill windows so scrolling starts bottom-up instead of top-down', + 'license' => 'BSD', + 'authors' => 'Michael Hansen', + 'contact' => 'mh on IRCnet #help', + 'url' => 'irc://open.ircnet.net', +); + +############################################################################## +# +# global variables +# +############################################################################## + +our $windowfill_running = 0; + +############################################################################## +# +# common support functions +# +############################################################################## + +sub trim_spacelike($) +{ + my ($string) = @_; + + if (defined($string)) + { + $string =~ s/^\s+//g; + $string =~ s/\s+$//g; + + } else { + + $string = ''; + } + + return($string); +} + +############################################################################## +# +# script functions +# +############################################################################## + +sub windowfill($) +{ + my ($window) = @_; + + if (ref($window) ne 'Irssi::UI::Window') + { + die(); + } + + # + # fill window with empty lines and move already printed lines to the bottom + # + if (($window->view()->{'ypos'} + 2) <= $window->{'height'}) + { + + while (($window->view()->{'ypos'} + 2) <= $window->{'height'}) + { + $window->print('', MSGLEVEL_CLIENTCRAP | MSGLEVEL_NEVER | MSGLEVEL_NO_ACT | MSGLEVEL_NOHILIGHT); + } + + my $linecount = $window->{'height'}; + my $line = $window->view()->get_lines(); + + while ((ref($line) eq 'Irssi::TextUI::Line') and $linecount) + { + my $linetext = $line->get_text(1); + + if ($linetext ne '') + { + # reprint line + $window->print($linetext, MSGLEVEL_CLIENTCRAP | MSGLEVEL_NEVER | MSGLEVEL_NO_ACT | MSGLEVEL_NOHILIGHT); + $line = $line->next(); + $window->view()->remove_line($line->prev()); + + } else { + + # skip empty line + $line = $line->next(); + } + + $linecount--; + } + } + + return(1); +} + +sub windowfill_all() +{ + # + # fill all windows with empty lines + # + for my $window (Irssi::windows()) + { + if (ref($window) ne 'Irssi::UI::Window') + { + die(); + } + + windowfill($window); + } + + return(1); +} + +############################################################################## +# +# irssi signal handlers +# +############################################################################## + +sub signal_mainwindow_resized_last() +{ + if ($windowfill_running) + { + # + # fill all windows with empty lines + # + windowfill_all(); + } + + return(1); +} + +Irssi::signal_add_last('mainwindow resized', 'signal_mainwindow_resized_last'); + +sub signal_window_created_last($) +{ + my ($window) = @_; + + if (ref($window) ne 'Irssi::UI::Window') + { + die(); + } + + if ($windowfill_running) + { + # + # fill created window with empty lines + # + windowfill($window); + } + + return(1); +} + +Irssi::signal_add_last('window created', 'signal_window_created_last'); + +############################################################################## +# +# script on load +# +############################################################################## + +sub script_on_load($) +{ + my ($undef) = @_; + + if (defined($undef)) + { + die(); + } + + if ($windowfill_running) + { + die(); + } + + windowfill_all(); + $windowfill_running = 1; + + return(1); +} + +# +# start script in a timeout to avoid printing before irssis "loaded script" +# +if (not Irssi::timeout_add_once(10, 'script_on_load', undef)) +{ + die(); +} + +1; + +############################################################################## +# +# eof mh_windowfill.pl +# +############################################################################## -- cgit v1.2.3 From d65df71c60cdca32975e2f542b4f2ef8893aa515 Mon Sep 17 00:00:00 2001 From: mh Date: Tue, 17 Nov 2015 17:53:27 +0100 Subject: mh_windowfill v1.01 small cleanup and added screenshots--- scripts/mh_windowfill.pl | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) (limited to 'scripts') diff --git a/scripts/mh_windowfill.pl b/scripts/mh_windowfill.pl index deee063..1ef6b85 100644 --- a/scripts/mh_windowfill.pl +++ b/scripts/mh_windowfill.pl @@ -1,6 +1,6 @@ ############################################################################## # -# mh_windowfill.pl v1.00 (20151116) +# mh_windowfill.pl v1.01 (20151116) # # Copyright (c) 2015 Michael Hansen # @@ -22,12 +22,18 @@ # # fill windows so scrolling starts bottom-up instead of top-down # +# screenshots: +# without script: http://picpaste.com/cfda32a34ea96e16dcb3f2d956655ff6.png +# with script: http://picpaste.com/e3b84ead852e3e77b12ed69383f1f80c.png +# # known issues: # - /CLEAR will reset to top-down # - it is possible to confuse the script into not filling with a combination # of script load/unloads and window resizes. but it requires effort # # history: +# v1.01 (20151116) +# source cleanup # v1.00 (20151116) # initial release # @@ -45,11 +51,11 @@ use strict; use Irssi 20100403; use Irssi::TextUI; -our $VERSION = '1.00'; +our $VERSION = '1.01'; our %IRSSI = ( 'name' => 'mh_windowfill', - 'description' => 'fill windows so scrolling starts bottom-up instead of top-down', + 'description' => 'fill windows so scrolling starts bottom-up instead of top-down (screenshots in source)', 'license' => 'BSD', 'authors' => 'Michael Hansen', 'contact' => 'mh on IRCnet #help', @@ -64,29 +70,6 @@ our %IRSSI = our $windowfill_running = 0; -############################################################################## -# -# common support functions -# -############################################################################## - -sub trim_spacelike($) -{ - my ($string) = @_; - - if (defined($string)) - { - $string =~ s/^\s+//g; - $string =~ s/\s+$//g; - - } else { - - $string = ''; - } - - return($string); -} - ############################################################################## # # script functions @@ -107,7 +90,6 @@ sub windowfill($) # if (($window->view()->{'ypos'} + 2) <= $window->{'height'}) { - while (($window->view()->{'ypos'} + 2) <= $window->{'height'}) { $window->print('', MSGLEVEL_CLIENTCRAP | MSGLEVEL_NEVER | MSGLEVEL_NO_ACT | MSGLEVEL_NOHILIGHT); -- cgit v1.2.3 From 7c01dabf4f1136d232782f60f8eb55fc8dd08cb8 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 18 Nov 2015 17:27:58 +0100 Subject: Update mh_windowfill.pl --- scripts/mh_windowfill.pl | 157 +++++++++++++++++++---------------------------- 1 file changed, 63 insertions(+), 94 deletions(-) (limited to 'scripts') diff --git a/scripts/mh_windowfill.pl b/scripts/mh_windowfill.pl index 1ef6b85..6b1416e 100644 --- a/scripts/mh_windowfill.pl +++ b/scripts/mh_windowfill.pl @@ -1,6 +1,6 @@ ############################################################################## # -# mh_windowfill.pl v1.01 (20151116) +# mh_windowfill.pl v1.02 (20151118) # # Copyright (c) 2015 Michael Hansen # @@ -26,12 +26,10 @@ # without script: http://picpaste.com/cfda32a34ea96e16dcb3f2d956655ff6.png # with script: http://picpaste.com/e3b84ead852e3e77b12ed69383f1f80c.png # -# known issues: -# - /CLEAR will reset to top-down -# - it is possible to confuse the script into not filling with a combination -# of script load/unloads and window resizes. but it requires effort -# # history: +# v1.02 (20151118) +# new windowfill routine +# fixed /clear # v1.01 (20151116) # source cleanup # v1.00 (20151116) @@ -51,7 +49,7 @@ use strict; use Irssi 20100403; use Irssi::TextUI; -our $VERSION = '1.01'; +our $VERSION = '1.02'; our %IRSSI = ( 'name' => 'mh_windowfill', @@ -62,82 +60,69 @@ our %IRSSI = 'url' => 'irc://open.ircnet.net', ); -############################################################################## -# -# global variables -# -############################################################################## - -our $windowfill_running = 0; - ############################################################################## # # script functions # ############################################################################## -sub windowfill($) +sub windowfill_fill { my ($window) = @_; - if (ref($window) ne 'Irssi::UI::Window') + while ($window->view()->{'empty_linecount'}) { - die(); + $window->print('', 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()->{'ypos'} + 2) <= $window->{'height'}) + if ($window->view()->{'empty_linecount'}) { - while (($window->view()->{'ypos'} + 2) <= $window->{'height'}) + my $line = $window->view()->get_lines(); + my $linecount = 0; + + while ($line) { - $window->print('', MSGLEVEL_CLIENTCRAP | MSGLEVEL_NEVER | MSGLEVEL_NO_ACT | MSGLEVEL_NOHILIGHT); + $linecount++; + $line = $line->next(); } - my $linecount = $window->{'height'}; - my $line = $window->view()->get_lines(); + windowfill_fill($window); - while ((ref($line) eq 'Irssi::TextUI::Line') and $linecount) + $line = $window->view()->get_lines(); + + while ($linecount) { my $linetext = $line->get_text(1); - - if ($linetext ne '') - { - # reprint line - $window->print($linetext, MSGLEVEL_CLIENTCRAP | MSGLEVEL_NEVER | MSGLEVEL_NO_ACT | MSGLEVEL_NOHILIGHT); - $line = $line->next(); - $window->view()->remove_line($line->prev()); - - } else { - - # skip empty line - $line = $line->next(); - } - + $line = $line->next(); + $window->print($linetext, MSGLEVEL_NEVER); + $window->view()->remove_line($line->prev()); $linecount--; } } - - return(1); } -sub windowfill_all() +sub windowfill_all { - # - # fill all windows with empty lines - # for my $window (Irssi::windows()) { - if (ref($window) ne 'Irssi::UI::Window') - { - die(); - } - windowfill($window); } - - return(1); } ############################################################################## @@ -146,76 +131,60 @@ sub windowfill_all() # ############################################################################## -sub signal_mainwindow_resized_last() +sub signal_mainwindow_resized_last { - if ($windowfill_running) - { - # - # fill all windows with empty lines - # - windowfill_all(); - } + windowfill_all(); +} + +sub signal_window_created_last +{ + my ($window) = @_; - return(1); + windowfill($window); } -Irssi::signal_add_last('mainwindow resized', 'signal_mainwindow_resized_last'); +############################################################################## +# +# irssi command functions +# +############################################################################## -sub signal_window_created_last($) +sub command_clear { - my ($window) = @_; + my ($data, $server, $windowitem) = @_; - if (ref($window) ne 'Irssi::UI::Window') + if (not ($data =~ s/^!{3} //)) { - die(); - } + Irssi::active_win()->command('CLEAR !!! ' . $data); + windowfill_fill_all(); + Irssi::signal_stop(); - if ($windowfill_running) - { - # - # fill created window with empty lines - # - windowfill($window); - } + } else { - return(1); + Irssi::signal_continue($data, $server, $windowitem); + } } -Irssi::signal_add_last('window created', 'signal_window_created_last'); - ############################################################################## # # script on load # ############################################################################## -sub script_on_load($) +sub script_on_load { - my ($undef) = @_; - - if (defined($undef)) - { - die(); - } + Irssi::signal_add_last('mainwindow resized', 'signal_mainwindow_resized_last'); + Irssi::signal_add_last('window created', 'signal_window_created_last'); - if ($windowfill_running) - { - die(); - } + Irssi::command_bind('clear', 'command_clear'); windowfill_all(); - $windowfill_running = 1; - - return(1); } # # start script in a timeout to avoid printing before irssis "loaded script" # -if (not Irssi::timeout_add_once(10, 'script_on_load', undef)) -{ - die(); -} +Irssi::timeout_add_once(10, 'script_on_load', undef); 1; -- cgit v1.2.3 From 51f94205527f62a84a968f33882141bf7341ed25 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 25 Nov 2015 20:46:02 +0100 Subject: v1.03 --- scripts/mh_windowfill.pl | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'scripts') diff --git a/scripts/mh_windowfill.pl b/scripts/mh_windowfill.pl index 6b1416e..d180706 100644 --- a/scripts/mh_windowfill.pl +++ b/scripts/mh_windowfill.pl @@ -1,6 +1,6 @@ ############################################################################## # -# mh_windowfill.pl v1.02 (20151118) +# mh_windowfill.pl v1.03 (20151125) # # Copyright (c) 2015 Michael Hansen # @@ -27,6 +27,10 @@ # with script: http://picpaste.com/e3b84ead852e3e77b12ed69383f1f80c.png # # history: +# v1.03 (20151125) +# cleaned up /clear +# added view()->redraw() to windowfill() +# optimistically changed url # v1.02 (20151118) # new windowfill routine # fixed /clear @@ -49,7 +53,7 @@ use strict; use Irssi 20100403; use Irssi::TextUI; -our $VERSION = '1.02'; +our $VERSION = '1.03'; our %IRSSI = ( 'name' => 'mh_windowfill', @@ -57,7 +61,7 @@ our %IRSSI = 'license' => 'BSD', 'authors' => 'Michael Hansen', 'contact' => 'mh on IRCnet #help', - 'url' => 'irc://open.ircnet.net', + 'url' => 'http://scripts.irssi.org', ); ############################################################################## @@ -114,6 +118,8 @@ sub windowfill $window->view()->remove_line($line->prev()); $linecount--; } + + $window->view()->redraw(); } } @@ -153,16 +159,8 @@ sub command_clear { my ($data, $server, $windowitem) = @_; - if (not ($data =~ s/^!{3} //)) - { - Irssi::active_win()->command('CLEAR !!! ' . $data); - windowfill_fill_all(); - Irssi::signal_stop(); - - } else { - Irssi::signal_continue($data, $server, $windowitem); - } + windowfill_fill_all(); } ############################################################################## @@ -174,7 +172,7 @@ sub command_clear sub script_on_load { Irssi::signal_add_last('mainwindow resized', 'signal_mainwindow_resized_last'); - Irssi::signal_add_last('window created', 'signal_window_created_last'); + Irssi::signal_add_last('window created', 'signal_window_created_last'); Irssi::command_bind('clear', 'command_clear'); -- cgit v1.2.3