-
Notifications
You must be signed in to change notification settings - Fork 235
/
autoclearinput.pl
80 lines (65 loc) · 2.38 KB
/
autoclearinput.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
#
# autoclearinput.pl
# Automatically clears pending input when you are away.
#
#
# Settings:
# /SET autoclear_sec <seconds> (0 to disable, 30 by default)
#
# Commands:
# /AUTOCLEARED, /CLEARED Retrieve the last cleared line of input
#
use strict;
use Irssi;
use Irssi::TextUI;
use vars qw($VERSION %IRSSI);
$VERSION = '1.0.2';
%IRSSI = (
authors => 'Trevor "tee" Slocum',
name => 'AutoClearInput',
description => 'Automatically clears pending input when you are away.',
license => 'GPLv3',
url => 'https://github.com/tslocum/irssi-scripts',
changed => '2019-02-11'
);
my ($autoclear_tag, $autoclear_last_input);
sub autoclear_key_pressed {
return if (Irssi::settings_get_int("autoclear_sec") <= 0);
if (defined($autoclear_tag)) {
Irssi::timeout_remove($autoclear_tag);
}
$autoclear_tag = Irssi::timeout_add_once(Irssi::settings_get_int("autoclear_sec") * 1000, "autoclear_timeout", "");
}
sub autoclear_timeout {
return if (Irssi::settings_get_int("autoclear_sec") <= 0);
my $autoclear_current_input = Irssi::parse_special('$L');
$autoclear_current_input =~ s/^\s+//;
$autoclear_current_input =~ s/\s+$//;
if ($autoclear_current_input ne "") {
$autoclear_last_input = Irssi::parse_special('$L');
}
Irssi::gui_input_set("");
}
sub autoclear_retrieve {
if (defined($autoclear_last_input)) {
Irssi::timeout_add_once(50, "autoclear_retrieve_workaround", "");
} else {
Irssi::print($IRSSI{name} . ': No input has been cleared yet.');
}
}
sub autoclear_retrieve_workaround {
return if (!defined($autoclear_last_input));
Irssi::gui_input_set($autoclear_last_input);
Irssi::gui_input_set_pos(length($autoclear_last_input));
}
Irssi::settings_add_int("misc", "autoclear_sec", 30);
Irssi::signal_add_last("gui key pressed", "autoclear_key_pressed");
Irssi::command_bind("autocleared", "autoclear_retrieve");
Irssi::command_bind("cleared", "autoclear_retrieve");
print $IRSSI{name} . ': v' . $VERSION . ' loaded. Pending input ' .
(Irssi::settings_get_int("autoclear_sec") > 0
? ('will be cleared after %9' . Irssi::settings_get_int("autoclear_sec") . ' seconds%9 of idling.')
: 'clearing is currently %9disabled%9.');
print $IRSSI{name} . ': Configure this delay with: /SET autoclear_sec <seconds> [0 to disable]';
print $IRSSI{name} . ': Retrieve the last cleared line of input with: /CLEARED';