aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--prompt_info/prompt_info.pl7
-rw-r--r--scrolled-reminder/scrolled_reminder.pl165
2 files changed, 144 insertions, 28 deletions
diff --git a/prompt_info/prompt_info.pl b/prompt_info/prompt_info.pl
index ad5321b..aa52a81 100644
--- a/prompt_info/prompt_info.pl
+++ b/prompt_info/prompt_info.pl
@@ -33,8 +33,10 @@ $VERSION = "1.0.1";
changed => "24/7/2010"
);
+#sub DEBUG () { 1 }
sub DEBUG () { 0 }
+
my $prompt_additional_content = '';
Irssi::expando_create('prompt_additional', \&expando_prompt, {});
@@ -52,9 +54,10 @@ sub redraw_prompts {
sub handle_change_prompt_sig {
my ($text) = @_;
- print "Got prompt change sig with: $text" if DEBUG;
-
my $expanded_text = Irssi::parse_special($text);
+
+ print "Got prompt change sig with: $text -> $expanded_text" if DEBUG;
+
my $changed = ($expanded_text ne $prompt_additional_content);
$prompt_additional_content = $expanded_text;
diff --git a/scrolled-reminder/scrolled_reminder.pl b/scrolled-reminder/scrolled_reminder.pl
index d768220..32b3bb5 100644
--- a/scrolled-reminder/scrolled_reminder.pl
+++ b/scrolled-reminder/scrolled_reminder.pl
@@ -7,21 +7,66 @@ use Irssi::Irc;
use Data::Dumper;
+# Everyone is permitted to copy and distribute verbatim or modified
+# copies of this license document, and changing it is allowed as long
+# as the name is changed.
+
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+
+sub DEBUG () { 1 }
+
our $VERSION = '0.01';
-our %IRSSI = (
- authors => 'Tom Feist',
- contact => 'shabble@cowu.be',
- name => 'scrolled-reminder',
- description => 'Requires confirmation to messages sent'
- . 'when the current window is scrolled up',
-
- license => 'WTFPL; http://sam.zoy.org/wtfpl/',
- url => 'http://metavore.org/',
+our %IRSSI =
+ (
+ authors => 'Tom Feist',
+ contact => 'shabble+irssi@metavore.org',
+ name => 'scrolled-reminder',
+ description => 'Requires confirmation to messages sent'
+ . 'when the current window is scrolled up',
+
+ license => 'WTFPL; http://sam.zoy.org/wtfpl/',
+ url => 'http://github.com/shabble/shab-irssi-scripts/'
+ . 'tree/master/scrolled-reminder/',
);
+# check we have prompt_info loaded.
+
+sub script_is_loaded {
+ my $name = shift;
+ print "Checking if $name is loaded" if DEBUG;
+ no strict 'refs';
+ my $retval = defined %{ "Irssi::Script::${name}::" };
+ use strict 'refs';
+
+ return $retval;
+}
+
+unless (script_is_loaded('prompt_info')) {
+ die "This script requires 'prompt_info' in order to work. "
+ . "Please load it and try again";
+} else {
+ scroll_reminder_init();
+}
+
+my $permit_pending;
+my $pending_input = {};
+my $active;
+
+sub scroll_reminder_init {
+ $permit_pending = 0;
+ $active = 0;
+ # we need to be first so we can intercept stuff.
+ Irssi::signal_add_first('send text', \&handle_send_text);
+ Irssi::signal_add_first('gui key pressed', \&handle_keypress);
+}
+
+################################################################
sub handle_send_text {
- my ($text, $server_tag, $win_item) = @_;
+ my ($text, $server, $win_item) = @_;
unless ($win_item) {
# not all windows have window-items (eg: status window)
return;
@@ -30,38 +75,106 @@ sub handle_send_text {
my $window = $win_item->window;
my $view = $window->view;
+ # are we scrolled up?
+
+ # TODO: would be better to check if we're scrolled /and/ there's activity?
+ # eg: --more-- is showing?
+
if ($view->{bottom} != 1) {
- # we're scrolled up.
- unless (require_confirmation($window)) {
+
+ # have we got a pending line that we've already allowed?
+ if ($permit_pending) {
+
+ $pending_input = {};
+ $permit_pending = 0;
+
+ # no idea why we need to explicitly continue this time.
+ Irssi::signal_continue(@_);
+
+ } else {
+
+ # otherwise, store it and start the confirmation process.
+ $pending_input = {
+ text => $text,
+ server => $server,
+ win_item => $win_item
+ };
+
Irssi::signal_stop;
+ require_confirmation();
}
}
}
sub handle_keypress {
my ($key) = @_;
- Irssi::print("key pressed: " . $key);
+
+ # would be nicer to add/remove ourselves appropriately, but
+ # for odd reasons, that doesn't work.
+ return unless $active;
+
if ($key == 3) { # Ctrl-c
+
+ # notify, and have it disappear after a second.
+ set_prompt('aborted!');
+ Irssi::timeout_add_once(1000, sub { set_prompt('') }, undef);
+
+ # stick the input line back into the input buffer for them.
+ my $text = $pending_input->{text};
+ Irssi::gui_input_set($text);
+ Irssi::gui_input_set_pos(length $text);
+
+ # clean up the pending stuff
+ $permit_pending = 0;
+ $pending_input = {};
+
+ # don't draw the C-c.
+ Irssi::signal_stop();
+
+
+ # and, we don't need the handler to trigger anymore
+ $active = 0;
+
} elsif ($key == 11) { # Ctrl-k
+
+ # allow this to be reraised and pass through
+ # the send text handler.
+ $permit_pending = 1;
+
+ # stop the C-k from behaving normally.
+ Irssi::signal_stop();
+
+ # and re-raise the signal with stored params.
+ Irssi::signal_emit('send text',
+ $pending_input->{text},
+ $pending_input->{server},
+ $pending_input->{win_item});
+
+ # stop the key handler from doing stuff
+ $active = 0;
+ # and restore the prompt
+ set_prompt('');
+
} else {
- }
- Irssi::signal_remove('gui key pressed', \&handle_keypress);
+ #TODO: What should the behaviour of other keys be when we're
+ # awaiting a response?
+
+ Irssi::signal_stop();
+ return;
+ }
}
sub require_confirmation {
- my ($window) = @_;
- Irssi::signal_add_first('gui key pressed', \&handle_keypress);
-
- $window->print("You are scrolled up Really send?");
- write_to_prompt($window, 'Press Ctrl-K to confirm, Ctrl-C to cancel ');
+ # enable the key handler
+ $active = 1;
+ set_prompt('Scrolled Warning: C-k to confirm, C-c to cancel');
}
-sub write_to_prompt {
- my ($window, $msg) = @_;
- #$window->command("insert_text $msg");
+sub set_prompt {
+ my $msg = shift;
+ # add a leading space unless we're trying to clear it entirely.
+ $msg = ' ' . $msg if length $msg;
+ Irssi::signal_emit('change prompt', $msg);
}
-
-Irssi::signal_add_first('send text', 'handle_send_text');
-