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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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 d4e0ae18456a828d2609e36726a4f0a0a7f95007 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 6 Apr 2011 09:19:40 +0100 Subject: input_overlay: cleanup, and work towards better region support. --- prompt_info/input_overlay.pl | 188 +++++++++++++++++++++++++++++++------------ 1 file changed, 137 insertions(+), 51 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/input_overlay.pl b/prompt_info/input_overlay.pl index 7a8dd9d..9d2a42b 100644 --- a/prompt_info/input_overlay.pl +++ b/prompt_info/input_overlay.pl @@ -27,8 +27,9 @@ my @regions; my ($term_w, $term_h) = (0, 0); -my $key_capture = 0; +my $overlay_active = 0; my $prompt_len = 5; +my $region_id = 0; sub DEBUG () { 1 } @@ -56,6 +57,16 @@ sub update_terminal_size { print "Terminal detected as $term_w cols by $term_h rows" if DEBUG; } +sub find_region { + my ($pos) = @_; + foreach my $region (@regions) { + next unless $pos > $region->{start}; + return $region if $pos <= $region->{end}; + } + print "failed to find region for pos: $pos"; + return undef; +} + sub redraw_overlay { # TODO: we can't assume the active win is the only one with overlays. #Irssi::active_win->view->redraw(); @@ -90,55 +101,25 @@ sub intercept_keypress { } -sub new_region { - my $key = shift; - print "Creating new Region"; - my $new_region - = { - text => '', - start => _pos() -1, - style => '%_', - open => 1, - draw => 1, - }; - - insert_into_region($key, $new_region); - - push @regions, $new_region; -} - -sub insert_into_region { - my ($key, $region) = @_; - - # if ($key == 127) { # backspace - # substr($region->{text}, -1, 1) = ''; - # } else { - # $region->{text} .= chr $key; - # } - my $input = Irssi::parse_special('$L'); - my $len = _pos() - $region->{start}; -# print "Input: $input, len: $len" if DEBUG; - - my $str = substr($input, $region->{start} , $len); -# print "Str: $str" if DEBUG; - $region->{text} = $str; - - # printf("region [%d-%d] now contains '%s'", - # $region->{start}, _pos(), - # $region->{text}) if DEBUG; -} - sub observe_keypress { my $key = shift; - if ($key_capture && $key > 31 && $key <= 127) { + print "Key " . chr ($key) . " pressed, pos: " . _pos(); + if ($key > 31 && $key <= 127) { # see if we're still appending to the last region: #print "Observed printable key: " . chr($key) if DEBUG; #print ''; my $latest_region = $regions[-1]; $latest_region = {} unless defined $latest_region; - if (not $latest_region->{open}) { - new_region($key); + + my $pos = _pos(); + my $reg = find_region($pos); + + if (defined $reg) { + insert_into_region($key, $reg); + } elsif (not $latest_region->{open}) { + my $style = $overlay_active?'%_':''; + new_region($style, $key); } else { insert_into_region($key, $latest_region); } @@ -148,6 +129,7 @@ sub observe_keypress { redraw_overlay(); } } + sub init { die "This script requires uberprompt.pl" @@ -160,8 +142,7 @@ sub init { Irssi::signal_add ('terminal resized', \&update_terminal_size); Irssi::signal_add_first('gui print text finished', \&augment_redraw); - Irssi::command_bind('region_start', \®ion_toggle); - Irssi::command('/bind ^C /region_start'); + setup_bindings(); Irssi::signal_add('prompt changed', sub { print "Updated prompt length: $_[1]"; @@ -173,22 +154,119 @@ sub init { update_terminal_size(); } +sub setup_bindings { + + Irssi::command_bind('region_start', \®ion_toggle); + Irssi::command_bind('region_clear', \®ion_clear); + Irssi::command_bind('region_print', \&print_regions); + + + Irssi::command('/bind ^C /region_start'); + ##Irssi::command('/bind ^D /region_clear'); + Irssi::command('/bind ^D /region_print'); + +} + + +################################################################################ + +sub escape_style { + my ($style) = @_; + $style =~ s/%/%%/g; + + return $style; +} + +sub print_regions { + foreach my $reg (@regions) { + printf("start: %d end: %d style: %s, text: \"%s\", open: %d, draw: %d", + $reg->{start}, $reg->{end}, escape_style($reg->{style}), + $reg->{text}, $reg->{open}, $reg->{draw}); + } +} + +sub new_region { + my ($style, $key) = @_; + + my $new_id = $region_id++; + _debug("Creating new Region: $new_id"); + + my $new_region + = { + id => $region_id++, + text => '', + start => _pos(), + end => _pos(), + style => $style, + open => 1, + draw => 1, + }; + + insert_into_region($key, $new_region); + + push @regions, $new_region; +} + +sub delete_region { + my ($region) = @_; + my $idx = 0; + foreach my $i (0..$#regions) { + if ($regions[$i]->{id} == $region->{id}) { + $idx = $i; + last; + } + } + print "Deleting region: $idx"; + splice(@regions, $idx, 1); # remove the selected region. +} + +sub insert_into_region { + my ($key, $region) = @_; + + my $pos = _pos(); + + if ($key == 127) { # backspace + substr($region->{text}, -1, 1) = ''; + $region->{end}--; + if ($region->{end} <= $region->{start}) { + delete_region($region); + } + } else { + printf("text: '%s', pos: %d, offset: %d", + $region->{text}, $pos, $pos - $region->{start}); + if ( $region->{end} < $pos) { + $region->{text} .= chr $key; + } else { + substr($region->{text}, $pos - $region->{start}, 0) = chr $key; + } + $region->{end}++; + } +} + +sub region_clear { + @regions = (); + Irssi::signal_emit('command redraw'); +} + sub region_toggle { - $key_capture = not $key_capture; - printf("Region is %sactive", $key_capture?'':'in'); + $overlay_active = not $overlay_active; + _debug("Region is %sactive", $overlay_active?'':'in'); #@regions = (); # terminate the previous region - my $latest_region = $regions[-1]; - if (defined $latest_region) { - $latest_region->{open} = 0; + + my $region = find_region(_pos()); + if (defined $region) { + $region->{open} = 0; + $region->{end} = _pos(); + debug("Region closed: %d-%d", $region->{start}, $region->{end}); } } sub script_is_loaded { my $name = shift; - print "Checking if $name is loaded" if DEBUG; + _debug("Checking if $name is loaded"); no strict 'refs'; - my $retval = defined %{ "Irssi::Script::${name}::" }; + my $retval = %{ "Irssi::Script::${name}::" }; use strict 'refs'; return $retval; @@ -198,5 +276,13 @@ sub _pos { return Irssi::gui_input_get_pos(); } +sub _input { + return Irssi::parse_special('$L'); +} + +sub _debug { + printf @_ if DEBUG(); +} + init(); -- cgit v1.2.3 From ce375dbf92cd89780138cff01deae6fbefb71cf6 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 18 Apr 2011 15:42:10 +0100 Subject: updated a whole bunch of README files. --- prompt_info/README.pod | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 prompt_info/README.pod (limited to 'prompt_info') diff --git a/prompt_info/README.pod b/prompt_info/README.pod new file mode 100644 index 0000000..e69de29 -- 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') 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 486aef8d31b80242c5e85951591f5063a0f47f63 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 18 Apr 2011 16:27:37 +0100 Subject: added uberprompt readme --- prompt_info/README.pod | 221 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) (limited to 'prompt_info') diff --git a/prompt_info/README.pod b/prompt_info/README.pod index e69de29..84b929b 100644 --- a/prompt_info/README.pod +++ b/prompt_info/README.pod @@ -0,0 +1,221 @@ + + +=cut + + + +=cut + + + +=cut + + + +=cut + +=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 + + + +=cut + -- 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/input_overlay.pl | 288 ----------------------------------- prompt_info/overlays.pl | 198 ------------------------ prompt_info/prompt_info.pl | 114 -------------- prompt_info/prompt_replace.pl | 346 ------------------------------------------ prompt_info/uberprompt.pl | 39 +++-- prompt_info/visual.pl | 168 -------------------- 6 files changed, 26 insertions(+), 1127 deletions(-) delete mode 100644 prompt_info/input_overlay.pl delete mode 100644 prompt_info/overlays.pl delete mode 100644 prompt_info/prompt_info.pl delete mode 100644 prompt_info/prompt_replace.pl delete mode 100644 prompt_info/visual.pl (limited to 'prompt_info') diff --git a/prompt_info/input_overlay.pl b/prompt_info/input_overlay.pl deleted file mode 100644 index 9d2a42b..0000000 --- a/prompt_info/input_overlay.pl +++ /dev/null @@ -1,288 +0,0 @@ - -use strict; -use warnings; - -use Irssi; -use Irssi::TextUI; # for sbar_items_redraw -use Data::Dumper; - - -# TODO: maybe eval { use Term::Size } and use tthat if poss. -our $VERSION = "0.2"; -our %IRSSI = - ( - authors => "shabble", - contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', - name => "overlays", - description => "Library script for drawing overlays on irssi UI", - license => "MIT", - changed => "24/7/2010" - ); - -# overlay := { $num1 => line1, $num2 => line2 } -# line := [ region, region, region ] -# region := { start => x, end => y, ...? } - -my @regions; - -my ($term_w, $term_h) = (0, 0); - -my $overlay_active = 0; -my $prompt_len = 5; -my $region_id = 0; - -sub DEBUG () { 1 } - -sub update_terminal_size { - - my @stty_data = qx/stty -a/; - my $line = $stty_data[0]; - - # linux - # speed 38400 baud; rows 36; columns 126; line = 0; - if ($line =~ m/rows (\d+); columns (\d+);/) { - $term_h = $1; - $term_w = $2; - # osx - # speed 9600 baud; 40 rows; 235 columns; - } elsif ($line =~ m/(\d+) rows; (\d+) columns;/) { - $term_h = $1; - $term_w = $2; - } else { - # guess? - $term_h = 24; - $term_w = 80; - } - - print "Terminal detected as $term_w cols by $term_h rows" if DEBUG; -} - -sub find_region { - my ($pos) = @_; - foreach my $region (@regions) { - next unless $pos > $region->{start}; - return $region if $pos <= $region->{end}; - } - print "failed to find region for pos: $pos"; - return undef; -} - -sub redraw_overlay { - # TODO: we can't assume the active win is the only one with overlays. - #Irssi::active_win->view->redraw(); - foreach my $region (@regions) { - if ($region->{draw}) { - my $str = $region->{style} . $region->{text} . '%n'; - my $x_offset = $region->{start} + $prompt_len; - - Irssi::gui_printtext($x_offset, $term_h, $str); - } - } - # my $inp = Irssi::parse_special('$L'); - # Irssi::gui_input_set($inp . ''); -} - -sub augment_redraw { - #print "Redraw called" if DEBUG; - #redraw_overlay(); - Irssi::timeout_add_once(20, \&redraw_overlay, 0); -} - -sub intercept_keypress { - my $key = shift; - - # intercept C-l for redraw, and force it to call - # /redraw instead of the internal function. - if ($key == 12) { # C-L - print "C-l pressed" if DEBUG; - Irssi::command("redraw"); - Irssi::signal_stop; - } - -} - -sub observe_keypress { - my $key = shift; - print "Key " . chr ($key) . " pressed, pos: " . _pos(); - if ($key > 31 && $key <= 127) { - # see if we're still appending to the last region: - #print "Observed printable key: " . chr($key) if DEBUG; - #print ''; - my $latest_region = $regions[-1]; - $latest_region = {} unless defined $latest_region; - - - my $pos = _pos(); - my $reg = find_region($pos); - - if (defined $reg) { - insert_into_region($key, $reg); - } elsif (not $latest_region->{open}) { - my $style = $overlay_active?'%_':''; - new_region($style, $key); - } else { - insert_into_region($key, $latest_region); - } - #Irssi::signal_stop; - # TODO: if the cursor pos is inside a region, handle it - # extend the region on addition? - redraw_overlay(); - } -} - -sub init { - - die "This script requires uberprompt.pl" - unless script_is_loaded('uberprompt'); - - Irssi::signal_add_last ('command redraw', \&augment_redraw); - Irssi::signal_add_first('gui key pressed', \&intercept_keypress); - Irssi::signal_add_last ('gui key pressed', \&observe_keypress); - - Irssi::signal_add ('terminal resized', \&update_terminal_size); - Irssi::signal_add_first('gui print text finished', \&augment_redraw); - - setup_bindings(); - - Irssi::signal_add('prompt changed', sub { - print "Updated prompt length: $_[1]"; - $prompt_len = $_[1]; - }); - - Irssi::signal_emit('prompt length request'); - - update_terminal_size(); -} - -sub setup_bindings { - - Irssi::command_bind('region_start', \®ion_toggle); - Irssi::command_bind('region_clear', \®ion_clear); - Irssi::command_bind('region_print', \&print_regions); - - - Irssi::command('/bind ^C /region_start'); - ##Irssi::command('/bind ^D /region_clear'); - Irssi::command('/bind ^D /region_print'); - -} - - -################################################################################ - -sub escape_style { - my ($style) = @_; - $style =~ s/%/%%/g; - - return $style; -} - -sub print_regions { - foreach my $reg (@regions) { - printf("start: %d end: %d style: %s, text: \"%s\", open: %d, draw: %d", - $reg->{start}, $reg->{end}, escape_style($reg->{style}), - $reg->{text}, $reg->{open}, $reg->{draw}); - } -} - -sub new_region { - my ($style, $key) = @_; - - my $new_id = $region_id++; - _debug("Creating new Region: $new_id"); - - my $new_region - = { - id => $region_id++, - text => '', - start => _pos(), - end => _pos(), - style => $style, - open => 1, - draw => 1, - }; - - insert_into_region($key, $new_region); - - push @regions, $new_region; -} - -sub delete_region { - my ($region) = @_; - my $idx = 0; - foreach my $i (0..$#regions) { - if ($regions[$i]->{id} == $region->{id}) { - $idx = $i; - last; - } - } - print "Deleting region: $idx"; - splice(@regions, $idx, 1); # remove the selected region. -} - -sub insert_into_region { - my ($key, $region) = @_; - - my $pos = _pos(); - - if ($key == 127) { # backspace - substr($region->{text}, -1, 1) = ''; - $region->{end}--; - if ($region->{end} <= $region->{start}) { - delete_region($region); - } - } else { - printf("text: '%s', pos: %d, offset: %d", - $region->{text}, $pos, $pos - $region->{start}); - if ( $region->{end} < $pos) { - $region->{text} .= chr $key; - } else { - substr($region->{text}, $pos - $region->{start}, 0) = chr $key; - } - $region->{end}++; - } -} - -sub region_clear { - @regions = (); - Irssi::signal_emit('command redraw'); -} - -sub region_toggle { - $overlay_active = not $overlay_active; - _debug("Region is %sactive", $overlay_active?'':'in'); - #@regions = (); - # terminate the previous region - - my $region = find_region(_pos()); - if (defined $region) { - $region->{open} = 0; - $region->{end} = _pos(); - debug("Region closed: %d-%d", $region->{start}, $region->{end}); - } -} - -sub script_is_loaded { - my $name = shift; - _debug("Checking if $name is loaded"); - no strict 'refs'; - my $retval = %{ "Irssi::Script::${name}::" }; - use strict 'refs'; - - return $retval; -} - -sub _pos { - return Irssi::gui_input_get_pos(); -} - -sub _input { - return Irssi::parse_special('$L'); -} - -sub _debug { - printf @_ if DEBUG(); -} - -init(); - diff --git a/prompt_info/overlays.pl b/prompt_info/overlays.pl deleted file mode 100644 index b3299e9..0000000 --- a/prompt_info/overlays.pl +++ /dev/null @@ -1,198 +0,0 @@ -# temp place for dumping all the stuff that doesn't belong in uberprompt. - -use strict; -use warnings; - -use Irssi; -use Irssi::TextUI; # for sbar_items_redraw -use Data::Dumper; - - -# TODO: maybe eval { use Term::Size } and use tthat if poss. -our $VERSION = "0.2"; -our %IRSSI = - ( - authors => "shabble", - contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', - name => "overlays", - description => "Library script for drawing overlays on irssi UI", - license => "MIT", - changed => "24/7/2010" - ); - -# overlay := { $num1 => line1, $num2 => line2 } -# line := [ region, region, region ] -# region := { start => x, end => y, ...? } - -my $overlays; -my ($term_w, $term_h) = (0, 0); - -sub DEBUG () { 1 } - -sub update_terminal_size { - - my @stty_data = qx/stty -a/; - my $line = $stty_data[0]; - - # linux - # speed 38400 baud; rows 36; columns 126; line = 0; - if ($line =~ m/rows (\d+); columns (\d+);/) { - $term_h = $1; - $term_w = $2; - # osx - # speed 9600 baud; 40 rows; 235 columns; - } elsif ($line =~ m/(\d+) rows; (\d+) columns;/) { - $term_h = $1; - $term_w = $2; - } else { - # guess? - $term_h = 24; - $term_w = 80; - } - - print "Terminal detected as $term_w cols by $term_h rows" if DEBUG; -} - -sub _add_overlay_region { - my ($x, $y, $text) = @_; - my $region = { start => $x, - text => $text, - }; - - my $o_line = $overlays->{$y}; - - unless (defined $o_line) { - $o_line = []; - $overlays->{$y} = $o_line; - } - - # foreach my $cur_region (@$o_line) { - # if (_region_overlaps($cur_region, $region)) { - # # do something. - # print "Region overlaps"; - # last; - # } - # } - - push @$o_line, $region; - redraw_overlay(); -} - -# sub _remove_overlay_region { -# my ($line, $start, $end) = @_; - -# my $o_line = $overlay->{$line}; -# return unless $o_line; - -# my $i = 0; -# foreach my $region (@$o_line) { -# if ($region->{start} == $start && $region->{end} == $end) { -# last; -# } -# $i++; -# } -# splice @$o_line, $i, 1, (); # remove it. -# } - -sub redraw_overlay { - # TODO: we can't assume the active win is the only one with overlays. - Irssi::active_win->view->redraw(); - foreach my $y (sort keys %$overlays) { - my $line = $overlays->{$y}; - foreach my $region (@$line) { - Irssi::gui_printtext($region->{start}, $y, $region->{text}); - } - } -} - -sub augment_redraw { - #print "Redraw called" if DEBUG; - #redraw_overlay(); - Irssi::timeout_add_once(10, \&redraw_overlay, 0); -} - -sub ctrl_L_intercept { - my $key = shift; - - if ($key == 12) { # C-L - print "C-l pressed" if DEBUG; - Irssi::command("redraw"); - Irssi::signal_stop(); - } -} - -sub init { - - die "needs uberprompt" unless script_is_loaded('uberprompt'); - - Irssi::signal_add_last ('command redraw', \&augment_redraw); - Irssi::signal_add_first('gui key pressed', \&ctrl_L_intercept); - Irssi::signal_add ('terminal resized', \&update_terminal_size); - Irssi::signal_add_first('gui print text finished', \&augment_redraw); - - my $api_sigs = { - # input signals - 'overlay create' => [qw/int int string/], # x, y, str - 'overlay remove' => [qw/int int/], # x, y - 'overlay clear' => [], # no args - # output signals - - }; - - Irssi::signal_register($api_sigs); - - Irssi::signal_add('overlay create', \&_add_overlay_region); - # Irssi::signal_add('overlay remove', \&_add_overlay_region); - Irssi::signal_add('overlay clear', \&_clear_overlay); - - Irssi::command_bind('ocr', \&cmd_overlay_create); - Irssi::command_bind('ocl', sub { Irssi::signal_emit('overlay clear'); }); - -} - -sub cmd_overlay_create { - my ($args) = @_; - my ($y, $x, $text) = split(/\s+/, $args, 3); - print "overlaying $text at [$x, $y]"; - - Irssi::signal_emit('overlay create', $x, $y, $text); -} - -sub _clear_overlay { - $overlays = {}; - redraw_overlay(); -} - -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; -} -print "Moo!"; -init(); - -__END__ - -# sub _draw_overlay_menu { - -# my $w = 10; - -# my @lines = ( -# '%7+' . ('-' x $w) . '+%n', -# sprintf('%%7|%%n%*s%%7|%%n', $w, 'bacon'), -# sprintf('|%*s|', $w, 'bacon'), -# sprintf('|%*s|', $w, 'bacon'), -# sprintf('|%*s|', $w, 'bacon'), -# sprintf('|%*s|', $w, 'bacon'), -# sprintf('|%*s|', $w, 'bacon'), -# '%7+' . ('-' x $w) . '+%n', -# ); -# my $i = 10; # start vert offset. -# for my $line (@lines) { -# Irssi::gui_printtext(int ($term_w / 2), $i++, $line); -# } -# } diff --git a/prompt_info/prompt_info.pl b/prompt_info/prompt_info.pl deleted file mode 100644 index 8ad63ba..0000000 --- a/prompt_info/prompt_info.pl +++ /dev/null @@ -1,114 +0,0 @@ -# Usage: - -# edit your theme, find the line beginning: -# -# prompt = "..." -# -# and add the string `$prompt_additional' somewhere inside it. -# If using the default: prompt = "[$*] ", then a good value would be: -# -# prompt = "[$*$prompt_additional] " -# -# Then place this script to your ~/.irssi/scripts directory (~/.irssi/scripts/) -# and symlink it to the ~/.irssi/scripts/autorun directory (which may need to -# be created first) -# -# You can also load it manually once the theme has been edited via -# -# /script load prompt_info.pl -# -# You will also need to reload your theme with the following command: -# -# /script exec Irssi::themes_reload() -# -# Once loaded, you can modify your prompt content by using the following command: -# -# /set_prompt -# -# You can also use it from other scripts by issuing a signal as follows: -# -# Irssi:signal_emit('change prompt', -# -# report bugs / feature requests to http://github.com/shabble/irssi-scripts/issues -# -# NOTE: it does not appear to be possible to use colours in your prompt at present. -# This is unlikely to change without source-code changes to Irssi itself. - -use strict; -use warnings; - -use Irssi; -use Irssi::TextUI; # for sbar_items_redraw - -use vars qw($VERSION %IRSSI); -$VERSION = "1.0.1"; -%IRSSI = - ( - authors => "shabble", - contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', - name => "prompt_info", - description => "Helper script for dynamically adding text " - . "into the input-bar prompt.", - license => "Public Domain", - changed => "24/7/2010" - ); - -#sub DEBUG () { 1 } -sub DEBUG () { 0 } - - -my $prompt_additional_content = ''; - -Irssi::expando_create('prompt_additional', \&expando_prompt, {}); - -sub expando_prompt { - my ($server, $witem, $arg) = @_; - return $prompt_additional_content; - #return Irssi::current_theme->format_expand("{sb - #$prompt_additional_content}", 0x0f); -} - -sub redraw_prompts { - Irssi::statusbar_items_redraw ('prompt'); - Irssi::statusbar_items_redraw ('prompt_empty'); -} - -sub handle_change_prompt_sig { - my ($text) = @_; - - 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; - - if ($changed) { - print "Redrawing prompts" if DEBUG; - redraw_prompts(); - } -} - -sub prompt_additional_cmd { - my ($str) = @_; - print "Setting prompt to: $str" if DEBUG; - Irssi::signal_emit('change prompt', $str); -} - -test_abstract_setup(); -Irssi::signal_register({'change prompt' => [qw/string/]}); -Irssi::signal_add('change prompt' => \&handle_change_prompt_sig); - -Irssi::command_bind('set_prompt' => \&prompt_additional_cmd); - -sub test_abstract_setup { - my $theme = Irssi::current_theme(); - my $prompt = $theme->format_expand('{prompt}', 0); - if ($prompt !~ m/\$prompt_additional/) { - print "Prompt_Info: It looks like you haven't modified your theme" - . " to include the \$prompt_additional expando. You will not see" - . " any prompt info messages until you do. See script comments" - . "for details"; - } -} diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl deleted file mode 100644 index 30120f7..0000000 --- a/prompt_info/prompt_replace.pl +++ /dev/null @@ -1,346 +0,0 @@ -use strict; -use warnings; - -use Irssi; -use Irssi::TextUI; # for sbar_items_redraw -use Data::Dumper; - - - -our $VERSION = "0.1"; -our %IRSSI = - ( - authors => "shabble", - contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', - name => "prompt_info", - description => "Helper script for dynamically adding text " - . "into the input-bar prompt.", - license => "Public Domain", - changed => "24/7/2010" - ); - -sub DEBUG () { 1 } -#sub DEBUG () { 0 } - -my $prompt_data = undef; -my $prompt_item = undef; - -my $region_active = 0; - -my ($term_w, $term_h) = (0, 0); - -# visual region selected. -my ($region_start, $region_end) = (0, 0); -my $region_content = ''; - -my $prompt_format = ''; - -init(); - -sub update_terminal_size { - - my @stty_data = qx/stty -a/; - my $line = $stty_data[0]; - - # linux - # speed 38400 baud; rows 36; columns 126; line = 0; - if ($line =~ m/rows (\d+); columns (\d+);/) { - $term_h = $1; - $term_w = $2; - # osx - # speed 9600 baud; 40 rows; 235 columns; - } elsif ($line =~ m/(\d+) rows; (\d+) columns;/) { - $term_h = $1; - $term_w = $2; - } else { - # guess? - $term_h = 24; - $term_w = 80; - } - - print "Terminal detected as $term_w cols by $term_h rows" if DEBUG; -} - -sub prompt_subcmd_handler { - my ($data, $server, $item) = @_; - $data =~ s/\s+$//g; # strip trailing whitespace. - Irssi::command_runsub('prompt', $data, $server, $item); -} - -sub visual_subcmd_handler { - my ($data, $server, $item) = @_; - $data =~ s/\s+$//g; # strip trailing whitespace. - Irssi::command_runsub('visual', $data, $server, $item); -} - -sub init { - - Irssi::statusbar_item_register ('uberprompt', 0, 'uberprompt_draw'); - - Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*] '); - - 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 { Irssi::signal_emit 'change prompt', shift; }); - Irssi::command_bind('prompt clear', - sub { Irssi::signal_emit 'change prompt', '$p'; }); - - # misc faff - Irssi::command_bind('visual', \&visual_subcmd_handler); - Irssi::command_bind('visual toggle', \&cmd_toggle_visual); - Irssi::command_bind('visual clear', \&cmd_clear_visual); - - Irssi::command("^BIND ^F /visual toggle"); - Irssi::command("^BIND ^G /visual clear"); - - Irssi::command_bind 'print_test', - sub { - Irssi::gui_printtext(0, 0, '%8hello there%n'); - }; - - # redraw interception - Irssi::signal_add_last('command redraw', \&augment_redraw); - Irssi::signal_add_first('gui key pressed', \&ctrl_l_intercept); - - # for updating the overlay. - Irssi::signal_add_last ('gui key pressed', \&key_pressed); - - # things to refresh the overlay for. - Irssi::signal_add('window changed', \&uberprompt_refresh); - Irssi::signal_add('window name changed', \&uberprompt_refresh); - Irssi::signal_add('window changed automatic', \&uberprompt_refresh); - Irssi::signal_add('window item changed', \&uberprompt_refresh); - - Irssi::signal_add('terminal resized', \&update_terminal_size); - Irssi::signal_add('setup changed', \&reload_settings); - - # so we know where the bottom line is - update_terminal_size(); - - # intialise the prompt format. - reload_settings(); - - # install our statusbars. - replace_prompt_items(); - - # the actual API signals. - Irssi::signal_register({'change prompt' => [qw/string/]}); - Irssi::signal_add('change prompt' => \&change_prompt_sig); - - Irssi::signal_register({'prompt changed' => [qw/string int/]}); -} - -sub change_prompt_sig { - my ($text) = @_; - - $text = '$p' . $text; - print "Got prompt change sig with: $text" if DEBUG; - - my $changed; - $changed = defined $prompt_data ? $prompt_data ne $text : 1; - - $prompt_data = $text; - - if ($changed) { - print "Redrawing prompt" if DEBUG; - uberprompt_refresh(); - } -} - - -sub UNLOAD { - # remove uberprompt and return the original ones. - restore_prompt_items(); -} - -sub reload_settings { - my $new = Irssi::settings_get_str('uberprompt_format'); - if ($prompt_format ne $new) { - print "Updated prompt format" if DEBUG; - $prompt_format = $new; - Irssi::abstracts_register(['uberprompt', $prompt_format]); - } -} - -sub uberprompt_draw { - my ($sb_item, $get_size_only) = @_; - - my $default_prompt = ''; - - my $window = Irssi::active_win; - - # hack to produce the same defaults as prompt/prompt_empty sbars. - - if (scalar( () = $window->items )) { - $default_prompt = '{uberprompt $[.15]itemname}'; - } else { - $default_prompt = '{uberprompt $winname}'; - } - - my $p_copy = $prompt_data; - - if (defined $prompt_data) { - # replace the special marker '$p' with the original prompt. - $p_copy =~ s/\$p/$default_prompt/; - } else { - $p_copy = $default_prompt; - } - print "Redrawing with: $p_copy, size-only: $get_size_only" if DEBUG; - - $prompt_item = $sb_item; - - my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); - - Irssi::signal_emit('prompt changed', $p_copy, $sb_item->{size}); - - return $ret; -} - -sub augment_redraw { - print "Redraw called" if DEBUG; - uberprompt_refresh(); - Irssi::timeout_add_once(10, \&refresh_visual_overlay, 0); -} - -sub uberprompt_refresh { - Irssi::statusbar_items_redraw('uberprompt'); -} - - -sub cmd_clear_visual { - _clear_visual_region(); - #refresh_visual_overlay(); - Irssi::statusbar_items_redraw('input'); -} - -sub cmd_toggle_visual { - - $region_active = not $region_active; - - if ($region_active) { - $region_start = _pos(); - $region_end = 0; # reset end marker. - print "visual mode started at $region_start" if DEBUG; - } else { - $region_end = _pos(); - print "Visual mode ended at $region_end" if DEBUG; - - if ($region_end > $region_start) { - my $input = Irssi::parse_special('$L', 0, 0); - my $str = substr($input, $region_start, $region_end - $region_start); - print "Region selected: $str" if DEBUG; - } else { - print "Invalid region selection: [ $region_start - $region_end ]" - if DEBUG; - $region_start = $region_end = 0; - } - cmd_clear_visual(); - } -} - -sub ctrl_l_intercept { - my $key = shift; - - if ($key == 12) { # C-l - print "C-l pressed" if DEBUG; - Irssi::command("redraw"); - Irssi::signal_stop(); - } elsif ($key == 10) { # RET - _clear_visual_region(); - } -} - -sub key_pressed { - # this handler needs to be last so the actual character is printed by irssi - # before we overlay on it. Otherwise things are all a bit off-by-1 - return unless $region_active; - - refresh_visual_overlay(); -} - -sub _clear_visual_region { - print "Clearing Region markers" if DEBUG; - $region_end = 0; - $region_start = 0; -} - - -sub refresh_visual_overlay { - - my $end_pos = $region_end; - $end_pos ||= _pos(); # if not set, take current position as end. - - my $len = $end_pos - $region_start; - return unless $len; # no point drawing an empty overlay - - my $input = Irssi::parse_special('$L'); - my $offset = $prompt_item->{size} + $region_start; - - my $text = substr($input, $region_start, $len); - - print "printing '$text' at $offset [$region_start, $end_pos] ($len)" if DEBUG; - - $text = '%8' . $text . '%8'; - _draw_overlay($offset, $text, $len); - -} - -sub _draw_overlay { - my ($offset, $text, $len) = @_; - Irssi::gui_printtext($offset, $term_h, $text); -} - -sub replace_prompt_items { - # remove existing ones. - print "Removing original prompt" if DEBUG; - - _sbar_command('prompt', 'remove', 'prompt'); - _sbar_command('prompt', 'remove', 'prompt_empty'); - - # add the new one. - - _sbar_command('prompt', 'add', 'uberprompt', - qw/-alignment left -before input -priority '-1'/); - - _sbar_command('prompt', 'position', '100'); -} - -sub restore_prompt_items { - - _sbar_command('prompt', 'remove', 'uberprompt'); - - print "Restoring original prompt" if DEBUG; - - _sbar_command('prompt', 'add', 'prompt', - qw/-alignment left -before input -priority '-1'/); - _sbar_command('prompt', 'add', 'prompt_empty', - qw/-alignment left -after prompt -priority '-1'/); - - _sbar_command('prompt', 'position', '100'); - -} - -sub _sbar_command { - my ($bar, $cmd, $item, @args) = @_; - - my $args_str = join ' ', @args; - - $args_str .= ' ' if length $args_str && defined $item; - - my $command = sprintf 'STATUSBAR %s %s %s%s', - $bar, $cmd, $args_str, defined($item)?$item:''; - - print "Running command: $command" if DEBUG; - Irssi::command($command); -} - -sub _pos { - return Irssi::gui_input_get_pos(); -} - - -# bit of fakery so things don't complain about the lack of prompt_info (hoepfully) - -%Irssi::Script::prompt_info:: = (); 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. diff --git a/prompt_info/visual.pl b/prompt_info/visual.pl deleted file mode 100644 index b29875b..0000000 --- a/prompt_info/visual.pl +++ /dev/null @@ -1,168 +0,0 @@ -use strict; -use warnings; - -use Irssi; -use Irssi::TextUI; # for sbar_items_redraw -use Data::Dumper; - - - -our $VERSION = "0.1"; -our %IRSSI = - ( - authors => "shabble", - contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', - name => "prompt_info", - description => "Helper script for dynamically adding text " - . "into the input-bar prompt.", - license => "Public Domain", - changed => "24/7/2010" - ); - -sub DEBUG () { 1 } -#sub DEBUG () { 0 } - -my $region_active = 0; - -my ($term_w, $term_h) = (0, 0); - -# visual region selected. -my ($region_start, $region_end) = (0, 0); -my $region_content = ''; - - -sub visual_subcmd_handler { - my ($data, $server, $item) = @_; - $data =~ s/\s+$//g; # strip trailing whitespace. - Irssi::command_runsub('visual', $data, $server, $item); -} - -sub init { - - # misc faff - Irssi::command_bind('visual', \&visual_subcmd_handler); - Irssi::command_bind('visual toggle', \&cmd_toggle_visual); - Irssi::command_bind('visual clear', \&cmd_clear_visual); - - Irssi::command("^BIND ^F /visual toggle"); - Irssi::command("^BIND ^G /visual clear"); - - Irssi::command_bind 'print_test', - sub { - Irssi::gui_printtext(0, 0, '%8hello there%n'); - }; - - # redraw interception - Irssi::signal_add_last('command redraw', \&augment_redraw); - Irssi::signal_add_first('gui key pressed', \&ctrl_l_intercept); - - # for updating the overlay. - Irssi::signal_add_last ('gui key pressed', \&key_pressed); - - # things to refresh the overlay for. - Irssi::signal_add('window changed', \&uberprompt_refresh); - Irssi::signal_add('window name changed', \&uberprompt_refresh); - Irssi::signal_add('window changed automatic', \&uberprompt_refresh); - Irssi::signal_add('window item changed', \&uberprompt_refresh); - - Irssi::signal_add('terminal resized', \&update_terminal_size); - - # so we know where the bottom line is - update_terminal_size(); - - -} -sub cmd_clear_visual { - _clear_visual_region(); - #refresh_visual_overlay(); - Irssi::statusbar_items_redraw('input'); -} - - -sub augment_redraw { - print "Redraw called" if DEBUG; - uberprompt_refresh(); - Irssi::timeout_add_once(10, \&refresh_visual_overlay, 0); -} - - -sub cmd_toggle_visual { - - $region_active = not $region_active; - - if ($region_active) { - $region_start = _pos(); - $region_end = 0; # reset end marker. - print "visual mode started at $region_start" if DEBUG; - } else { - $region_end = _pos(); - print "Visual mode ended at $region_end" if DEBUG; - - if ($region_end > $region_start) { - my $input = Irssi::parse_special('$L', 0, 0); - my $str = substr($input, $region_start, $region_end - $region_start); - print "Region selected: $str" if DEBUG; - } else { - print "Invalid region selection: [ $region_start - $region_end ]" - if DEBUG; - $region_start = $region_end = 0; - } - cmd_clear_visual(); - } -} - -sub ctrl_l_intercept { - my $key = shift; - - if ($key == 12) { # C-l - print "C-l pressed" if DEBUG; - Irssi::command("redraw"); - Irssi::signal_stop(); - } elsif ($key == 10) { # RET - _clear_visual_region(); - } -} - -sub key_pressed { - # this handler needs to be last so the actual character is printed by irssi - # before we overlay on it. Otherwise things are all a bit off-by-1 - return unless $region_active; - - refresh_visual_overlay(); -} - -sub _clear_visual_region { - print "Clearing Region markers" if DEBUG; - $region_end = 0; - $region_start = 0; -} - - -sub refresh_visual_overlay { - - my $end_pos = $region_end; - $end_pos ||= _pos(); # if not set, take current position as end. - - my $len = $end_pos - $region_start; - return unless $len; # no point drawing an empty overlay - - my $input = Irssi::parse_special('$L'); - my $offset = $prompt_item->{size} + $region_start; - - my $text = substr($input, $region_start, $len); - - print "printing '$text' at $offset [$region_start, $end_pos] ($len)" if DEBUG; - - $text = '%8' . $text . '%8'; - _draw_overlay($offset, $text, $len); - -} - -sub _draw_overlay { - my ($offset, $text, $len) = @_; - Irssi::gui_printtext($offset, $term_h, $text); -} - -sub _pos { - return Irssi::gui_input_get_pos(); -} -- cgit v1.2.3 From fdcab7762591fca9677ed74ada21267481e255e6 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 18 Apr 2011 16:33:59 +0100 Subject: moved older scripts out of prompt-info to ensure uberprompt readme is correctly generated (2) --- prompt_info/old/input_overlay.pl | 288 +++++++++++++++++++++++++++++++ prompt_info/old/overlays.pl | 198 ++++++++++++++++++++++ prompt_info/old/prompt_info.pl | 114 +++++++++++++ prompt_info/old/prompt_replace.pl | 346 ++++++++++++++++++++++++++++++++++++++ prompt_info/old/visual.pl | 168 ++++++++++++++++++ 5 files changed, 1114 insertions(+) create mode 100644 prompt_info/old/input_overlay.pl create mode 100644 prompt_info/old/overlays.pl create mode 100644 prompt_info/old/prompt_info.pl create mode 100644 prompt_info/old/prompt_replace.pl create mode 100644 prompt_info/old/visual.pl (limited to 'prompt_info') diff --git a/prompt_info/old/input_overlay.pl b/prompt_info/old/input_overlay.pl new file mode 100644 index 0000000..9d2a42b --- /dev/null +++ b/prompt_info/old/input_overlay.pl @@ -0,0 +1,288 @@ + +use strict; +use warnings; + +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw +use Data::Dumper; + + +# TODO: maybe eval { use Term::Size } and use tthat if poss. +our $VERSION = "0.2"; +our %IRSSI = + ( + authors => "shabble", + contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', + name => "overlays", + description => "Library script for drawing overlays on irssi UI", + license => "MIT", + changed => "24/7/2010" + ); + +# overlay := { $num1 => line1, $num2 => line2 } +# line := [ region, region, region ] +# region := { start => x, end => y, ...? } + +my @regions; + +my ($term_w, $term_h) = (0, 0); + +my $overlay_active = 0; +my $prompt_len = 5; +my $region_id = 0; + +sub DEBUG () { 1 } + +sub update_terminal_size { + + my @stty_data = qx/stty -a/; + my $line = $stty_data[0]; + + # linux + # speed 38400 baud; rows 36; columns 126; line = 0; + if ($line =~ m/rows (\d+); columns (\d+);/) { + $term_h = $1; + $term_w = $2; + # osx + # speed 9600 baud; 40 rows; 235 columns; + } elsif ($line =~ m/(\d+) rows; (\d+) columns;/) { + $term_h = $1; + $term_w = $2; + } else { + # guess? + $term_h = 24; + $term_w = 80; + } + + print "Terminal detected as $term_w cols by $term_h rows" if DEBUG; +} + +sub find_region { + my ($pos) = @_; + foreach my $region (@regions) { + next unless $pos > $region->{start}; + return $region if $pos <= $region->{end}; + } + print "failed to find region for pos: $pos"; + return undef; +} + +sub redraw_overlay { + # TODO: we can't assume the active win is the only one with overlays. + #Irssi::active_win->view->redraw(); + foreach my $region (@regions) { + if ($region->{draw}) { + my $str = $region->{style} . $region->{text} . '%n'; + my $x_offset = $region->{start} + $prompt_len; + + Irssi::gui_printtext($x_offset, $term_h, $str); + } + } + # my $inp = Irssi::parse_special('$L'); + # Irssi::gui_input_set($inp . ''); +} + +sub augment_redraw { + #print "Redraw called" if DEBUG; + #redraw_overlay(); + Irssi::timeout_add_once(20, \&redraw_overlay, 0); +} + +sub intercept_keypress { + my $key = shift; + + # intercept C-l for redraw, and force it to call + # /redraw instead of the internal function. + if ($key == 12) { # C-L + print "C-l pressed" if DEBUG; + Irssi::command("redraw"); + Irssi::signal_stop; + } + +} + +sub observe_keypress { + my $key = shift; + print "Key " . chr ($key) . " pressed, pos: " . _pos(); + if ($key > 31 && $key <= 127) { + # see if we're still appending to the last region: + #print "Observed printable key: " . chr($key) if DEBUG; + #print ''; + my $latest_region = $regions[-1]; + $latest_region = {} unless defined $latest_region; + + + my $pos = _pos(); + my $reg = find_region($pos); + + if (defined $reg) { + insert_into_region($key, $reg); + } elsif (not $latest_region->{open}) { + my $style = $overlay_active?'%_':''; + new_region($style, $key); + } else { + insert_into_region($key, $latest_region); + } + #Irssi::signal_stop; + # TODO: if the cursor pos is inside a region, handle it + # extend the region on addition? + redraw_overlay(); + } +} + +sub init { + + die "This script requires uberprompt.pl" + unless script_is_loaded('uberprompt'); + + Irssi::signal_add_last ('command redraw', \&augment_redraw); + Irssi::signal_add_first('gui key pressed', \&intercept_keypress); + Irssi::signal_add_last ('gui key pressed', \&observe_keypress); + + Irssi::signal_add ('terminal resized', \&update_terminal_size); + Irssi::signal_add_first('gui print text finished', \&augment_redraw); + + setup_bindings(); + + Irssi::signal_add('prompt changed', sub { + print "Updated prompt length: $_[1]"; + $prompt_len = $_[1]; + }); + + Irssi::signal_emit('prompt length request'); + + update_terminal_size(); +} + +sub setup_bindings { + + Irssi::command_bind('region_start', \®ion_toggle); + Irssi::command_bind('region_clear', \®ion_clear); + Irssi::command_bind('region_print', \&print_regions); + + + Irssi::command('/bind ^C /region_start'); + ##Irssi::command('/bind ^D /region_clear'); + Irssi::command('/bind ^D /region_print'); + +} + + +################################################################################ + +sub escape_style { + my ($style) = @_; + $style =~ s/%/%%/g; + + return $style; +} + +sub print_regions { + foreach my $reg (@regions) { + printf("start: %d end: %d style: %s, text: \"%s\", open: %d, draw: %d", + $reg->{start}, $reg->{end}, escape_style($reg->{style}), + $reg->{text}, $reg->{open}, $reg->{draw}); + } +} + +sub new_region { + my ($style, $key) = @_; + + my $new_id = $region_id++; + _debug("Creating new Region: $new_id"); + + my $new_region + = { + id => $region_id++, + text => '', + start => _pos(), + end => _pos(), + style => $style, + open => 1, + draw => 1, + }; + + insert_into_region($key, $new_region); + + push @regions, $new_region; +} + +sub delete_region { + my ($region) = @_; + my $idx = 0; + foreach my $i (0..$#regions) { + if ($regions[$i]->{id} == $region->{id}) { + $idx = $i; + last; + } + } + print "Deleting region: $idx"; + splice(@regions, $idx, 1); # remove the selected region. +} + +sub insert_into_region { + my ($key, $region) = @_; + + my $pos = _pos(); + + if ($key == 127) { # backspace + substr($region->{text}, -1, 1) = ''; + $region->{end}--; + if ($region->{end} <= $region->{start}) { + delete_region($region); + } + } else { + printf("text: '%s', pos: %d, offset: %d", + $region->{text}, $pos, $pos - $region->{start}); + if ( $region->{end} < $pos) { + $region->{text} .= chr $key; + } else { + substr($region->{text}, $pos - $region->{start}, 0) = chr $key; + } + $region->{end}++; + } +} + +sub region_clear { + @regions = (); + Irssi::signal_emit('command redraw'); +} + +sub region_toggle { + $overlay_active = not $overlay_active; + _debug("Region is %sactive", $overlay_active?'':'in'); + #@regions = (); + # terminate the previous region + + my $region = find_region(_pos()); + if (defined $region) { + $region->{open} = 0; + $region->{end} = _pos(); + debug("Region closed: %d-%d", $region->{start}, $region->{end}); + } +} + +sub script_is_loaded { + my $name = shift; + _debug("Checking if $name is loaded"); + no strict 'refs'; + my $retval = %{ "Irssi::Script::${name}::" }; + use strict 'refs'; + + return $retval; +} + +sub _pos { + return Irssi::gui_input_get_pos(); +} + +sub _input { + return Irssi::parse_special('$L'); +} + +sub _debug { + printf @_ if DEBUG(); +} + +init(); + diff --git a/prompt_info/old/overlays.pl b/prompt_info/old/overlays.pl new file mode 100644 index 0000000..b3299e9 --- /dev/null +++ b/prompt_info/old/overlays.pl @@ -0,0 +1,198 @@ +# temp place for dumping all the stuff that doesn't belong in uberprompt. + +use strict; +use warnings; + +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw +use Data::Dumper; + + +# TODO: maybe eval { use Term::Size } and use tthat if poss. +our $VERSION = "0.2"; +our %IRSSI = + ( + authors => "shabble", + contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', + name => "overlays", + description => "Library script for drawing overlays on irssi UI", + license => "MIT", + changed => "24/7/2010" + ); + +# overlay := { $num1 => line1, $num2 => line2 } +# line := [ region, region, region ] +# region := { start => x, end => y, ...? } + +my $overlays; +my ($term_w, $term_h) = (0, 0); + +sub DEBUG () { 1 } + +sub update_terminal_size { + + my @stty_data = qx/stty -a/; + my $line = $stty_data[0]; + + # linux + # speed 38400 baud; rows 36; columns 126; line = 0; + if ($line =~ m/rows (\d+); columns (\d+);/) { + $term_h = $1; + $term_w = $2; + # osx + # speed 9600 baud; 40 rows; 235 columns; + } elsif ($line =~ m/(\d+) rows; (\d+) columns;/) { + $term_h = $1; + $term_w = $2; + } else { + # guess? + $term_h = 24; + $term_w = 80; + } + + print "Terminal detected as $term_w cols by $term_h rows" if DEBUG; +} + +sub _add_overlay_region { + my ($x, $y, $text) = @_; + my $region = { start => $x, + text => $text, + }; + + my $o_line = $overlays->{$y}; + + unless (defined $o_line) { + $o_line = []; + $overlays->{$y} = $o_line; + } + + # foreach my $cur_region (@$o_line) { + # if (_region_overlaps($cur_region, $region)) { + # # do something. + # print "Region overlaps"; + # last; + # } + # } + + push @$o_line, $region; + redraw_overlay(); +} + +# sub _remove_overlay_region { +# my ($line, $start, $end) = @_; + +# my $o_line = $overlay->{$line}; +# return unless $o_line; + +# my $i = 0; +# foreach my $region (@$o_line) { +# if ($region->{start} == $start && $region->{end} == $end) { +# last; +# } +# $i++; +# } +# splice @$o_line, $i, 1, (); # remove it. +# } + +sub redraw_overlay { + # TODO: we can't assume the active win is the only one with overlays. + Irssi::active_win->view->redraw(); + foreach my $y (sort keys %$overlays) { + my $line = $overlays->{$y}; + foreach my $region (@$line) { + Irssi::gui_printtext($region->{start}, $y, $region->{text}); + } + } +} + +sub augment_redraw { + #print "Redraw called" if DEBUG; + #redraw_overlay(); + Irssi::timeout_add_once(10, \&redraw_overlay, 0); +} + +sub ctrl_L_intercept { + my $key = shift; + + if ($key == 12) { # C-L + print "C-l pressed" if DEBUG; + Irssi::command("redraw"); + Irssi::signal_stop(); + } +} + +sub init { + + die "needs uberprompt" unless script_is_loaded('uberprompt'); + + Irssi::signal_add_last ('command redraw', \&augment_redraw); + Irssi::signal_add_first('gui key pressed', \&ctrl_L_intercept); + Irssi::signal_add ('terminal resized', \&update_terminal_size); + Irssi::signal_add_first('gui print text finished', \&augment_redraw); + + my $api_sigs = { + # input signals + 'overlay create' => [qw/int int string/], # x, y, str + 'overlay remove' => [qw/int int/], # x, y + 'overlay clear' => [], # no args + # output signals + + }; + + Irssi::signal_register($api_sigs); + + Irssi::signal_add('overlay create', \&_add_overlay_region); + # Irssi::signal_add('overlay remove', \&_add_overlay_region); + Irssi::signal_add('overlay clear', \&_clear_overlay); + + Irssi::command_bind('ocr', \&cmd_overlay_create); + Irssi::command_bind('ocl', sub { Irssi::signal_emit('overlay clear'); }); + +} + +sub cmd_overlay_create { + my ($args) = @_; + my ($y, $x, $text) = split(/\s+/, $args, 3); + print "overlaying $text at [$x, $y]"; + + Irssi::signal_emit('overlay create', $x, $y, $text); +} + +sub _clear_overlay { + $overlays = {}; + redraw_overlay(); +} + +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; +} +print "Moo!"; +init(); + +__END__ + +# sub _draw_overlay_menu { + +# my $w = 10; + +# my @lines = ( +# '%7+' . ('-' x $w) . '+%n', +# sprintf('%%7|%%n%*s%%7|%%n', $w, 'bacon'), +# sprintf('|%*s|', $w, 'bacon'), +# sprintf('|%*s|', $w, 'bacon'), +# sprintf('|%*s|', $w, 'bacon'), +# sprintf('|%*s|', $w, 'bacon'), +# sprintf('|%*s|', $w, 'bacon'), +# '%7+' . ('-' x $w) . '+%n', +# ); +# my $i = 10; # start vert offset. +# for my $line (@lines) { +# Irssi::gui_printtext(int ($term_w / 2), $i++, $line); +# } +# } diff --git a/prompt_info/old/prompt_info.pl b/prompt_info/old/prompt_info.pl new file mode 100644 index 0000000..8ad63ba --- /dev/null +++ b/prompt_info/old/prompt_info.pl @@ -0,0 +1,114 @@ +# Usage: + +# edit your theme, find the line beginning: +# +# prompt = "..." +# +# and add the string `$prompt_additional' somewhere inside it. +# If using the default: prompt = "[$*] ", then a good value would be: +# +# prompt = "[$*$prompt_additional] " +# +# Then place this script to your ~/.irssi/scripts directory (~/.irssi/scripts/) +# and symlink it to the ~/.irssi/scripts/autorun directory (which may need to +# be created first) +# +# You can also load it manually once the theme has been edited via +# +# /script load prompt_info.pl +# +# You will also need to reload your theme with the following command: +# +# /script exec Irssi::themes_reload() +# +# Once loaded, you can modify your prompt content by using the following command: +# +# /set_prompt +# +# You can also use it from other scripts by issuing a signal as follows: +# +# Irssi:signal_emit('change prompt', +# +# report bugs / feature requests to http://github.com/shabble/irssi-scripts/issues +# +# NOTE: it does not appear to be possible to use colours in your prompt at present. +# This is unlikely to change without source-code changes to Irssi itself. + +use strict; +use warnings; + +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw + +use vars qw($VERSION %IRSSI); +$VERSION = "1.0.1"; +%IRSSI = + ( + authors => "shabble", + contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', + name => "prompt_info", + description => "Helper script for dynamically adding text " + . "into the input-bar prompt.", + license => "Public Domain", + changed => "24/7/2010" + ); + +#sub DEBUG () { 1 } +sub DEBUG () { 0 } + + +my $prompt_additional_content = ''; + +Irssi::expando_create('prompt_additional', \&expando_prompt, {}); + +sub expando_prompt { + my ($server, $witem, $arg) = @_; + return $prompt_additional_content; + #return Irssi::current_theme->format_expand("{sb + #$prompt_additional_content}", 0x0f); +} + +sub redraw_prompts { + Irssi::statusbar_items_redraw ('prompt'); + Irssi::statusbar_items_redraw ('prompt_empty'); +} + +sub handle_change_prompt_sig { + my ($text) = @_; + + 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; + + if ($changed) { + print "Redrawing prompts" if DEBUG; + redraw_prompts(); + } +} + +sub prompt_additional_cmd { + my ($str) = @_; + print "Setting prompt to: $str" if DEBUG; + Irssi::signal_emit('change prompt', $str); +} + +test_abstract_setup(); +Irssi::signal_register({'change prompt' => [qw/string/]}); +Irssi::signal_add('change prompt' => \&handle_change_prompt_sig); + +Irssi::command_bind('set_prompt' => \&prompt_additional_cmd); + +sub test_abstract_setup { + my $theme = Irssi::current_theme(); + my $prompt = $theme->format_expand('{prompt}', 0); + if ($prompt !~ m/\$prompt_additional/) { + print "Prompt_Info: It looks like you haven't modified your theme" + . " to include the \$prompt_additional expando. You will not see" + . " any prompt info messages until you do. See script comments" + . "for details"; + } +} diff --git a/prompt_info/old/prompt_replace.pl b/prompt_info/old/prompt_replace.pl new file mode 100644 index 0000000..30120f7 --- /dev/null +++ b/prompt_info/old/prompt_replace.pl @@ -0,0 +1,346 @@ +use strict; +use warnings; + +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw +use Data::Dumper; + + + +our $VERSION = "0.1"; +our %IRSSI = + ( + authors => "shabble", + contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', + name => "prompt_info", + description => "Helper script for dynamically adding text " + . "into the input-bar prompt.", + license => "Public Domain", + changed => "24/7/2010" + ); + +sub DEBUG () { 1 } +#sub DEBUG () { 0 } + +my $prompt_data = undef; +my $prompt_item = undef; + +my $region_active = 0; + +my ($term_w, $term_h) = (0, 0); + +# visual region selected. +my ($region_start, $region_end) = (0, 0); +my $region_content = ''; + +my $prompt_format = ''; + +init(); + +sub update_terminal_size { + + my @stty_data = qx/stty -a/; + my $line = $stty_data[0]; + + # linux + # speed 38400 baud; rows 36; columns 126; line = 0; + if ($line =~ m/rows (\d+); columns (\d+);/) { + $term_h = $1; + $term_w = $2; + # osx + # speed 9600 baud; 40 rows; 235 columns; + } elsif ($line =~ m/(\d+) rows; (\d+) columns;/) { + $term_h = $1; + $term_w = $2; + } else { + # guess? + $term_h = 24; + $term_w = 80; + } + + print "Terminal detected as $term_w cols by $term_h rows" if DEBUG; +} + +sub prompt_subcmd_handler { + my ($data, $server, $item) = @_; + $data =~ s/\s+$//g; # strip trailing whitespace. + Irssi::command_runsub('prompt', $data, $server, $item); +} + +sub visual_subcmd_handler { + my ($data, $server, $item) = @_; + $data =~ s/\s+$//g; # strip trailing whitespace. + Irssi::command_runsub('visual', $data, $server, $item); +} + +sub init { + + Irssi::statusbar_item_register ('uberprompt', 0, 'uberprompt_draw'); + + Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*] '); + + 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 { Irssi::signal_emit 'change prompt', shift; }); + Irssi::command_bind('prompt clear', + sub { Irssi::signal_emit 'change prompt', '$p'; }); + + # misc faff + Irssi::command_bind('visual', \&visual_subcmd_handler); + Irssi::command_bind('visual toggle', \&cmd_toggle_visual); + Irssi::command_bind('visual clear', \&cmd_clear_visual); + + Irssi::command("^BIND ^F /visual toggle"); + Irssi::command("^BIND ^G /visual clear"); + + Irssi::command_bind 'print_test', + sub { + Irssi::gui_printtext(0, 0, '%8hello there%n'); + }; + + # redraw interception + Irssi::signal_add_last('command redraw', \&augment_redraw); + Irssi::signal_add_first('gui key pressed', \&ctrl_l_intercept); + + # for updating the overlay. + Irssi::signal_add_last ('gui key pressed', \&key_pressed); + + # things to refresh the overlay for. + Irssi::signal_add('window changed', \&uberprompt_refresh); + Irssi::signal_add('window name changed', \&uberprompt_refresh); + Irssi::signal_add('window changed automatic', \&uberprompt_refresh); + Irssi::signal_add('window item changed', \&uberprompt_refresh); + + Irssi::signal_add('terminal resized', \&update_terminal_size); + Irssi::signal_add('setup changed', \&reload_settings); + + # so we know where the bottom line is + update_terminal_size(); + + # intialise the prompt format. + reload_settings(); + + # install our statusbars. + replace_prompt_items(); + + # the actual API signals. + Irssi::signal_register({'change prompt' => [qw/string/]}); + Irssi::signal_add('change prompt' => \&change_prompt_sig); + + Irssi::signal_register({'prompt changed' => [qw/string int/]}); +} + +sub change_prompt_sig { + my ($text) = @_; + + $text = '$p' . $text; + print "Got prompt change sig with: $text" if DEBUG; + + my $changed; + $changed = defined $prompt_data ? $prompt_data ne $text : 1; + + $prompt_data = $text; + + if ($changed) { + print "Redrawing prompt" if DEBUG; + uberprompt_refresh(); + } +} + + +sub UNLOAD { + # remove uberprompt and return the original ones. + restore_prompt_items(); +} + +sub reload_settings { + my $new = Irssi::settings_get_str('uberprompt_format'); + if ($prompt_format ne $new) { + print "Updated prompt format" if DEBUG; + $prompt_format = $new; + Irssi::abstracts_register(['uberprompt', $prompt_format]); + } +} + +sub uberprompt_draw { + my ($sb_item, $get_size_only) = @_; + + my $default_prompt = ''; + + my $window = Irssi::active_win; + + # hack to produce the same defaults as prompt/prompt_empty sbars. + + if (scalar( () = $window->items )) { + $default_prompt = '{uberprompt $[.15]itemname}'; + } else { + $default_prompt = '{uberprompt $winname}'; + } + + my $p_copy = $prompt_data; + + if (defined $prompt_data) { + # replace the special marker '$p' with the original prompt. + $p_copy =~ s/\$p/$default_prompt/; + } else { + $p_copy = $default_prompt; + } + print "Redrawing with: $p_copy, size-only: $get_size_only" if DEBUG; + + $prompt_item = $sb_item; + + my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); + + Irssi::signal_emit('prompt changed', $p_copy, $sb_item->{size}); + + return $ret; +} + +sub augment_redraw { + print "Redraw called" if DEBUG; + uberprompt_refresh(); + Irssi::timeout_add_once(10, \&refresh_visual_overlay, 0); +} + +sub uberprompt_refresh { + Irssi::statusbar_items_redraw('uberprompt'); +} + + +sub cmd_clear_visual { + _clear_visual_region(); + #refresh_visual_overlay(); + Irssi::statusbar_items_redraw('input'); +} + +sub cmd_toggle_visual { + + $region_active = not $region_active; + + if ($region_active) { + $region_start = _pos(); + $region_end = 0; # reset end marker. + print "visual mode started at $region_start" if DEBUG; + } else { + $region_end = _pos(); + print "Visual mode ended at $region_end" if DEBUG; + + if ($region_end > $region_start) { + my $input = Irssi::parse_special('$L', 0, 0); + my $str = substr($input, $region_start, $region_end - $region_start); + print "Region selected: $str" if DEBUG; + } else { + print "Invalid region selection: [ $region_start - $region_end ]" + if DEBUG; + $region_start = $region_end = 0; + } + cmd_clear_visual(); + } +} + +sub ctrl_l_intercept { + my $key = shift; + + if ($key == 12) { # C-l + print "C-l pressed" if DEBUG; + Irssi::command("redraw"); + Irssi::signal_stop(); + } elsif ($key == 10) { # RET + _clear_visual_region(); + } +} + +sub key_pressed { + # this handler needs to be last so the actual character is printed by irssi + # before we overlay on it. Otherwise things are all a bit off-by-1 + return unless $region_active; + + refresh_visual_overlay(); +} + +sub _clear_visual_region { + print "Clearing Region markers" if DEBUG; + $region_end = 0; + $region_start = 0; +} + + +sub refresh_visual_overlay { + + my $end_pos = $region_end; + $end_pos ||= _pos(); # if not set, take current position as end. + + my $len = $end_pos - $region_start; + return unless $len; # no point drawing an empty overlay + + my $input = Irssi::parse_special('$L'); + my $offset = $prompt_item->{size} + $region_start; + + my $text = substr($input, $region_start, $len); + + print "printing '$text' at $offset [$region_start, $end_pos] ($len)" if DEBUG; + + $text = '%8' . $text . '%8'; + _draw_overlay($offset, $text, $len); + +} + +sub _draw_overlay { + my ($offset, $text, $len) = @_; + Irssi::gui_printtext($offset, $term_h, $text); +} + +sub replace_prompt_items { + # remove existing ones. + print "Removing original prompt" if DEBUG; + + _sbar_command('prompt', 'remove', 'prompt'); + _sbar_command('prompt', 'remove', 'prompt_empty'); + + # add the new one. + + _sbar_command('prompt', 'add', 'uberprompt', + qw/-alignment left -before input -priority '-1'/); + + _sbar_command('prompt', 'position', '100'); +} + +sub restore_prompt_items { + + _sbar_command('prompt', 'remove', 'uberprompt'); + + print "Restoring original prompt" if DEBUG; + + _sbar_command('prompt', 'add', 'prompt', + qw/-alignment left -before input -priority '-1'/); + _sbar_command('prompt', 'add', 'prompt_empty', + qw/-alignment left -after prompt -priority '-1'/); + + _sbar_command('prompt', 'position', '100'); + +} + +sub _sbar_command { + my ($bar, $cmd, $item, @args) = @_; + + my $args_str = join ' ', @args; + + $args_str .= ' ' if length $args_str && defined $item; + + my $command = sprintf 'STATUSBAR %s %s %s%s', + $bar, $cmd, $args_str, defined($item)?$item:''; + + print "Running command: $command" if DEBUG; + Irssi::command($command); +} + +sub _pos { + return Irssi::gui_input_get_pos(); +} + + +# bit of fakery so things don't complain about the lack of prompt_info (hoepfully) + +%Irssi::Script::prompt_info:: = (); diff --git a/prompt_info/old/visual.pl b/prompt_info/old/visual.pl new file mode 100644 index 0000000..b29875b --- /dev/null +++ b/prompt_info/old/visual.pl @@ -0,0 +1,168 @@ +use strict; +use warnings; + +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw +use Data::Dumper; + + + +our $VERSION = "0.1"; +our %IRSSI = + ( + authors => "shabble", + contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', + name => "prompt_info", + description => "Helper script for dynamically adding text " + . "into the input-bar prompt.", + license => "Public Domain", + changed => "24/7/2010" + ); + +sub DEBUG () { 1 } +#sub DEBUG () { 0 } + +my $region_active = 0; + +my ($term_w, $term_h) = (0, 0); + +# visual region selected. +my ($region_start, $region_end) = (0, 0); +my $region_content = ''; + + +sub visual_subcmd_handler { + my ($data, $server, $item) = @_; + $data =~ s/\s+$//g; # strip trailing whitespace. + Irssi::command_runsub('visual', $data, $server, $item); +} + +sub init { + + # misc faff + Irssi::command_bind('visual', \&visual_subcmd_handler); + Irssi::command_bind('visual toggle', \&cmd_toggle_visual); + Irssi::command_bind('visual clear', \&cmd_clear_visual); + + Irssi::command("^BIND ^F /visual toggle"); + Irssi::command("^BIND ^G /visual clear"); + + Irssi::command_bind 'print_test', + sub { + Irssi::gui_printtext(0, 0, '%8hello there%n'); + }; + + # redraw interception + Irssi::signal_add_last('command redraw', \&augment_redraw); + Irssi::signal_add_first('gui key pressed', \&ctrl_l_intercept); + + # for updating the overlay. + Irssi::signal_add_last ('gui key pressed', \&key_pressed); + + # things to refresh the overlay for. + Irssi::signal_add('window changed', \&uberprompt_refresh); + Irssi::signal_add('window name changed', \&uberprompt_refresh); + Irssi::signal_add('window changed automatic', \&uberprompt_refresh); + Irssi::signal_add('window item changed', \&uberprompt_refresh); + + Irssi::signal_add('terminal resized', \&update_terminal_size); + + # so we know where the bottom line is + update_terminal_size(); + + +} +sub cmd_clear_visual { + _clear_visual_region(); + #refresh_visual_overlay(); + Irssi::statusbar_items_redraw('input'); +} + + +sub augment_redraw { + print "Redraw called" if DEBUG; + uberprompt_refresh(); + Irssi::timeout_add_once(10, \&refresh_visual_overlay, 0); +} + + +sub cmd_toggle_visual { + + $region_active = not $region_active; + + if ($region_active) { + $region_start = _pos(); + $region_end = 0; # reset end marker. + print "visual mode started at $region_start" if DEBUG; + } else { + $region_end = _pos(); + print "Visual mode ended at $region_end" if DEBUG; + + if ($region_end > $region_start) { + my $input = Irssi::parse_special('$L', 0, 0); + my $str = substr($input, $region_start, $region_end - $region_start); + print "Region selected: $str" if DEBUG; + } else { + print "Invalid region selection: [ $region_start - $region_end ]" + if DEBUG; + $region_start = $region_end = 0; + } + cmd_clear_visual(); + } +} + +sub ctrl_l_intercept { + my $key = shift; + + if ($key == 12) { # C-l + print "C-l pressed" if DEBUG; + Irssi::command("redraw"); + Irssi::signal_stop(); + } elsif ($key == 10) { # RET + _clear_visual_region(); + } +} + +sub key_pressed { + # this handler needs to be last so the actual character is printed by irssi + # before we overlay on it. Otherwise things are all a bit off-by-1 + return unless $region_active; + + refresh_visual_overlay(); +} + +sub _clear_visual_region { + print "Clearing Region markers" if DEBUG; + $region_end = 0; + $region_start = 0; +} + + +sub refresh_visual_overlay { + + my $end_pos = $region_end; + $end_pos ||= _pos(); # if not set, take current position as end. + + my $len = $end_pos - $region_start; + return unless $len; # no point drawing an empty overlay + + my $input = Irssi::parse_special('$L'); + my $offset = $prompt_item->{size} + $region_start; + + my $text = substr($input, $region_start, $len); + + print "printing '$text' at $offset [$region_start, $end_pos] ($len)" if DEBUG; + + $text = '%8' . $text . '%8'; + _draw_overlay($offset, $text, $len); + +} + +sub _draw_overlay { + my ($offset, $text, $len) = @_; + Irssi::gui_printtext($offset, $term_h, $text); +} + +sub _pos { + return Irssi::gui_input_get_pos(); +} -- cgit v1.2.3 From d924883845fd6e2d1e0a9f63e91884b894eab6a8 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 18 Apr 2011 16:34:34 +0100 Subject: uberprompt: updated readme --- prompt_info/README.pod | 214 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) (limited to 'prompt_info') diff --git a/prompt_info/README.pod b/prompt_info/README.pod index 84b929b..547def6 100644 --- a/prompt_info/README.pod +++ b/prompt_info/README.pod @@ -217,5 +217,219 @@ irssi to crash. See bug report at http://bugs.irssi.org/index.php?do=details&tas +=cut + +=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: + +=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 + +Clears the additional data provided to the prompt. + +=item * C + +Eenables the uberprompt (things may get confused if this is used +whilst the prompt is already enabled) + +=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: + +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 C +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 -- 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/README.pod | 226 +--------------------------------------------- prompt_info/uberprompt.pl | 5 + 2 files changed, 10 insertions(+), 221 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/README.pod b/prompt_info/README.pod index 547def6..882553d 100644 --- a/prompt_info/README.pod +++ b/prompt_info/README.pod @@ -1,224 +1,3 @@ - - -=cut - - - -=cut - - - -=cut - - - -=cut - -=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 - - - -=cut - =pod =head1 NAME @@ -318,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 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') 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') 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/README.pod | 56 ++++++++++++++++++++++++++++++++++++++++++++++- prompt_info/uberprompt.pl | 56 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 110 insertions(+), 2 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/README.pod b/prompt_info/README.pod index 882553d..d8e3b3e 100644 --- a/prompt_info/README.pod +++ b/prompt_info/README.pod @@ -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 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