From 90352618f680723a1a6a6cf59aec93917d64dbb1 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 16:39:29 +0100 Subject: factored all the visual stuff out of prompt_replace into its own file. --- prompt_info/prompt_replace.pl | 171 +++------------------------------------ prompt_info/visual.pl | 184 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+), 159 deletions(-) create mode 100644 prompt_info/visual.pl (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 20fb7b1..c9bfcc8 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -25,41 +25,10 @@ sub DEBUG () { 1 } 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) = @_; @@ -67,57 +36,21 @@ sub prompt_subcmd_handler { 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::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", \&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(); + Irssi::signal_add('setup changed', \&reload_settings); # intialise the prompt format. reload_settings(); @@ -128,13 +61,12 @@ sub init { # the actual API signal. Irssi::signal_register({'change prompt' => [qw/string/]}); Irssi::signal_add('change prompt' => \&change_prompt_sig); - - } sub change_prompt_sig { my ($text) = @_; + # TODO: mroe intelligence about where to insert $p? $text = '$p' . $text; print "Got prompt change sig with: $text" if DEBUG; @@ -149,9 +81,9 @@ sub change_prompt_sig { } } - sub UNLOAD { # remove uberprompt and return the original ones. + print "Removing uberprompt and restoring original"; restore_prompt_items(); } @@ -187,19 +119,19 @@ sub uberprompt_draw { } else { $p_copy = $default_prompt; } + $p_copy =~ s/\$/\$\$/g; # escape all $ symbols + $p_copy =~ s/\\/\\\\/g; # escape backslashes. + print "Redrawing with: $p_copy, size-only: $get_size_only" if DEBUG; $prompt_item = $sb_item; - $sb_item->default_handler($get_size_only, $p_copy, '', 0); -} + my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); -sub augment_redraw { - print "Redraw called" if DEBUG; - uberprompt_refresh(); - Irssi::timeout_add_once(10, \&refresh_visual_overlay, 0); + return $ret; } + sub uberprompt_refresh { Irssi::statusbar_items_redraw('uberprompt'); } @@ -211,82 +143,6 @@ sub cmd_clear_visual { 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. @@ -332,9 +188,6 @@ sub _sbar_command { 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) diff --git a/prompt_info/visual.pl b/prompt_info/visual.pl new file mode 100644 index 0000000..5941fe0 --- /dev/null +++ b/prompt_info/visual.pl @@ -0,0 +1,184 @@ +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 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 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 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 7dd9bb7fe62e4ec10a80bd8df7942ee33e203e87 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 16:40:44 +0100 Subject: renamed prompt_replace to uberprompt --- prompt_info/prompt_replace.pl | 195 ------------------------------------------ prompt_info/uberprompt.pl | 195 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+), 195 deletions(-) delete mode 100644 prompt_info/prompt_replace.pl create mode 100644 prompt_info/uberprompt.pl (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl deleted file mode 100644 index c9bfcc8..0000000 --- a/prompt_info/prompt_replace.pl +++ /dev/null @@ -1,195 +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 $prompt_format = ''; - -init(); - - -sub prompt_subcmd_handler { - my ($data, $server, $item) = @_; - $data =~ s/\s+$//g; # strip trailing whitespace. - Irssi::command_runsub('prompt', $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'; }); - - Irssi::signal_add('setup changed', \&reload_settings); - - # intialise the prompt format. - reload_settings(); - - # install our statusbars. - replace_prompt_items(); - - # the actual API signal. - Irssi::signal_register({'change prompt' => [qw/string/]}); - Irssi::signal_add('change prompt' => \&change_prompt_sig); -} - -sub change_prompt_sig { - my ($text) = @_; - - # TODO: mroe intelligence about where to insert $p? - $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. - print "Removing uberprompt and restoring original"; - 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; - } - $p_copy =~ s/\$/\$\$/g; # escape all $ symbols - $p_copy =~ s/\\/\\\\/g; # escape backslashes. - - 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); - - return $ret; -} - - -sub uberprompt_refresh { - Irssi::statusbar_items_redraw('uberprompt'); -} - - -sub cmd_clear_visual { - _clear_visual_region(); - #refresh_visual_overlay(); - Irssi::statusbar_items_redraw('input'); -} - - -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); -} - - - -# 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 new file mode 100644 index 0000000..c9bfcc8 --- /dev/null +++ b/prompt_info/uberprompt.pl @@ -0,0 +1,195 @@ +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 $prompt_format = ''; + +init(); + + +sub prompt_subcmd_handler { + my ($data, $server, $item) = @_; + $data =~ s/\s+$//g; # strip trailing whitespace. + Irssi::command_runsub('prompt', $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'; }); + + Irssi::signal_add('setup changed', \&reload_settings); + + # intialise the prompt format. + reload_settings(); + + # install our statusbars. + replace_prompt_items(); + + # the actual API signal. + Irssi::signal_register({'change prompt' => [qw/string/]}); + Irssi::signal_add('change prompt' => \&change_prompt_sig); +} + +sub change_prompt_sig { + my ($text) = @_; + + # TODO: mroe intelligence about where to insert $p? + $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. + print "Removing uberprompt and restoring original"; + 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; + } + $p_copy =~ s/\$/\$\$/g; # escape all $ symbols + $p_copy =~ s/\\/\\\\/g; # escape backslashes. + + 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); + + return $ret; +} + + +sub uberprompt_refresh { + Irssi::statusbar_items_redraw('uberprompt'); +} + + +sub cmd_clear_visual { + _clear_visual_region(); + #refresh_visual_overlay(); + Irssi::statusbar_items_redraw('input'); +} + + +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); +} + + + +# bit of fakery so things don't complain about the lack of prompt_info (hoepfully) + +%Irssi::Script::prompt_info:: = (); -- cgit v1.2.3 From b39c8d2a1472f75ffeb0dd3215f65a6930373ab8 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 16:49:50 +0100 Subject: actually properly fixed the escaping of stuff now. --- prompt_info/uberprompt.pl | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index c9bfcc8..0a2dc6a 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -61,6 +61,11 @@ sub init { # the actual API signal. Irssi::signal_register({'change prompt' => [qw/string/]}); Irssi::signal_add('change prompt' => \&change_prompt_sig); + + # other scripts (specifically overlay/visual) can subscribe to + # this event to be notified when the prompt changes. + # arguments are new contents (string), new length (int) + Irssi::signal_register({'prompt changed' => [qw/string int/]}); } sub change_prompt_sig { @@ -104,7 +109,7 @@ sub uberprompt_draw { my $window = Irssi::active_win; # hack to produce the same defaults as prompt/prompt_empty sbars. - + print Dumper($sb_item); if (scalar( () = $window->items )) { $default_prompt = '{uberprompt $[.15]itemname}'; } else { @@ -115,19 +120,21 @@ sub uberprompt_draw { if (defined $prompt_data) { # replace the special marker '$p' with the original prompt. - $p_copy =~ s/\$p/$default_prompt/; + $p_copy =~ s/\$/\$\$/g; # escape all $ symbols + $p_copy =~ s/\\/\\\\/g; # escape backslashes. + + $p_copy =~ s/\$\$p/$default_prompt/; + } else { $p_copy = $default_prompt; } - $p_copy =~ s/\$/\$\$/g; # escape all $ symbols - $p_copy =~ s/\\/\\\\/g; # escape backslashes. 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', return $ret; } -- cgit v1.2.3 From d80d66a287910526f119c06bcecff42a7ab15b79 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 17:27:24 +0100 Subject: documented uberprompt better, and added the 'prompt changed' signal --- prompt_info/uberprompt.pl | 71 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 0a2dc6a..6c012c4 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -1,3 +1,63 @@ +# This script replaces the default prompt status-bar item with one capable +# of displaying additional information, under either user control or via +# scripts. +# +# Installation: +# +# 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 +# +# Usage: +# +# Although the script is designed primarily for other scripts to set +# status information into the prompt, the following commands are available: +# +# /prompt set - sets the prompt to the given argument. $p in the argument will +# be replaced by the original prompt content. +# /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. +# +# Usage from other Scripts: +# +# signal_emit 'change prompt' 'some_string $p other string'; +# +# will set the prompt to include that content. +# +# 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 ... }; +# +# 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. + + use strict; use warnings; @@ -15,7 +75,7 @@ our %IRSSI = name => "prompt_info", description => "Helper script for dynamically adding text " . "into the input-bar prompt.", - license => "Public Domain", + license => "MIT", changed => "24/7/2010" ); @@ -108,8 +168,9 @@ sub uberprompt_draw { my $window = Irssi::active_win; + #print Dumper($sb_item); + # hack to produce the same defaults as prompt/prompt_empty sbars. - print Dumper($sb_item); if (scalar( () = $window->items )) { $default_prompt = '{uberprompt $[.15]itemname}'; } else { @@ -134,7 +195,11 @@ sub uberprompt_draw { $prompt_item = $sb_item; my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); - #Irssi::signal_emit('prompt changed', + # TODO: do this properly, and also make sure it's only emitted once per + # change. + + Irssi::signal_emit('prompt changed', $p_copy, $sb_item->{size}); + return $ret; } -- cgit v1.2.3 From 217d7296f79de207639bf4d47cbfd15d54ec5129 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 17:58:39 +0100 Subject: added some debug logging to catch 'prompt changed' --- prompt_info/uberprompt.pl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 6c012c4..6056d3f 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -67,7 +67,7 @@ use Data::Dumper; -our $VERSION = "0.1"; +our $VERSION = "0.2"; our %IRSSI = ( authors => "shabble", @@ -83,7 +83,7 @@ sub DEBUG () { 1 } #sub DEBUG () { 0 } my $prompt_data = undef; -my $prompt_item = undef; +#my $prompt_item = undef; my $prompt_format = ''; @@ -126,6 +126,16 @@ sub init { # this event to be notified when the prompt changes. # arguments are new contents (string), new length (int) Irssi::signal_register({'prompt changed' => [qw/string int/]}); + if (DEBUG) { + Irssi::signal_add 'prompt changed', \&debug_prompt_changed; + } +} + +sub debug_prompt_changed { + my ($text, $len) = @_; + my $exp = Irssi::current_theme()->format_expand($text, 0); + my $ps = Irssi::parse_special($exp); + print "DEBUG: Got $text = $exp = $ps, length: $len"; } sub change_prompt_sig { @@ -192,8 +202,6 @@ sub uberprompt_draw { 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); # TODO: do this properly, and also make sure it's only emitted once per # change. -- cgit v1.2.3 From 73487a72a5988da26f8a57e80d2fa68dfa9d2a01 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 18:01:13 +0100 Subject: moved more functions out into visual.pl, cleaned up some of the formatting. --- prompt_info/uberprompt.pl | 13 ------------- prompt_info/visual.pl | 7 +++++++ 2 files changed, 7 insertions(+), 13 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 6056d3f..bf7380b 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -83,13 +83,11 @@ sub DEBUG () { 1 } #sub DEBUG () { 0 } my $prompt_data = undef; -#my $prompt_item = undef; my $prompt_format = ''; init(); - sub prompt_subcmd_handler { my ($data, $server, $item) = @_; $data =~ s/\s+$//g; # strip trailing whitespace. @@ -211,19 +209,10 @@ sub uberprompt_draw { return $ret; } - sub uberprompt_refresh { Irssi::statusbar_items_redraw('uberprompt'); } - -sub cmd_clear_visual { - _clear_visual_region(); - #refresh_visual_overlay(); - Irssi::statusbar_items_redraw('input'); -} - - sub replace_prompt_items { # remove existing ones. print "Removing original prompt" if DEBUG; @@ -268,8 +257,6 @@ sub _sbar_command { Irssi::command($command); } - - # bit of fakery so things don't complain about the lack of prompt_info (hoepfully) %Irssi::Script::prompt_info:: = (); diff --git a/prompt_info/visual.pl b/prompt_info/visual.pl index 5941fe0..1413d0d 100644 --- a/prompt_info/visual.pl +++ b/prompt_info/visual.pl @@ -95,6 +95,13 @@ sub init { } +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(); -- cgit v1.2.3 From 497389336904a9bc1f0fe4d87ed5aae29a0f80d5 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 22:00:07 +0100 Subject: added Bugs section in comments describing crash bug when debug enabled. Rare enough to not really be a problem, I hope. --- prompt_info/uberprompt.pl | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index bf7380b..3146c67 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -35,6 +35,12 @@ # # signal_add 'prompt changed', sub { my ($text, $len) = @_; ... do something ... }; # +# 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. +# # LICENCE: # # Copyright (c) 2010 Tom Feist -- cgit v1.2.3 From 6012b57692ee31ad43abf0270fe29f1ed313e6d9 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 22:02:48 +0100 Subject: added doc about uberprompt_format setting --- prompt_info/uberprompt.pl | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 3146c67..a192780 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -24,6 +24,18 @@ # /prompt off - restore the original irssi prompt and prompt_empty statusbars. # unloading the script has the same effect. # +# Additionally, the format for the prompt can be set via: +# +# /set uberprompt_format +# +# The default is [$*], which is the same as the default provided in default.theme. +# Changing this setting will update the prompt immediately, unlike editing your theme. +# +# 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_emit 'change prompt' 'some_string $p other string'; -- cgit v1.2.3 From d2e68afdbcf321b2051269e4419478eb7bccc387 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 22:10:20 +0100 Subject: added uberprompt_debug as an irssi setting. defaults to off. --- prompt_info/uberprompt.pl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index a192780..d5f66b2 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -97,8 +97,10 @@ our %IRSSI = changed => "24/7/2010" ); -sub DEBUG () { 1 } -#sub DEBUG () { 0 } + +my $DEBUG_ENABLED = 0; + +sub DEBUG { $DEBUG_ENABLED } my $prompt_data = undef; @@ -117,6 +119,7 @@ sub init { Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*] '); + Irssi::settings_add_bool('uberprompt', 'uberprompt_debug', 0); Irssi::command_bind("prompt", \&prompt_subcmd_handler); Irssi::command_bind('prompt on', \&replace_prompt_items); @@ -179,6 +182,9 @@ sub UNLOAD { } sub reload_settings { + + $DEBUG_ENABLED = Irssi::settings_get_bool('uberprompt_debug'); + my $new = Irssi::settings_get_str('uberprompt_format'); if ($prompt_format ne $new) { print "Updated prompt format" if DEBUG; -- cgit v1.2.3 From a3c1eabb6272b0cff113a557dba10913e85f4ab1 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sun, 10 Oct 2010 19:03:35 +0100 Subject: added a bunch of documentation (provisional atm, pending implementation), and started cleanup of code --- prompt_info/uberprompt.pl | 117 +++++++++++++++++++++++++++++++--------------- 1 file changed, 79 insertions(+), 38 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index d5f66b2..f026a91 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -2,7 +2,7 @@ # of displaying additional information, under either user control or via # scripts. # -# Installation: +# INSTALL: # # Place script in ~/.irssi/scripts/ and potentially symlink into autorun/ # to ensure it starts at irssi startup. @@ -11,11 +11,16 @@ # # /script load uberprompt.pl # -# Usage: +# 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. # /prompt clear - clears the additional data provided to the prompt. @@ -26,21 +31,43 @@ # # Additionally, the format for the prompt can be set via: # +# UBERPROMPT FORMAT: +# # /set uberprompt_format # # The default is [$*], which is the same as the default provided in default.theme. # 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: +# Usage from other Scripts: signal 'change prompt' => 'string' => position +# +# eg: +# +# signal_emit 'change prompt' 'some_string', UberPrompt::UP_INNER; # -# signal_emit 'change prompt' 'some_string $p other string'; +# will set the prompt to include that content, by default '[$* some_string]' # -# will set the prompt to include that content. +# The possible position arguments are: +# +# 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: @@ -75,7 +102,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. - use strict; use warnings; @@ -83,8 +109,6 @@ use Irssi; use Irssi::TextUI; # for sbar_items_redraw use Data::Dumper; - - our $VERSION = "0.2"; our %IRSSI = ( @@ -99,11 +123,10 @@ our %IRSSI = my $DEBUG_ENABLED = 0; - sub DEBUG { $DEBUG_ENABLED } my $prompt_data = undef; - +my $prompt_changed = 0; my $prompt_format = ''; init(); @@ -118,8 +141,9 @@ sub init { Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); - Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*] '); + 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::command_bind("prompt", \&prompt_subcmd_handler); Irssi::command_bind('prompt on', \&replace_prompt_items); @@ -134,34 +158,46 @@ sub init { # intialise the prompt format. reload_settings(); - # install our statusbars. - replace_prompt_items(); + # install our statusbars if required. + if (Irssi::settings_get_bool('uberprompt_autostart')) { + replace_prompt_items(); + } + + # API signals - # the actual API signal. - Irssi::signal_register({'change prompt' => [qw/string/]}); - Irssi::signal_add('change prompt' => \&change_prompt_sig); + Irssi::signal_register({'change prompt' => [qw/string int/]}); + Irssi::signal_add('change prompt' => \&change_prompt_handler); # other scripts (specifically overlay/visual) can subscribe to # this event to be notified when the prompt changes. # arguments are new contents (string), new length (int) Irssi::signal_register({'prompt changed' => [qw/string int/]}); + if (DEBUG) { Irssi::signal_add 'prompt changed', \&debug_prompt_changed; } } +sub reload_settings { + + $DEBUG_ENABLED = Irssi::settings_get_bool('uberprompt_debug'); + + 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 debug_prompt_changed { my ($text, $len) = @_; - my $exp = Irssi::current_theme()->format_expand($text, 0); - my $ps = Irssi::parse_special($exp); print "DEBUG: Got $text = $exp = $ps, length: $len"; } -sub change_prompt_sig { +sub change_prompt_handler { my ($text) = @_; - # TODO: mroe intelligence about where to insert $p? - $text = '$p' . $text; print "Got prompt change sig with: $text" if DEBUG; my $changed; @@ -181,22 +217,11 @@ sub UNLOAD { restore_prompt_items(); } -sub reload_settings { - - $DEBUG_ENABLED = Irssi::settings_get_bool('uberprompt_debug'); - - 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 $actual_prompt = ''; my $window = Irssi::active_win; @@ -204,19 +229,24 @@ sub uberprompt_draw { # hack to produce the same defaults as prompt/prompt_empty sbars. if (scalar( () = $window->items )) { - $default_prompt = '{uberprompt $[.15]itemname}'; + $actual_prompt = '{uberprompt $[.15]itemname}'; } else { - $default_prompt = '{uberprompt $winname}'; + $actual_prompt = '{uberprompt $winname}'; } my $p_copy = $prompt_data; if (defined $prompt_data) { - # replace the special marker '$p' with the original prompt. - $p_copy =~ s/\$/\$\$/g; # escape all $ symbols + if ($prompt_data =~ m/\$\$p/) { + $p_copy =~ s/\$\$p/$default_prompt/; + + # replace the special marker '$p' with the original prompt. + } else { + $p_copy = $prompt_format; + $p_copy =~ s/\$ + } $p_copy =~ s/\\/\\\\/g; # escape backslashes. - $p_copy =~ s/\$\$p/$default_prompt/; } else { $p_copy = $default_prompt; @@ -225,8 +255,12 @@ sub uberprompt_draw { print "Redrawing with: $p_copy, size-only: $get_size_only" if DEBUG; my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); + + # TODO: do this properly, and also make sure it's only emitted once per # change. + my $exp = Irssi::current_theme()->format_expand($text, 0); + my $ps = Irssi::parse_special($exp); Irssi::signal_emit('prompt changed', $p_copy, $sb_item->{size}); @@ -284,3 +318,10 @@ sub _sbar_command { # bit of fakery so things don't complain about the lack of prompt_info (hoepfully) %Irssi::Script::prompt_info:: = (); + +package UberPrompt; + +sub UP_PRE () { 0 } +sub UP_INNER () { 1 } +sub UP_POST () { 2 } +sub UP_ONLY () { 3 } -- cgit v1.2.3 From 9a55a5a02458693c2297d19e7c8017deb9938191 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sun, 10 Oct 2010 21:16:03 +0100 Subject: implemented the various prompt addition modes as documented. tests so far look good. --- prompt_info/uberprompt.pl | 134 ++++++++++++++++++++++++++++------------------ 1 file changed, 82 insertions(+), 52 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index f026a91..cc01e52 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -55,7 +55,7 @@ # # will set the prompt to include that content, by default '[$* some_string]' # -# The possible position arguments are: +# 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} @@ -125,18 +125,26 @@ our %IRSSI = my $DEBUG_ENABLED = 0; sub DEBUG { $DEBUG_ENABLED } -my $prompt_data = undef; -my $prompt_changed = 0; -my $prompt_format = ''; +my $prompt_data = undef; +my $prompt_data_pos = 'UP_INNER'; + +my $prompt_last = ''; +my $prompt_format = ''; 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); } +sub UNLOAD { + # remove uberprompt and return the original ones. + print "Removing uberprompt and restoring original"; + restore_prompt_items(); +} + sub init { Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); @@ -149,9 +157,16 @@ sub init { 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; }); + 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 clear', - sub { Irssi::signal_emit 'change prompt', '$p'; }); + sub { + Irssi::signal_emit 'change prompt', '$p', 'UP_POST'; + }); Irssi::signal_add('setup changed', \&reload_settings); @@ -165,7 +180,7 @@ sub init { # API signals - Irssi::signal_register({'change prompt' => [qw/string int/]}); + Irssi::signal_register({'change prompt' => [qw/string string/]}); Irssi::signal_add('change prompt' => \&change_prompt_handler); # other scripts (specifically overlay/visual) can subscribe to @@ -186,83 +201,105 @@ sub reload_settings { if ($prompt_format ne $new) { print "Updated prompt format" if DEBUG; $prompt_format = $new; + $prompt_format =~ s/\$uber/\$\$uber/; Irssi::abstracts_register(['uberprompt', $prompt_format]); } } sub debug_prompt_changed { my ($text, $len) = @_; - print "DEBUG: Got $text = $exp = $ps, length: $len"; + + $text =~ s/%/%%/g; + + print "DEBUG: Got $text, length: $len"; } sub change_prompt_handler { - my ($text) = @_; + my ($text, $pos) = @_; - print "Got prompt change sig with: $text" if DEBUG; + print "Got prompt change signal with: $text, $pos" if DEBUG; - my $changed; - $changed = defined $prompt_data ? $prompt_data ne $text : 1; + my ($changed_text, $changed_pos); + $changed_text = defined $prompt_data ? $prompt_data ne $text : 1; + $changed_pos = defined $prompt_data_pos ? $prompt_data_pos ne $pos : 1; - $prompt_data = $text; + $prompt_data = $text; + $prompt_data_pos = $pos; - if ($changed) { + if ($changed_text || $changed_pos) { print "Redrawing prompt" if DEBUG; uberprompt_refresh(); } } -sub UNLOAD { - # remove uberprompt and return the original ones. - print "Removing uberprompt and restoring original"; - restore_prompt_items(); +sub _escape_prompt_special { + my $str = shift; + $str =~ s/\$/\$\$/g; + $str =~ s/\\/\\\\/g; + return $str; } - sub uberprompt_draw { my ($sb_item, $get_size_only) = @_; - my $actual_prompt = ''; - my $window = Irssi::active_win; + my $prompt_arg = ''; - #print Dumper($sb_item); - - # hack to produce the same defaults as prompt/prompt_empty sbars. + # default prompt sbar arguments (from config) if (scalar( () = $window->items )) { - $actual_prompt = '{uberprompt $[.15]itemname}'; + $prompt_arg = '$[.15]{itemname}'; } else { - $actual_prompt = '{uberprompt $winname}'; + $prompt_arg = '${winname}'; } - my $p_copy = $prompt_data; + my $prompt = ''; # rendered content of the prompt. + my $theme = Irssi::current_theme; - if (defined $prompt_data) { - if ($prompt_data =~ m/\$\$p/) { - $p_copy =~ s/\$\$p/$default_prompt/; + $prompt = $theme->format_expand("{uberprompt $prompt_arg}"); - # replace the special marker '$p' with the original prompt. - } else { - $p_copy = $prompt_format; - $p_copy =~ s/\$ - } - $p_copy =~ s/\\/\\\\/g; # escape backslashes. + if ($prompt_data_pos eq 'UP_ONLY') { + $prompt =~ s/\$\$uber//; # no need for recursive prompting, I hope. + + # TODO: only compute this if necessary? + my $prompt_nt = $prompt; + $prompt_nt =~ s/\s+$//; + + my $pdata_copy = $prompt_data; + $pdata_copy =~ s/\$prompt_nt/$prompt_nt/; + $pdata_copy =~ s/\$prompt/$prompt/; + + $prompt = $pdata_copy; + + } elsif ($prompt_data_pos eq 'UP_INNER' && defined $prompt_data) { + my $esc = _escape_prompt_special($prompt_data); + $prompt =~ s/\$\$uber/$esc/; } else { - $p_copy = $default_prompt; + # remove the $uber marker + $prompt =~ s/\$\$uber//; + + # and add the additional text at the appropriate position. + if ($prompt_data_pos eq 'UP_PRE') { + $prompt = $prompt_data . $prompt; + } elsif ($prompt_data_pos eq 'UP_POST') { + $prompt .= $prompt_data; + } } - print "Redrawing with: $p_copy, size-only: $get_size_only" if DEBUG; + print "Redrawing with: $prompt, size-only: $get_size_only" if DEBUG; - my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); + if ($prompt ne $prompt_last) { - # TODO: do this properly, and also make sure it's only emitted once per - # change. - my $exp = Irssi::current_theme()->format_expand($text, 0); - my $ps = Irssi::parse_special($exp); + # print "Emitting prompt changed signal" if DEBUG; + # my $exp = Irssi::current_theme()->format_expand($text, 0); + my $ps = Irssi::parse_special($prompt); - Irssi::signal_emit('prompt changed', $p_copy, $sb_item->{size}); + Irssi::signal_emit('prompt changed', $ps, length($ps)); + $prompt_last = $prompt; + } + my $ret = $sb_item->default_handler($get_size_only, $prompt, '', 0); return $ret; } @@ -318,10 +355,3 @@ sub _sbar_command { # bit of fakery so things don't complain about the lack of prompt_info (hoepfully) %Irssi::Script::prompt_info:: = (); - -package UberPrompt; - -sub UP_PRE () { 0 } -sub UP_INNER () { 1 } -sub UP_POST () { 2 } -sub UP_ONLY () { 3 } -- cgit v1.2.3 From b2bcef1f165be98916fb2b67121baa225a269098 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sun, 10 Oct 2010 21:40:10 +0100 Subject: removed compat mode for prompt-info, since we no longer adhere to the same signal params --- prompt_info/uberprompt.pl | 3 --- 1 file changed, 3 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index cc01e52..45a5d0b 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -352,6 +352,3 @@ sub _sbar_command { Irssi::command($command); } -# bit of fakery so things don't complain about the lack of prompt_info (hoepfully) - -%Irssi::Script::prompt_info:: = (); -- cgit v1.2.3 From 6c06bc858315a0802c0b901555873de4eccaf966 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sun, 10 Oct 2010 21:47:40 +0100 Subject: re-added additional signals to refresh prompt when needed --- prompt_info/uberprompt.pl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 45a5d0b..390e8e5 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -149,7 +149,7 @@ sub init { Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); - 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); @@ -173,6 +173,12 @@ sub init { # intialise the prompt format. reload_settings(); + # make sure we redraw when necessary. + Irssi::signal_add('window changed', \&uberprompt_draw); + Irssi::signal_add('window name changed', \&uberprompt_draw); + Irssi::signal_add('window changed automatic', \&uberprompt_draw); + Irssi::signal_add('window item changed', \&uberprompt_draw); + # install our statusbars if required. if (Irssi::settings_get_bool('uberprompt_autostart')) { replace_prompt_items(); -- cgit v1.2.3 From 80305f6c0c471acc643882281829a5c391310552 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 13 Oct 2010 02:16:08 +0100 Subject: fix to uberprompt calling the wrong draw function from signalhandlers --- prompt_info/uberprompt.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 390e8e5..3bb3155 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -174,10 +174,10 @@ sub init { reload_settings(); # make sure we redraw when necessary. - Irssi::signal_add('window changed', \&uberprompt_draw); - Irssi::signal_add('window name changed', \&uberprompt_draw); - Irssi::signal_add('window changed automatic', \&uberprompt_draw); - Irssi::signal_add('window item changed', \&uberprompt_draw); + 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); # install our statusbars if required. if (Irssi::settings_get_bool('uberprompt_autostart')) { -- cgit v1.2.3 From 8edb0c6866d7263a11efa11bbee4e2f738ac7d35 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 13 Oct 2010 12:35:07 +0100 Subject: fixed undef bug in uberprompt --- 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 3bb3155..79717ae 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -125,7 +125,7 @@ our %IRSSI = my $DEBUG_ENABLED = 0; sub DEBUG { $DEBUG_ENABLED } -my $prompt_data = undef; +my $prompt_data = ''; my $prompt_data_pos = 'UP_INNER'; my $prompt_last = ''; -- cgit v1.2.3 From 46f32ac80dfc4d5542f0a01a1996d15d4ce11157 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 14 Oct 2010 19:02:17 +0100 Subject: fixed problem with uberprompt sometimes starting on RHS of input line. --- prompt_info/uberprompt.pl | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 79717ae..76660b2 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -335,13 +335,7 @@ sub restore_prompt_items { 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'); - + _sbar_command('prompt', 'reset'); } sub _sbar_command { -- cgit v1.2.3 From 85ab93558d23470dd7a3f043354980a82226ece7 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 14 Oct 2010 21:00:05 +0100 Subject: uberprompt: hopefully fixed RHS positioning on script autorun --- prompt_info/uberprompt.pl | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 76660b2..0581dd3 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -80,6 +80,14 @@ # 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 @@ -114,7 +122,7 @@ our %IRSSI = ( authors => "shabble", contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', - name => "prompt_info", + name => "uberprompt", description => "Helper script for dynamically adding text " . "into the input-bar prompt.", license => "MIT", @@ -131,7 +139,25 @@ my $prompt_data_pos = 'UP_INNER'; my $prompt_last = ''; my $prompt_format = ''; -init(); +pre_init(); + +sub pre_init { + # my $start_time = Irssi::parse_special('$F'); + # my $now = time(); + # my $delta = $now - $start_time; + + # print "Delta is $delta"; + # if ($delta < 2) { + # print "starting a bit later"; + # Irssi::timeout_add_once(5000, \&init, undef); + # } else { + # print "starting immediately"; + + # init(); + # } + Irssi::command('statusbar prompt reset'); + init(); +} sub prompt_subcmd_handler { my ($data, $server, $item) = @_; @@ -146,7 +172,6 @@ sub UNLOAD { } sub init { - Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*$uber] '); -- cgit v1.2.3