aboutsummaryrefslogtreecommitdiffstats
path: root/prompt_info
diff options
context:
space:
mode:
authorTom Feist <shabble@metavore.org>2011-01-09 10:28:31 +0000
committerTom Feist <shabble@metavore.org>2011-01-09 10:28:31 +0000
commit3f094d80c8c93bdf09977114bc17e07fda5d3963 (patch)
tree7d4dd0b311f39d31681a68b521007d5afc4bacc6 /prompt_info
parentmake the blasted link absolute to stop GH screwing with me. (diff)
downloadirssi-scripts-3f094d80c8c93bdf09977114bc17e07fda5d3963.tar.gz
irssi-scripts-3f094d80c8c93bdf09977114bc17e07fda5d3963.zip
uberprompt: use argument parser to ensure a mode is set for /prompt set
Diffstat (limited to 'prompt_info')
-rw-r--r--prompt_info/uberprompt.pl47
1 files changed, 40 insertions, 7 deletions
diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl
index c1c4a55..a480fc9 100644
--- a/prompt_info/uberprompt.pl
+++ b/prompt_info/uberprompt.pl
@@ -163,6 +163,18 @@ sub prompt_subcmd_handler {
Irssi::command_runsub('prompt', $data, $server, $item);
}
+sub _error($) {
+ my ($msg) = @_;
+ Irssi::active_win->print($msg, Irssi::MSGLEVEL_CLIENTERROR);
+}
+
+sub _debug_print($) {
+ return unless DEBUG;
+ my ($msg) = @_;
+ Irssi::active_win->print($msg, Irssi::MSGLEVEL_CLIENTCRAP);
+}
+
+
sub UNLOAD {
deinit();
}
@@ -176,6 +188,7 @@ sub deinit {
print "Removing uberprompt and restoring original";
restore_prompt_items();
}
+
sub init {
Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw');
@@ -192,18 +205,15 @@ sub init {
Irssi::command_bind("prompt", \&prompt_subcmd_handler);
Irssi::command_bind('prompt on', \&replace_prompt_items);
Irssi::command_bind('prompt off', \&restore_prompt_items);
- Irssi::command_bind('prompt set',
- sub {
- my $args = shift;
- $args =~ s/^\s*(\w+)\s*(.*$)/$2/;
- my $mode = 'UP_' . uc($1);
- Irssi::signal_emit 'change prompt', $args, $mode;
- });
+ Irssi::command_bind('prompt set', \&cmd_prompt_set);
Irssi::command_bind('prompt clear',
sub {
Irssi::signal_emit 'change prompt', '$p', 'UP_POST';
});
+ my $prompt_set_args_format = "inner pre post only";
+ Irssi::command_set_options('prompt set', $prompt_set_args_format);
+
Irssi::signal_add('setup changed', \&reload_settings);
# intialise the prompt format.
@@ -239,6 +249,29 @@ sub init {
Irssi::signal_add('prompt length request', \&length_request_handler);
}
+sub cmd_prompt_set {
+ my $args = shift;
+ my @options_list = Irssi::command_parse_options "prompt set", $args;
+ if (@options_list) {
+ my ($options, $rest) = @options_list;
+ _debug_print("set options2: " . Dumper($options) . ":: $rest");
+
+ my @opt_modes = keys %$options;
+ if (@opt_modes != 1) {
+ _error '%_/prompt set%_ must specify exactly one mode of'
+ . ' {-inner, -only, -pre, -post}';
+ return;
+ }
+
+ #$opt_modes[0] =~ s/^-//;
+ my $mode = 'UP_' . uc($opt_modes[0]);
+
+ Irssi::signal_emit 'change prompt', $rest, $mode;
+ } else {
+ _error ('%_/prompt set%_ must specify a mode {-inner, -only, -pre, -post}');
+ }
+}
+
sub refresh_if_me {
my ($channel, $nick) = @_;