aboutsummaryrefslogtreecommitdiffstats
path: root/prompt_info
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--prompt_info/overlays.pl213
-rw-r--r--prompt_info/uberprompt.pl18
-rw-r--r--prompt_info/visual.pl23
3 files changed, 178 insertions, 76 deletions
diff --git a/prompt_info/overlays.pl b/prompt_info/overlays.pl
index 47a3eef..b3299e9 100644
--- a/prompt_info/overlays.pl
+++ b/prompt_info/overlays.pl
@@ -1,89 +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 $overlay;
-
+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 ($line, $start, $end, $text, $len) = @_;
- my $region = { start => $start,
- end => $end,
+ my ($x, $y, $text) = @_;
+ my $region = { start => $x,
text => $text,
- len => $len };
+ };
- my $o_line = $overlay->{$line};
+ my $o_line = $overlays->{$y};
unless (defined $o_line) {
$o_line = [];
- $overlay->{$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;
- }
- }
+ # 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) = @_;
+# sub _remove_overlay_region {
+# my ($line, $start, $end) = @_;
- my $o_line = $overlay->{$line};
- return unless $o_line;
+# 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;
+# 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});
}
- $i++;
}
- splice @$o_line, $i, 1, (); # remove it.
}
-sub _redraw_overlay {
- foreach my $line_num (sort keys %$overlay) {
- my $line = $overlay->{$line_num};
+sub augment_redraw {
+ #print "Redraw called" if DEBUG;
+ #redraw_overlay();
+ Irssi::timeout_add_once(10, \&redraw_overlay, 0);
+}
- foreach my $region (@$line) {
- Irssi::gui_printtext($region->{start}, $line_num,
- $region->{text});
- }
+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 {
- Irssi::active_win->view->redraw();
+ $overlays = {};
+ redraw_overlay();
}
-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);
- }
+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/uberprompt.pl b/prompt_info/uberprompt.pl
index 7b3e022..ded45cf 100644
--- a/prompt_info/uberprompt.pl
+++ b/prompt_info/uberprompt.pl
@@ -153,14 +153,25 @@ sub prompt_subcmd_handler {
}
sub UNLOAD {
+ deinit();
+}
+
+sub exp_lbrace { '{' }
+sub exp_rbrace { '}' }
+
+sub deinit {
+ Irssi::expando_destroy('brace');
# 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');
+ # TODO: flags to prevent these from being recomputed?
+ Irssi::expando_create('lbrace', \&exp_lbrace, {});
+ Irssi::expando_create('rbrace', \&exp_rbrace, {});
+
Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*$uber] ');
Irssi::settings_add_bool('uberprompt', 'uberprompt_debug', 0);
Irssi::settings_add_bool('uberprompt', 'uberprompt_autostart', 1);
@@ -255,6 +266,10 @@ sub _escape_prompt_special {
my $str = shift;
$str =~ s/\$/\$\$/g;
$str =~ s/\\/\\\\/g;
+ #$str =~ s/%/%%/g;
+ $str =~ s/{/\$lbrace/g;
+ $str =~ s/}/\$rbrace/g;
+
return $str;
}
@@ -292,6 +307,7 @@ sub uberprompt_draw {
$prompt = $pdata_copy;
} elsif ($prompt_data_pos eq 'UP_INNER' && defined $prompt_data) {
+
my $esc = _escape_prompt_special($prompt_data);
$prompt =~ s/\$\$uber/$esc/;
diff --git a/prompt_info/visual.pl b/prompt_info/visual.pl
index 1413d0d..b29875b 100644
--- a/prompt_info/visual.pl
+++ b/prompt_info/visual.pl
@@ -30,29 +30,6 @@ my ($term_w, $term_h) = (0, 0);
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) = @_;