aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--prompt_info/input_overlay.pl288
-rw-r--r--prompt_info/overlays.pl198
-rw-r--r--prompt_info/prompt_info.pl114
-rw-r--r--prompt_info/prompt_replace.pl346
-rw-r--r--prompt_info/uberprompt.pl39
-rw-r--r--prompt_info/visual.pl168
6 files changed, 26 insertions, 1127 deletions
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', \&region_toggle);
- Irssi::command_bind('region_clear', \&region_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 <string>
-#
-# 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 * C</prompt set [-inner|-pre|-post|only] E<lt>msgE<gt>>
+
+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<UP_*> constants listed below is required, in
+the format C</prompt set -inner Hello!>
+
+=item * C</prompt clear>
-/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] <msg>
+=item * C</prompt on>
-/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</prompt off>
+
+Restore the original irssi prompt and prompt_empty statusbars. unloading the
+script has the same effect.
+
+=item * C</help prompt>
+
+show help for uberprompt commands
+
+=back
=head1 UBERPROMPT FORMAT:
@@ -54,7 +67,7 @@ F<default.theme>.
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<UP_INNER> or </prompt set -inner>
+the content of prompt data provided with the C<UP_INNER> or C</prompt set -inner>
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();
-}