From 3f094d80c8c93bdf09977114bc17e07fda5d3963 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sun, 9 Jan 2011 10:28:31 +0000 Subject: uberprompt: use argument parser to ensure a mode is set for /prompt set --- prompt_info/uberprompt.pl | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'prompt_info/uberprompt.pl') 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) = @_; -- cgit v1.2.3 From a15b1c9cbd4a9054d7f32c2919c6b561ec62c735 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sun, 9 Jan 2011 10:33:13 +0000 Subject: uberprompt: switch to _debug_print(), and clean up some unnecessary debugging code --- prompt_info/uberprompt.pl | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index a480fc9..407119d 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -159,7 +159,7 @@ sub pre_init { sub prompt_subcmd_handler { my ($data, $server, $item) = @_; - $data =~ s/\s+$//g; # strip trailing whitespace. + #$data =~ s/\s+$//g; # strip trailing whitespace. Irssi::command_runsub('prompt', $data, $server, $item); } @@ -254,7 +254,6 @@ sub cmd_prompt_set { 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) { @@ -263,7 +262,6 @@ sub cmd_prompt_set { return; } - #$opt_modes[0] =~ s/^-//; my $mode = 'UP_' . uc($opt_modes[0]); Irssi::signal_emit 'change prompt', $rest, $mode; @@ -287,9 +285,9 @@ sub refresh_if_me { return unless $my_chan and $my_nick; - print "Chan: $channel->{name}, " + _debug_print "Chan: $channel->{name}, " . "nick: $nick->{nick}, " - . "me: $my_nick, chan: $my_chan" if DEBUG; + . "me: $my_nick, chan: $my_chan"; if ($my_chan eq $channel->{name} and $my_nick eq $nick->{nick}) { uberprompt_refresh(); @@ -318,7 +316,7 @@ sub reload_settings { my $new = Irssi::settings_get_str('uberprompt_format'); if ($prompt_format ne $new) { - print "Updated prompt format" if DEBUG; + _debug_print("Updated prompt format"); $prompt_format = $new; $prompt_format =~ s/\$uber/\$\$uber/; Irssi::abstracts_register(['uberprompt', $prompt_format]); @@ -329,7 +327,7 @@ sub reload_settings { # an update timer or something, rather than just refreshing on # every possible activity in init() while ($prompt_format =~ m/(?{$var_name} = Irssi::parse_special($1); } @@ -341,7 +339,7 @@ sub debug_prompt_changed { $text =~ s/%/%%/g; - print "DEBUG: Got $text, length: $len"; + print "DEBUG_HANDLER: Prompt Changed to: \"$text\", length: $len"; } sub change_prompt_handler { @@ -350,7 +348,7 @@ sub change_prompt_handler { # fix for people who used prompt_info and hence the signal won't # pass the second argument. $pos = 'UP_INNER' unless defined $pos; - print "Got prompt change signal with: $text, $pos" if DEBUG; + _debug_print("Got prompt change signal with: $text, $pos"); my ($changed_text, $changed_pos); $changed_text = defined $prompt_data ? $prompt_data ne $text : 1; @@ -360,7 +358,7 @@ sub change_prompt_handler { $prompt_data_pos = $pos; if ($changed_text || $changed_pos) { - print "Redrawing prompt" if DEBUG; + _debug_print("Redrawing prompt"); uberprompt_refresh(); } } @@ -425,12 +423,12 @@ sub uberprompt_render_prompt { } } - #print "Redrawing with: $prompt, size-only: $get_size_only" if DEBUG; + #_debug_print("Redrawing with: $prompt, size-only: $get_size_only"); if (($prompt ne $prompt_last) or $emit_request) { - # print "Emitting prompt changed signal" if DEBUG; + # _debug_print("Emitting prompt changed signal"); # my $exp = Irssi::current_theme()->format_expand($text, 0); my $ps = Irssi::parse_special($prompt); @@ -456,7 +454,7 @@ sub uberprompt_refresh { sub replace_prompt_items { # remove existing ones. - print "Removing original prompt" if DEBUG; + _debug_print("Removing original prompt"); _sbar_command('prompt', 'remove', 'prompt'); _sbar_command('prompt', 'remove', 'prompt_empty'); @@ -473,7 +471,7 @@ sub restore_prompt_items { _sbar_command('prompt', 'remove', 'uberprompt'); - print "Restoring original prompt" if DEBUG; + _debug_print("Restoring original prompt"); _sbar_command('prompt', 'reset'); } @@ -488,7 +486,7 @@ sub _sbar_command { my $command = sprintf 'STATUSBAR %s %s %s%s', $bar, $cmd, $args_str, defined $item ? $item : ''; - print "Running command: $command" if DEBUG; + _debug_print("Running command: $command"); Irssi::command($command); } -- cgit v1.2.3 From 6d4c7f5033350698f476ac7ab0c3099a650e7b9d Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sun, 9 Jan 2011 10:58:15 +0000 Subject: uberprompt: added /help prompt to mimic built-in help stuffs. --- prompt_info/uberprompt.pl | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 407119d..0706d29 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -23,12 +23,16 @@ # # /prompt set - sets the prompt to the given argument. $p in the argument will # be replaced by the original prompt content. +# A parameter corresponding to the UP_* constants listed below +# is required, in the format `/prompt set -inner Hello!' # /prompt clear - clears the additional data provided to the prompt. # /prompt on - enables the uberprompt (things may get confused if this is used # whilst the prompt is already enabled) # /prompt off - restore the original irssi prompt and prompt_empty statusbars. # unloading the script has the same effect. # +# /help prompt - show help for uberprompt commands +# # Additionally, the format for the prompt can be set via: # # UBERPROMPT FORMAT: @@ -174,6 +178,47 @@ sub _debug_print($) { Irssi::active_win->print($msg, Irssi::MSGLEVEL_CLIENTCRAP); } +sub _print_help { + my ($args) = @_; + if ($args =~ m/^\s*prompt/i) { + my @help_lines = + ( + "", + "PROMPT ON", + "PROMPT OFF", + "PROMPT CLEAR", + "PROMPT SET { -pre | -post | -only | -inner } ", + "", + "Commands for manipulating the UberPrompt.", + "", + "/PROMPT ON enables uberprompt, replacing the existing prompt ", + " statusbar-item", + "/PROMPT OFF disables it, and restores the original prompt item", + "/PROMPT CLEAR resets the value of any additional data set by /PROMPT SET", + " or a script", + "/PROMPT SET changes the contents of the prompt, according to the mode", + " and content provided.", + " -inner sets the value of the \$uber psuedo-variable in the", + " /set uberprompt_format setting.", + " -pre places the content before the current prompt string", + " -post places the content after the prompt string", + " -only replaces the entire prompt contents with the given string", + "", + "See Also:", + '', + '/SET uberprompt_format -- defaults to [$*$uber]', + "/SET uberprompt_autostart -- determines whether /PROMPT ON is run", + " automatically when the script loads", + "/set uberprompt_use_replaces -- toggles the use of the current theme", + " \"replaces\" setting. Especially", + " noticeable on brackets \"[ ]\" ", + "", + ); + + Irssi::print($_, Irssi::MSGLEVEL_CLIENTCRAP) for @help_lines; + Irssi::signal_stop; + } +} sub UNLOAD { deinit(); @@ -214,6 +259,8 @@ sub init { my $prompt_set_args_format = "inner pre post only"; Irssi::command_set_options('prompt set', $prompt_set_args_format); + Irssi::command_bind('help', \&_print_help); + Irssi::signal_add('setup changed', \&reload_settings); # intialise the prompt format. -- cgit v1.2.3 From 6deca692390e63157de0f5682020d65e4e3567f7 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Tue, 1 Mar 2011 20:27:13 +0000 Subject: uberprompt: updated docs to clarify $uber variable, and polish help stirngs. --- prompt_info/uberprompt.pl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 0706d29..70d083d 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -25,6 +25,9 @@ # be replaced by the original prompt content. # A parameter corresponding to the UP_* constants listed below # is required, in the format `/prompt set -inner Hello!' +# +# /prompt set [-inner|-pre|-post|only] +# # /prompt clear - clears the additional data provided to the prompt. # /prompt on - enables the uberprompt (things may get confused if this is used # whilst the prompt is already enabled) @@ -39,7 +42,9 @@ # # /set uberprompt_format # -# The default is [$*], which is the same as the default provided in default.theme. +# The default is [$*$uber], which is the same as the default provided in +# default.theme. $uber is a placeholder variable to contain your additions +# to the prompt when using the -inner mode. # Changing this setting will update the prompt immediately, unlike editing your theme. # # An additional variable available within this format is '$uber', which expands to @@ -198,11 +203,11 @@ sub _print_help { " or a script", "/PROMPT SET changes the contents of the prompt, according to the mode", " and content provided.", - " -inner sets the value of the \$uber psuedo-variable in the", + " { -inner sets the value of the \$uber psuedo-variable in the", " /set uberprompt_format setting.", - " -pre places the content before the current prompt string", - " -post places the content after the prompt string", - " -only replaces the entire prompt contents with the given string", + " | -pre places the content before the current prompt string", + " | -post places the content after the prompt string", + " | -only replaces the entire prompt contents with the given string }", "", "See Also:", '', -- cgit v1.2.3 From d431098109187fdfbf68f7d63864c94442dc3354 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 31 Mar 2011 22:03:34 +0100 Subject: uberprompt: add script developer notes and stealable code loading snippet to documentation at the top of the script. --- prompt_info/uberprompt.pl | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 70d083d..3ef220e 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -83,6 +83,62 @@ # # signal_add 'prompt changed', sub { my ($text, $len) = @_; ... do something ... }; # +# +# NOTES FOR SCRIPT WRITERS: +# +# The following code snippet can be used within your own script as a preamble +# to ensure that uberprompt is loaded before your script to avoid +# any issues with load order. It first checks if uberprompt is loaded, and +# if not, attempts to load it. If the load fails, the script will die +# with an error message, otherwise it will call your app_init() function. +# +# ---- start of snippet ---- + +# my $DEBUG_ENABLED = 0; +# sub DEBUG () { $DEBUG_ENABLED } +# +# # check we have uberprompt 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; +# } +# +# if (not script_is_loaded('uberprompt')) { +# +# print "This script requires 'uberprompt.pl' in order to work. " +# . "Attempting to load it now..."; +# +# Irssi::signal_add('script error', 'load_uberprompt_failed'); +# Irssi::command("script load uberprompt.pl"); +# +# unless(script_is_loaded('uberprompt')) { +# load_uberprompt_failed("File does not exist"); +# } +# app_init(); +# } else { +# app_init(); +# } +# +# sub load_uberprompt_failed { +# Irssi::signal_remove('script error', 'load_prompt_failed'); +# +# print "Script could not be loaded. Script cannot continue. " +# . "Check you have uberprompt.pl installed in your path and " +# . "try again."; +# +# die "Script Load Failed: " . join(" ", @_); +# } +# +# ---- end of snippet ---- +# +# +# # Bugs: # # * Resizing the terminal rapidly whilst using this script in debug mode -- cgit v1.2.3 From a78ca35574eded3972be42c339ee838afb0380fe Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 1 Apr 2011 06:36:04 +0100 Subject: uberprompt: added brace-truncation bug to BUGS section in comments. --- prompt_info/uberprompt.pl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 3ef220e..37c3c81 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -145,6 +145,8 @@ # may cause irssi to crash. See bug report at # http://bugs.irssi.org/index.php?do=details&task_id=772 for details. # +# * displaying strings containing braces ( {} ) only displays up to the first {. +# # TODO: # # * report failure (somehow) to clients if hte prompt is disabled. -- cgit v1.2.3 From 8a8ba2c51eadbc0a7ce0236ba6a04dd081f657e2 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 1 Apr 2011 06:43:04 +0100 Subject: modify all scripts to use the new script_is_loaded() function, since newer versions of perl get upset at defined(%hash). --- prompt_info/uberprompt.pl | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 37c3c81..3426711 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -100,13 +100,7 @@ # # check we have uberprompt 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; +# return exists($Irssi::Script::{shift . '::'}); # } # # if (not script_is_loaded('uberprompt')) { @@ -122,7 +116,7 @@ # } # app_init(); # } else { -# app_init(); +# app_init(); # } # # sub load_uberprompt_failed { -- cgit v1.2.3 From 3d8262cff80e0d1cf640feaa3abcf1b09d7c5e2d Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 1 Apr 2011 07:17:35 +0100 Subject: uberprompt: fix brace handling bug --- prompt_info/uberprompt.pl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 3426711..59dcb65 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -285,7 +285,9 @@ sub exp_lbrace() { '{' } sub exp_rbrace() { '}' } sub deinit { - Irssi::expando_destroy('brace'); + Irssi::expando_destroy('lbrace'); + Irssi::expando_destroy('rbrace'); + # remove uberprompt and return the original ones. print "Removing uberprompt and restoring original"; restore_prompt_items(); @@ -472,8 +474,8 @@ sub _escape_prompt_special { $str =~ s/\$/\$\$/g; $str =~ s/\\/\\\\/g; #$str =~ s/%/%%/g; - $str =~ s/{/\$lbrace/g; - $str =~ s/}/\$rbrace/g; + $str =~ s/{/\${lbrace}/g; + $str =~ s/}/\${rbrace}/g; return $str; } -- cgit v1.2.3 From acfafdfc07685c3ac2d572001a10d67870d74cf7 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 1 Apr 2011 07:17:54 +0100 Subject: uberprompt: general cleanup --- prompt_info/uberprompt.pl | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 59dcb65..e7f8672 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -139,8 +139,6 @@ # may cause irssi to crash. See bug report at # http://bugs.irssi.org/index.php?do=details&task_id=772 for details. # -# * displaying strings containing braces ( {} ) only displays up to the first {. -# # TODO: # # * report failure (somehow) to clients if hte prompt is disabled. @@ -175,7 +173,7 @@ use strict; use warnings; use Irssi; -use Irssi::TextUI; # for sbar_items_redraw +use Irssi::TextUI; use Data::Dumper; { package Irssi::Nick } @@ -300,7 +298,7 @@ sub init { Irssi::expando_create('lbrace', \&exp_lbrace, {}); Irssi::expando_create('rbrace', \&exp_rbrace, {}); - Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*$uber] '); + Irssi::settings_add_str ('uberprompt', 'uberprompt_format', '[$*$uber] '); Irssi::settings_add_bool('uberprompt', 'uberprompt_debug', 0); Irssi::settings_add_bool('uberprompt', 'uberprompt_autostart', 1); Irssi::settings_add_bool('uberprompt', 'uberprompt_use_replaces', 0); @@ -408,8 +406,7 @@ sub length_request_handler { sub reload_settings { - $use_replaces = Irssi::settings_get_bool('uberprompt_use_replaces'); - + $use_replaces = Irssi::settings_get_bool('uberprompt_use_replaces'); $DEBUG_ENABLED = Irssi::settings_get_bool('uberprompt_debug'); if (DEBUG) { @@ -418,7 +415,6 @@ sub reload_settings { Irssi::signal_remove 'prompt changed', 'debug_prompt_changed'; } - my $new = Irssi::settings_get_str('uberprompt_format'); if ($prompt_format ne $new) { @@ -493,7 +489,7 @@ sub uberprompt_render_prompt { } my $prompt = ''; # rendered content of the prompt. - my $theme = Irssi::current_theme; + my $theme = Irssi::current_theme; my $arg = $use_replaces ? 0 : Irssi::EXPAND_FLAG_IGNORE_REPLACES; $prompt = $theme->format_expand("{uberprompt $prompt_arg}", $arg); @@ -529,7 +525,7 @@ sub uberprompt_render_prompt { } } - #_debug_print("Redrawing with: $prompt, size-only: $get_size_only"); + _debug_print("rendering with: $prompt"); if (($prompt ne $prompt_last) or $emit_request) { @@ -550,7 +546,7 @@ sub uberprompt_draw { my $prompt = uberprompt_render_prompt(); my $ret = $sb_item->default_handler($get_size_only, $prompt, '', 0); - + _debug_print("redrawing with: $prompt"); return $ret; } -- cgit v1.2.3 From 9b4f3c204419e20bcb470b8aa04a6ffb4e35fdfb Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 1 Apr 2011 07:26:42 +0100 Subject: Bah. more fixing of script_is_loaded. --- prompt_info/uberprompt.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index e7f8672..63cd958 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -100,7 +100,7 @@ # # check we have uberprompt loaded. # # sub script_is_loaded { -# return exists($Irssi::Script::{shift . '::'}); +# return exists($Irssi::Script::{$_[0] . '::'}); # } # # if (not script_is_loaded('uberprompt')) { -- cgit v1.2.3 From 0287d05780ca7bb9430f116dca1a86ef6de210aa Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 18 Apr 2011 16:25:57 +0100 Subject: uberprompt: converted header comments to POD --- prompt_info/uberprompt.pl | 370 +++++++++++++++++++++++++--------------------- 1 file changed, 199 insertions(+), 171 deletions(-) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 63cd958..adafee7 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -1,173 +1,201 @@ -# This script replaces the default prompt status-bar item with one capable -# of displaying additional information, under either user control or via -# scripts. -# -# INSTALL: -# -# Place script in ~/.irssi/scripts/ and potentially symlink into autorun/ -# to ensure it starts at irssi startup. -# -# If not using autorun, manually load the script via: -# -# /script load uberprompt.pl -# -# If you have a custom prompt format, you may need to copy it to the -# uberprompt_format setting. See below for details. -# -# USAGE: -# -# Although the script is designed primarily for other scripts to set -# status information into the prompt, the following commands are available: -# -# TODO: Document positional settings. -# -# /prompt set - sets the prompt to the given argument. $p in the argument will -# be replaced by the original prompt content. -# A parameter corresponding to the UP_* constants listed below -# is required, in the format `/prompt set -inner Hello!' -# -# /prompt set [-inner|-pre|-post|only] -# -# /prompt clear - clears the additional data provided to the prompt. -# /prompt on - enables the uberprompt (things may get confused if this is used -# whilst the prompt is already enabled) -# /prompt off - restore the original irssi prompt and prompt_empty statusbars. -# unloading the script has the same effect. -# -# /help prompt - show help for uberprompt commands -# -# Additionally, the format for the prompt can be set via: -# -# UBERPROMPT FORMAT: -# -# /set uberprompt_format -# -# The default is [$*$uber], which is the same as the default provided in -# default.theme. $uber is a placeholder variable to contain your additions -# to the prompt when using the -inner mode. -# Changing this setting will update the prompt immediately, unlike editing your theme. -# -# An additional variable available within this format is '$uber', which expands to -# the content of prompt data provided with the UP_INNER placement argument. For all -# other placement arguments, it will expand to the empty string ''. -# -# NOTE: this setting completely overrides the prompt="..." line in your .theme -# file, and may cause unexpected behaviour if your theme wishes to set a -# different form of prompt. It can be simply copied from the theme file into -# the above setting. -# -# Usage from other Scripts: signal 'change prompt' => 'string' => position -# -# eg: -# -# signal_emit 'change prompt' 'some_string', UberPrompt::UP_INNER; -# -# will set the prompt to include that content, by default '[$* some_string]' -# -# The possible position arguments are the following strings: -# -# UP_PRE - place the provided string before the prompt -- $string$prompt -# UP_INNER - place the provided string inside the prompt -- {prompt $* $string} -# UP_POST - place the provided string after the prompt -- $prompt$string -# UP_ONLY - replace the prompt with the provided string -- $string -# -# All strings may use the special variable '$prompt' to include the prompt -# verbatim at that position in the string. It is probably only useful for -# the UP_ONLY mode however. '$prompt_nt' will include the prompt, minus any -# trailing whitespace. -# -# NOTIFICATIONS: -# -# You can also be notified when the prompt changes in response to the previous -# signal or manual commands via: -# -# signal_add 'prompt changed', sub { my ($text, $len) = @_; ... do something ... }; -# -# -# NOTES FOR SCRIPT WRITERS: -# -# The following code snippet can be used within your own script as a preamble -# to ensure that uberprompt is loaded before your script to avoid -# any issues with load order. It first checks if uberprompt is loaded, and -# if not, attempts to load it. If the load fails, the script will die -# with an error message, otherwise it will call your app_init() function. -# -# ---- start of snippet ---- - -# my $DEBUG_ENABLED = 0; -# sub DEBUG () { $DEBUG_ENABLED } -# -# # check we have uberprompt loaded. -# -# sub script_is_loaded { -# return exists($Irssi::Script::{$_[0] . '::'}); -# } -# -# if (not script_is_loaded('uberprompt')) { -# -# print "This script requires 'uberprompt.pl' in order to work. " -# . "Attempting to load it now..."; -# -# Irssi::signal_add('script error', 'load_uberprompt_failed'); -# Irssi::command("script load uberprompt.pl"); -# -# unless(script_is_loaded('uberprompt')) { -# load_uberprompt_failed("File does not exist"); -# } -# app_init(); -# } else { -# app_init(); -# } -# -# sub load_uberprompt_failed { -# Irssi::signal_remove('script error', 'load_prompt_failed'); -# -# print "Script could not be loaded. Script cannot continue. " -# . "Check you have uberprompt.pl installed in your path and " -# . "try again."; -# -# die "Script Load Failed: " . join(" ", @_); -# } -# -# ---- end of snippet ---- -# -# -# -# Bugs: -# -# * Resizing the terminal rapidly whilst using this script in debug mode -# may cause irssi to crash. See bug report at -# http://bugs.irssi.org/index.php?do=details&task_id=772 for details. -# -# TODO: -# -# * report failure (somehow) to clients if hte prompt is disabled. -# * fix issue at autorun startup with sbar item doesn't exist. -# -# -# -# -# LICENCE: -# -# Copyright (c) 2010 Tom Feist -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +=pod + +=head1 NAME + +uberprompt.pl + +=head1 DESCRIPTION + +This script replaces the default prompt status-bar item with one capable of +displaying additional information, under either user control or via scripts. + +=head1 INSTALLATION + +Copy into your F<~/.irssi/scripts/> directory and load with +C>. + +It is recommended that you make it autoload in one of the +L. + +=head1 SETUP + +If you have a custom prompt format, you may need to copy it to the +uberprompt_format setting. See below for details. + +=head1 USAGE + +Although the script is designed primarily for other scripts to set +status information into the prompt, the following commands are available: + +TODO: Document positional settings. + +/prompt set - sets the prompt to the given argument. $p in the argument will + be replaced by the original prompt content. + A parameter corresponding to the UP_* constants listed below + is required, in the format `/prompt set -inner Hello!' + +/prompt set [-inner|-pre|-post|only] + +/prompt clear - clears the additional data provided to the prompt. +/prompt on - enables the uberprompt (things may get confused if this is used + whilst the prompt is already enabled) +/prompt off - restore the original irssi prompt and prompt_empty statusbars. + unloading the script has the same effect. + +/help prompt - show help for uberprompt commands + +=head1 UBERPROMPT FORMAT: + +CformatE> + +The default is C<[$*$uber]>, which is the same as the default provided in +F. + +Changing this setting will update the prompt immediately, unlike editing your theme. + +An additional variable available within this format is C<$uber>, which expands to +the content of prompt data provided with the C or +placement argument. + +For all other placement arguments, it will expand to the empty string. + +B This setting completely overrides the C line in your +.theme file, and may cause unexpected behaviour if your theme wishes to set a +different form of prompt. It can be simply copied from the theme file into the +above setting. + +=head2 SCRIPTING USAGE + +The primary purpose of uberprompt is to be used by other scripts to +display information in a way that is not possible by printing to the active +window or using statusbar items. + +The content of the prompt can be set from other scripts via the C<"change prompt"> +signal. + +For Example: + + signal_emit 'change prompt' 'some_string', UberPrompt::UP_INNER; + +will set the prompt to include that content, by default 'C<[$* some_string]>' + +The possible position arguments are the following strings: + +=over 4 + +=item * C - place the provided string before the prompt - C<$string$prompt> +=item * C - place the provided string inside the prompt - C<{prompt $* $string}> +=item * C - place the provided string after the prompt - C<$prompt$string> +=item * C - replace the prompt with the provided string - C<$string> + +All strings may use the special variable 'C<$prompt>' to include the prompt +verbatim at that position in the string. It is probably only useful for +the C mode however. '$C' will include the prompt, minus any +trailing whitespace. + +=head2 CHANGE NOTIFICATIONS + +You can also be notified when the prompt changes in response to the previous +signal or manual C commands via: + + signal_add 'prompt changed', sub { my ($text, $len) = @_; ... do something ... }; + +This callback will occur whenever the contents of the prompt is changed. + + +=head2 NOTES FOR SCRIPT WRITERS: + +The following code snippet can be used within your own script as a preamble +to ensure that uberprompt is loaded before your script to avoid +any issues with loading order. It first checks if uberprompt is loaded, and +if not, attempts to load it. If the load fails, the script will die +with an error message, otherwise it will call your app_init() function. + +I<---- start of snippet ----> + + my $DEBUG_ENABLED = 0; + sub DEBUG () { $DEBUG_ENABLED } + + # check we have uberprompt loaded. + + sub script_is_loaded { + return exists($Irssi::Script::{$_[0] . '::'}); + } + + if (not script_is_loaded('uberprompt')) { + + print "This script requires 'uberprompt.pl' in order to work. " + . "Attempting to load it now..."; + + Irssi::signal_add('script error', 'load_uberprompt_failed'); + Irssi::command("script load uberprompt.pl"); + + unless(script_is_loaded('uberprompt')) { + load_uberprompt_failed("File does not exist"); + } + app_init(); + } else { + app_init(); + } + + sub load_uberprompt_failed { + Irssi::signal_remove('script error', 'load_prompt_failed'); + + print "Script could not be loaded. Script cannot continue. " + . "Check you have uberprompt.pl installed in your path and " + . "try again."; + + die "Script Load Failed: " . join(" ", @_); + } + +I<---- end of snippet ----> + +=head1 AUTHORS + +Copyright E 2011 Tom Feist Cshabble+irssi@metavore.orgE> + +=head1 LICENCE + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +=head1 BUGS + +=over 4 + +=item * + +Resizing the terminal rapidly whilst using this script in debug mode may cause +irssi to crash. See bug report at http://bugs.irssi.org/index.php?do=details&task_id=772 for details. + +=back + +=head1 TODO + +=over 4 + +=item * report failure (somehow) to clients if hte prompt is disabled. + +=item * fix issue at autorun startup with sbar item doesn't exist. + +=back + +=cut use strict; use warnings; @@ -176,7 +204,7 @@ use Irssi; use Irssi::TextUI; use Data::Dumper; -{ package Irssi::Nick } +{ package Irssi::Nick } # magic. our $VERSION = "0.2"; our %IRSSI = -- cgit v1.2.3 From 344287c95bb566ac158d8986dac97c533bc33a78 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 18 Apr 2011 16:33:46 +0100 Subject: moved older scripts out of prompt-info to ensure uberprompt readme is correctly generated --- prompt_info/uberprompt.pl | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index adafee7..6a750ad 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -27,22 +27,35 @@ uberprompt_format setting. See below for details. Although the script is designed primarily for other scripts to set status information into the prompt, the following commands are available: -TODO: Document positional settings. +=over 4 + +=item * CmsgE> + +Sets the prompt to the given argument. Any use of C<$p> in the argument will +be replaced by the original prompt content. + +A parameter corresponding to the C constants listed below is required, in +the format C + +=item * C -/prompt set - sets the prompt to the given argument. $p in the argument will - be replaced by the original prompt content. - A parameter corresponding to the UP_* constants listed below - is required, in the format `/prompt set -inner Hello!' +Clears the additional data provided to the prompt. -/prompt set [-inner|-pre|-post|only] +=item * C -/prompt clear - clears the additional data provided to the prompt. -/prompt on - enables the uberprompt (things may get confused if this is used - whilst the prompt is already enabled) -/prompt off - restore the original irssi prompt and prompt_empty statusbars. - unloading the script has the same effect. +Eenables the uberprompt (things may get confused if this is used +whilst the prompt is already enabled) -/help prompt - show help for uberprompt commands +=item * C + +Restore the original irssi prompt and prompt_empty statusbars. unloading the +script has the same effect. + +=item * C + +show help for uberprompt commands + +=back =head1 UBERPROMPT FORMAT: @@ -54,7 +67,7 @@ F. Changing this setting will update the prompt immediately, unlike editing your theme. An additional variable available within this format is C<$uber>, which expands to -the content of prompt data provided with the C or +the content of prompt data provided with the C or C placement argument. For all other placement arguments, it will expand to the empty string. -- cgit v1.2.3 From 0baf0dc985765733499a2e1a2e5f4bce988c2c55 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 18 Apr 2011 16:37:44 +0100 Subject: uberprompt: rebuild docs AGAIN. :( --- prompt_info/uberprompt.pl | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 6a750ad..72b61f6 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -97,10 +97,15 @@ The possible position arguments are the following strings: =over 4 =item * C - place the provided string before the prompt - C<$string$prompt> + =item * C - place the provided string inside the prompt - C<{prompt $* $string}> + =item * C - place the provided string after the prompt - C<$prompt$string> + =item * C - replace the prompt with the provided string - C<$string> +=back + All strings may use the special variable 'C<$prompt>' to include the prompt verbatim at that position in the string. It is probably only useful for the C mode however. '$C' will include the prompt, minus any -- cgit v1.2.3 From 5cd0c2667f3f1669ece9f377338d148091b98756 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 18 Apr 2011 18:30:46 +0100 Subject: uberprompt: minor cleanup of MSGLEVEL args. --- prompt_info/uberprompt.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 72b61f6..9d97b0c 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -270,13 +270,13 @@ sub prompt_subcmd_handler { sub _error($) { my ($msg) = @_; - Irssi::active_win->print($msg, Irssi::MSGLEVEL_CLIENTERROR); + Irssi::active_win->print($msg, MSGLEVEL_CLIENTERROR); } sub _debug_print($) { return unless DEBUG; my ($msg) = @_; - Irssi::active_win->print($msg, Irssi::MSGLEVEL_CLIENTCRAP); + Irssi::active_win->print($msg, MSGLEVEL_CLIENTCRAP); } sub _print_help { @@ -316,7 +316,7 @@ sub _print_help { "", ); - Irssi::print($_, Irssi::MSGLEVEL_CLIENTCRAP) for @help_lines; + Irssi::print($_, MSGLEVEL_CLIENTCRAP) for @help_lines; Irssi::signal_stop; } } -- cgit v1.2.3 From 2ea2db3f227383be4ce7ffc6fdc1c358debadd46 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 18 Apr 2011 18:59:36 +0100 Subject: uberprompt: added uberprompt_load_hook and uberprompt_unload_hook settings which run user-specified commands during uberprompt startup and shutdown. --- prompt_info/uberprompt.pl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 9d97b0c..71638a5 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -255,6 +255,8 @@ my $emit_request = 0; my $expando_refresh_timer; my $expando_vars = {}; +my $init_callbacks = {load => '', unload => ''}; + pre_init(); sub pre_init { @@ -345,6 +347,10 @@ sub init { Irssi::expando_create('rbrace', \&exp_rbrace, {}); Irssi::settings_add_str ('uberprompt', 'uberprompt_format', '[$*$uber] '); + + Irssi::settings_add_str ('uberprompt', 'uberprompt_load_hook', ''); + Irssi::settings_add_str ('uberprompt', 'uberprompt_unload_hook', ''); + Irssi::settings_add_bool('uberprompt', 'uberprompt_debug', 0); Irssi::settings_add_bool('uberprompt', 'uberprompt_autostart', 1); Irssi::settings_add_bool('uberprompt', 'uberprompt_use_replaces', 0); @@ -455,6 +461,11 @@ sub reload_settings { $use_replaces = Irssi::settings_get_bool('uberprompt_use_replaces'); $DEBUG_ENABLED = Irssi::settings_get_bool('uberprompt_debug'); + $init_callbacks = { + load => Irssi::settings_get_str('uberprompt_load_hook'), + unload => Irssi::settings_get_str('uberprompt_unload_hook'), + }; + if (DEBUG) { Irssi::signal_add 'prompt changed', 'debug_prompt_changed'; } else { @@ -613,6 +624,17 @@ sub replace_prompt_items { qw/-alignment left -before input -priority '-1'/); _sbar_command('prompt', 'position', '100'); + + my $load_hook = $init_callbacks->{load}; + if (defined $load_hook and length $load_hook) { + eval { + Irssi::command($load_hook); + }; + if ($@) { + _error("Uberprompt user load-hook command ($load_hook) failed: $@"); + } + } + } sub restore_prompt_items { @@ -622,6 +644,17 @@ sub restore_prompt_items { _debug_print("Restoring original prompt"); _sbar_command('prompt', 'reset'); + + my $unload_hook = $init_callbacks->{unload}; + + if (defined $unload_hook and length $unload_hook) { + eval { + Irssi::command($unload_hook); + }; + if ($@) { + _error("Uberprompt user unload-hook command ($unload_hook) failed: $@"); + } + } } sub _sbar_command { -- cgit v1.2.3 From 3ae56e9a2fb9485ea62ce78883d22bac07531cd2 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 18 Apr 2011 19:28:49 +0100 Subject: uberprompt: added documentation for all the uberprompt settings, including the new uberprompt_*_hook commands. Updated Readme. --- prompt_info/uberprompt.pl | 56 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'prompt_info/uberprompt.pl') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 71638a5..62bda13 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -57,7 +57,9 @@ show help for uberprompt commands =back -=head1 UBERPROMPT FORMAT: +=head1 SETTINGS + +=head2 UBERPROMPT FORMAT CformatE> @@ -77,6 +79,58 @@ B This setting completely overrides the C line in your different form of prompt. It can be simply copied from the theme file into the above setting. +=head2 OTHER SETTINGS + +=over 4 + +=item * C + +Boolean value, which determines if uberprompt should enable itself automatically +upon loading. If Off, it must be enabled manually with C. Defaults to On. + +=item * C + +Boolean value, which determines if uberprompt should print debugging information. +Defaults to Off, and should probably be left that way unless requested for bug-tracing +purposes. + +=item * C + +String value containing the format-string which uberprompt uses to display the +prompt. Defaults to "C<[$*$uber] >", where C<$*> is the content the prompt would +normally display, and C<$uber> is a placeholder variable for dynamic content, as +described in the section above. + +=item * C + +String value which can contain one or more commands to be run whenever the uberprompt +is enabled, either via autostart, or C. Defaults to the empty string, in +which case no commands are run. Some examples include: + +C or + +C for those using vim_mode.pl who want +the command status indicator on the prompt line. + +=item * C + +String value, defaulting to the empty string, which can contain commands which +are executed when the uberprompt is disabled, either by unloading the script, +or by the command C. + +=item * C + +Boolean value, defaults to Off. If enabled, the format string for the prompt +will be subject to the I section of the theme. The most obvious +effect of this is that bracket characters C<[ ]> are displayed in a different +colour, typically quite dark. + +=back + +B For both C settings above, multiple commands can +be chained together in the form C. The C<^> prevents +any output from the commands (such as error messages) being displayed. + =head2 SCRIPTING USAGE The primary purpose of uberprompt is to be used by other scripts to -- cgit v1.2.3