From e7487fd2ba208f00f50942613da91038b0a2a432 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Tue, 28 Sep 2010 02:29:44 +0100 Subject: added a bunch more documentation to prompt_info script. --- prompt_info/prompt_info.pl | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/prompt_info.pl b/prompt_info/prompt_info.pl index 51e5c16..8ad63ba 100644 --- a/prompt_info/prompt_info.pl +++ b/prompt_info/prompt_info.pl @@ -9,10 +9,30 @@ # # prompt = "[$*$prompt_additional] " # -# Then add this script to your autorun directory (~/.irssi/scripts/autorun/) +# 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 modify your prompt content by using the '/set_prompt ' command, -# or from scripts by Irssi:signal_emit('change prompt', $string); +# You can also load it manually once the theme has been edited via +# +# /script load prompt_info.pl +# +# You will also need to reload your theme with the following command: +# +# /script exec Irssi::themes_reload() +# +# Once loaded, you can modify your prompt content by using the following command: +# +# /set_prompt +# +# You can also use it from other scripts by issuing a signal as follows: +# +# Irssi:signal_emit('change prompt', +# +# report bugs / feature requests to http://github.com/shabble/irssi-scripts/issues +# +# NOTE: it does not appear to be possible to use colours in your prompt at present. +# This is unlikely to change without source-code changes to Irssi itself. use strict; use warnings; -- cgit v1.2.3 From 90e7c67629ccd0e01176df5b59eb9301fab7121d Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 6 Oct 2010 18:21:03 +0100 Subject: more progress on replacing prompt bar for visual mode and other trickery. Prompt is mostly working but needs configuration options and more cleanup. Visual mode is still hacky as sin. --- prompt_info/prompt_replace.pl | 275 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 275 insertions(+) create mode 100644 prompt_info/prompt_replace.pl (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl new file mode 100644 index 0000000..5e29f92 --- /dev/null +++ b/prompt_info/prompt_replace.pl @@ -0,0 +1,275 @@ +use strict; +use warnings; + +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw +use Data::Dumper; +use Term::Size; + + + +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 $vis_enabled = 0; + +my ($term_w, $term_h); + +my ($region_start, $region_end); + +init(); + +sub update_terminal_size { + my @stty_lines = qx/stty -a/; + my $line = $stty_lines[0]; + @stty_lines = (); # don't need the rest. + + if ($line =~ m/\s*(\d+)\s*rows\s*;\s*(\d+)\s*columns\s*;/) { + $term_h = $1; + $term_w = $2; + } else { + print "Failed to detect terminal size"; + } +} + +sub init { + + Irssi::command_bind('prompt_on', \&replace_prompt_items); + Irssi::command_bind('prompt_off', \&restore_prompt_items); + + Irssi::command_bind('prompt_set', + sub { + my $data = shift; + $prompt_data = $data; + refresh_prompt(); + }); + + Irssi::command_bind('prompt_clear', + sub { + $prompt_data = undef; + refresh_prompt(); + }); + + Irssi::command_bind('visual', \&cmd_vis); + Irssi::command("^BIND meta-l /visual"); + + Irssi::statusbar_item_register ('new_prompt', 0, 'new_prompt_render'); + + + Irssi::signal_add_last('gui key pressed', \&key_pressed); + Irssi::signal_add('window changed', \&refresh_prompt); + Irssi::signal_add('window name changed', \&refresh_prompt); + Irssi::signal_add('window changed automatic', \&refresh_prompt); + Irssi::signal_add('window item changed', \&refresh_prompt); + + Irssi::signal_add('terminal resized', \&update_terminal_size); + + update_terminal_size(); + replace_prompt_items(); +} + +# Irssi::signal_add('window changed automatic', \&refresh_prompt); +# Irssi::signal_add('window changed automatic', \&refresh_prompt); + + +sub UNLOAD { + restore_prompt_items(); +} + +sub cmd_vis { + $vis_enabled = not $vis_enabled; + if ($vis_enabled) { + print "visual mode started"; + $region_start = _pos(); + } else { + print "Visual mode ended"; + $region_end = _pos(); + + 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"; + } else { + print "Invalid region selection: [ $region_start - $region_end ]"; + $region_start = $region_end = undef; + } + } + +} + +sub refresh_prompt { + Irssi::statusbar_items_redraw('new_prompt'); +} + +my $buf = ''; + +sub key_pressed { + my ($key) = @_; + my $char = chr($key); + $buf .= $char; + my $str = Irssi::parse_special('$L'); + + return unless $vis_enabled; + + print_to_input($str, $prompt_item->{size}); +} + +sub print_to_input { + my ($str, $offset) = @_; + $str = "%8$str%8"; + + # my ($term_w, $term_h) = Term::Size::chars *STDOUT{IO}; + + + # my $theme = Irssi::current_theme(); + # my $prompt = $theme->format_expand('{prompt $itemname $winname}', + # Irssi::EXPAND_FLAG_RECURSIVE_MASK); + #print "Prompt is $prompt"; + + Irssi::gui_printtext($offset, $term_h, $str); +} + + + sub new_prompt_render { + my ($sb_item, $get_size_only) = @_; + + + my $default_prompt = ''; + + my $window = Irssi::active_win(); + if (scalar( () = $window->items )) { + $default_prompt = '{prompt $[.15]itemname}'; + } else { + $default_prompt = '{prompt $winname}'; + } + + my $p_copy = $prompt_data; + if (defined $prompt_data) { + # check if we have a marker + $p_copy =~ s/\$p/$default_prompt/; + } else { + $p_copy = $default_prompt; + } + print "Redrawing with: $p_copy"; + + $prompt_item = $sb_item; + + $sb_item->default_handler($get_size_only, $p_copy, '', 0); + } + +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', 'new_prompt', + qw/-alignment left -before input -priority 0/); + +} + +sub restore_prompt_items { + + _sbar_command('prompt', 'remove', 'new_prompt'); + + print "Restoring original prompt" if DEBUG; + _sbar_command('prompt', 'add', 'prompt', + qw/-alignment left -before input -priority 0/); + _sbar_command('prompt', 'add', 'prompt_empty', + qw/-alignment left -after prompt -priority 0/); +} + + +sub _sbar_command { + my ($bar, $cmd, $item, @args) = @_; + + my $args_str = join ' ', @args; + + $args_str .= ' ' if length $args_str; + + 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(); +} + + +# 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"; +# } +# } -- cgit v1.2.3 From 2bf267d9bd0303e87df87817bba05c2128cc5898 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 6 Oct 2010 19:37:44 +0100 Subject: test release of prompt_replace. need to rework the whole visual stuff a bit more - probably into a generic overlay system. Also menu! --- prompt_info/prompt_replace.pl | 141 +++++++++++++++++++++++++++--------------- 1 file changed, 92 insertions(+), 49 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 5e29f92..83df371 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -28,16 +28,17 @@ my $prompt_item = undef; my $vis_enabled = 0; -my ($term_w, $term_h); +my ($term_w, $term_h) = (0, 0); -my ($region_start, $region_end); +my ($region_start, $region_end) = (0, 0); init(); sub update_terminal_size { + my @stty_lines = qx/stty -a/; my $line = $stty_lines[0]; - @stty_lines = (); # don't need the rest. + @stty_lines = (); # don't need the rest. if ($line =~ m/\s*(\d+)\s*rows\s*;\s*(\d+)\s*columns\s*;/) { $term_h = $1; @@ -52,6 +53,8 @@ sub init { Irssi::command_bind('prompt_on', \&replace_prompt_items); Irssi::command_bind('prompt_off', \&restore_prompt_items); + Irssi::command_bind('menu', \&draw_menu); + Irssi::command_bind('prompt_set', sub { my $data = shift; @@ -65,13 +68,20 @@ sub init { refresh_prompt(); }); - Irssi::command_bind('visual', \&cmd_vis); + Irssi::command_bind('visual', \&cmd_toggle_visual); Irssi::command("^BIND meta-l /visual"); + Irssi::signal_add_last('command redraw', sub { + print "Redrawing"; + refresh_prompt(); + Irssi::timeout_add_once(10, \&refresh_inputline, 0); + }); + Irssi::statusbar_item_register ('new_prompt', 0, 'new_prompt_render'); + Irssi::signal_add_first('gui key pressed', \&ctrl_l_intercept); + Irssi::signal_add_last ('gui key pressed', \&key_pressed); - Irssi::signal_add_last('gui key pressed', \&key_pressed); Irssi::signal_add('window changed', \&refresh_prompt); Irssi::signal_add('window name changed', \&refresh_prompt); Irssi::signal_add('window changed automatic', \&refresh_prompt); @@ -83,22 +93,20 @@ sub init { replace_prompt_items(); } -# Irssi::signal_add('window changed automatic', \&refresh_prompt); -# Irssi::signal_add('window changed automatic', \&refresh_prompt); - sub UNLOAD { restore_prompt_items(); } -sub cmd_vis { +sub cmd_toggle_visual { $vis_enabled = not $vis_enabled; if ($vis_enabled) { - print "visual mode started"; $region_start = _pos(); + $region_end = 0; # reset end marker. + print "visual mode started at $region_start"; } else { - print "Visual mode ended"; $region_end = _pos(); + print "Visual mode ended at $region_end"; if ($region_end > $region_start) { my $input = Irssi::parse_special('$L', 0, 0); @@ -106,7 +114,7 @@ sub cmd_vis { print "Region selected: $str"; } else { print "Invalid region selection: [ $region_start - $region_end ]"; - $region_start = $region_end = undef; + $region_start = $region_end = 0; } } @@ -116,61 +124,96 @@ sub refresh_prompt { Irssi::statusbar_items_redraw('new_prompt'); } -my $buf = ''; +sub ctrl_l_intercept { + my $key = shift; -sub key_pressed { - my ($key) = @_; - my $char = chr($key); - $buf .= $char; - my $str = Irssi::parse_special('$L'); + if ($key == 12) { + print "C-l pressed"; + Irssi::command("redraw"); + Irssi::signal_stop(); + } + if ($key == 10) { + $region_end = $region_start = 0; + } +} +sub key_pressed { + my $key = shift; return unless $vis_enabled; - - print_to_input($str, $prompt_item->{size}); + refresh_inputline(); } -sub print_to_input { - my ($str, $offset) = @_; - $str = "%8$str%8"; +sub refresh_inputline { + + my $end_pos = $region_end; + $end_pos ||= _pos(); # if not set, take current position as end. - # my ($term_w, $term_h) = Term::Size::chars *STDOUT{IO}; + 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 $theme = Irssi::current_theme(); - # my $prompt = $theme->format_expand('{prompt $itemname $winname}', - # Irssi::EXPAND_FLAG_RECURSIVE_MASK); - #print "Prompt is $prompt"; + my $text = substr($input, $region_start, $len); + + print "printing '$text' at $offset [$region_start, $end_pos] ($len)"; + + $text = '%k%2' . $text . '%n'; + _draw_overlay($offset, $text, $len); - Irssi::gui_printtext($offset, $term_h, $str); } +sub _draw_overlay { + my ($offset, $text, $len) = @_; + Irssi::gui_printtext($offset, $term_h, $text); +} - sub new_prompt_render { - my ($sb_item, $get_size_only) = @_; +sub draw_menu { + + my $w = 10; + + my @lines = ( + '+' . ('-' x $w) . '+', + sprintf('|%*s|', $w, 'bacon'), + sprintf('|%*s|', $w, 'bacon'), + sprintf('|%*s|', $w, 'bacon'), + sprintf('|%*s|', $w, 'bacon'), + sprintf('|%*s|', $w, 'bacon'), + sprintf('|%*s|', $w, 'bacon'), + '+' . ('-' x $w) . '+', + ); + my $i = 10; # start vert offset. + for my $line (@lines) { + Irssi::gui_printtext(int ($term_w / 2), $i++, $line); + } +} +sub new_prompt_render { + my ($sb_item, $get_size_only) = @_; - my $default_prompt = ''; - my $window = Irssi::active_win(); - if (scalar( () = $window->items )) { - $default_prompt = '{prompt $[.15]itemname}'; - } else { - $default_prompt = '{prompt $winname}'; - } + my $default_prompt = ''; - my $p_copy = $prompt_data; - if (defined $prompt_data) { - # check if we have a marker - $p_copy =~ s/\$p/$default_prompt/; - } else { - $p_copy = $default_prompt; - } - print "Redrawing with: $p_copy"; + my $window = Irssi::active_win(); + if (scalar( () = $window->items )) { + $default_prompt = '{prompt $[.15]itemname}'; + } else { + $default_prompt = '{prompt $winname}'; + } - $prompt_item = $sb_item; + my $p_copy = $prompt_data; + if (defined $prompt_data) { + # check if we have a marker + $p_copy =~ s/\$p/$default_prompt/; + } else { + $p_copy = $default_prompt; + } + print "Redrawing with: $p_copy, size-only: $get_size_only"; - $sb_item->default_handler($get_size_only, $p_copy, '', 0); - } + $prompt_item = $sb_item; + + $sb_item->default_handler($get_size_only, $p_copy, '', 0); +} sub replace_prompt_items { # remove existing ones. -- cgit v1.2.3 From 2c7a354130c995024f698597923e47fbee1dd535 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 6 Oct 2010 19:40:15 +0100 Subject: removed useless include of Term::Size --- prompt_info/prompt_replace.pl | 1 - 1 file changed, 1 deletion(-) (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 83df371..107e9c2 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -4,7 +4,6 @@ use warnings; use Irssi; use Irssi::TextUI; # for sbar_items_redraw use Data::Dumper; -use Term::Size; -- cgit v1.2.3 From 7e73f5db693ffb82ea49ecfed37e53dfd332f496 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 6 Oct 2010 21:58:39 +0100 Subject: renamed a lot of things, it's now 'uberprompt', which can be set from within irssi rather than editing themes. It also allows additional text to be specified with the $p 'variable' Started on a big overlay system, but needs a lot more thinking about. Will rip it out and just make visual inputline for now. --- prompt_info/prompt_replace.pl | 281 +++++++++++++++++++++++------------------- 1 file changed, 157 insertions(+), 124 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 107e9c2..3b28a05 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -31,6 +31,70 @@ my ($term_w, $term_h) = (0, 0); my ($region_start, $region_end) = (0, 0); +# overlay := { $num1 => line1, $num2 => line2 } +# line := [ region, region, region ] +# region := { start => x, end => y, ...? } + +my $overlay; + +my $prompt_format; +my $prompt_format_str = ''; + + +sub _add_overlay_region { + my ($line, $start, $end, $text, $len) = @_; + my $region = { start => $start, + end => $end, + text => $text, + len => $len }; + + my $o_line = $overlay->{$line}; + + unless (defined $o_line) { + $o_line = []; + $overlay->{$line} = $o_line; + } + + foreach my $cur_region (@$o_line) { + if (_region_overlaps($cur_region, $region)) { + # do something. + print "Region overlaps"; + last; + } + } + + push @$o_line, $region; + +} + +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 { + foreach my $line_num (sort keys %$overlay) { + my $line = $overlay->{$line_num}; + + foreach my $region (@$line) { + Irssi::gui_printtext($region->{start}, $line_num, + $region->{text}); + } + } +} + + init(); sub update_terminal_size { @@ -47,56 +111,111 @@ sub update_terminal_size { } } -sub init { +sub subcmd_handler { + my ($data, $server, $item) = @_; + $data =~ s/\s+$//g; # strip trailing whitespace. + Irssi::command_runsub('prompt', $data, $server, $item); +} - Irssi::command_bind('prompt_on', \&replace_prompt_items); - Irssi::command_bind('prompt_off', \&restore_prompt_items); +sub init { - Irssi::command_bind('menu', \&draw_menu); + Irssi::statusbar_item_register ('uberprompt', 0, 'uberprompt_draw'); - Irssi::command_bind('prompt_set', - sub { - my $data = shift; - $prompt_data = $data; - refresh_prompt(); - }); + Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*] '); - Irssi::command_bind('prompt_clear', - sub { - $prompt_data = undef; - refresh_prompt(); - }); + Irssi::command_bind("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 { $prompt_data = shift; uberprompt_refresh(); }); + Irssi::command_bind('prompt clear', + sub { undef $prompt_data; uberprompt_refresh(); }); + # misc faff Irssi::command_bind('visual', \&cmd_toggle_visual); Irssi::command("^BIND meta-l /visual"); + Irssi::command_bind('menu', \&draw_menu); - Irssi::signal_add_last('command redraw', sub { - print "Redrawing"; - refresh_prompt(); - Irssi::timeout_add_once(10, \&refresh_inputline, 0); - }); - - Irssi::statusbar_item_register ('new_prompt', 0, 'new_prompt_render'); - + # 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); - Irssi::signal_add('window changed', \&refresh_prompt); - Irssi::signal_add('window name changed', \&refresh_prompt); - Irssi::signal_add('window changed automatic', \&refresh_prompt); - Irssi::signal_add('window item changed', \&refresh_prompt); + # 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(); } - 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_str ne $new) { + print "Updated prompt format"; + $prompt_format_str = $new; + Irssi::abstracts_register(['uberprompt', $prompt_format_str]); + } +} + +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"; + + $prompt_item = $sb_item; + + $sb_item->default_handler($get_size_only, $p_copy, '', 0); +} + +sub augment_redraw { + print "Redraw called"; + uberprompt_refresh(); + Irssi::timeout_add_once(10, \&refresh_inputline, 0); +} + +sub uberprompt_refresh { + Irssi::statusbar_items_redraw('uberprompt'); +} + sub cmd_toggle_visual { $vis_enabled = not $vis_enabled; if ($vis_enabled) { @@ -116,11 +235,6 @@ sub cmd_toggle_visual { $region_start = $region_end = 0; } } - -} - -sub refresh_prompt { - Irssi::statusbar_items_redraw('new_prompt'); } sub ctrl_l_intercept { @@ -167,19 +281,23 @@ sub _draw_overlay { Irssi::gui_printtext($offset, $term_h, $text); } -sub draw_menu { +sub _clear_overlay { + Irssi::active_win->view->redraw(); +} + +sub _draw_overlay_menu { my $w = 10; my @lines = ( - '+' . ('-' x $w) . '+', - sprintf('|%*s|', $w, 'bacon'), + '%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'), - '+' . ('-' x $w) . '+', + '%7+' . ('-' x $w) . '+%n', ); my $i = 10; # start vert offset. for my $line (@lines) { @@ -187,32 +305,6 @@ sub draw_menu { } } -sub new_prompt_render { - my ($sb_item, $get_size_only) = @_; - - - my $default_prompt = ''; - - my $window = Irssi::active_win(); - if (scalar( () = $window->items )) { - $default_prompt = '{prompt $[.15]itemname}'; - } else { - $default_prompt = '{prompt $winname}'; - } - - my $p_copy = $prompt_data; - if (defined $prompt_data) { - # check if we have a marker - $p_copy =~ s/\$p/$default_prompt/; - } else { - $p_copy = $default_prompt; - } - print "Redrawing with: $p_copy, size-only: $get_size_only"; - - $prompt_item = $sb_item; - - $sb_item->default_handler($get_size_only, $p_copy, '', 0); -} sub replace_prompt_items { # remove existing ones. @@ -223,14 +315,14 @@ sub replace_prompt_items { # add the new one. - _sbar_command('prompt', 'add', 'new_prompt', + _sbar_command('prompt', 'add', 'uberprompt', qw/-alignment left -before input -priority 0/); } sub restore_prompt_items { - _sbar_command('prompt', 'remove', 'new_prompt'); + _sbar_command('prompt', 'remove', 'uberprompt'); print "Restoring original prompt" if DEBUG; _sbar_command('prompt', 'add', 'prompt', @@ -239,7 +331,6 @@ sub restore_prompt_items { qw/-alignment left -after prompt -priority 0/); } - sub _sbar_command { my ($bar, $cmd, $item, @args) = @_; @@ -254,64 +345,6 @@ sub _sbar_command { Irssi::command($command); } - sub _pos { return Irssi::gui_input_get_pos(); } - - -# 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"; -# } -# } -- cgit v1.2.3 From 72052b70195a3f44839d1c0c54d4281c94c05162 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 6 Oct 2010 22:02:12 +0100 Subject: moved most of the overlay stuff out into overlays.pl for another time. --- prompt_info/overlays.pl | 89 +++++++++++++++++++++++++++++++++++++++++++ prompt_info/prompt_replace.pl | 85 ----------------------------------------- 2 files changed, 89 insertions(+), 85 deletions(-) create mode 100644 prompt_info/overlays.pl (limited to 'prompt_info') diff --git a/prompt_info/overlays.pl b/prompt_info/overlays.pl new file mode 100644 index 0000000..47a3eef --- /dev/null +++ b/prompt_info/overlays.pl @@ -0,0 +1,89 @@ +# temp place for dumping all the stuff that doesn't belong in uberprompt. + +# overlay := { $num1 => line1, $num2 => line2 } +# line := [ region, region, region ] +# region := { start => x, end => y, ...? } + +my $overlay; + + + +sub _add_overlay_region { + my ($line, $start, $end, $text, $len) = @_; + my $region = { start => $start, + end => $end, + text => $text, + len => $len }; + + my $o_line = $overlay->{$line}; + + unless (defined $o_line) { + $o_line = []; + $overlay->{$line} = $o_line; + } + + foreach my $cur_region (@$o_line) { + if (_region_overlaps($cur_region, $region)) { + # do something. + print "Region overlaps"; + last; + } + } + + push @$o_line, $region; + +} + +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 { + foreach my $line_num (sort keys %$overlay) { + my $line = $overlay->{$line_num}; + + foreach my $region (@$line) { + Irssi::gui_printtext($region->{start}, $line_num, + $region->{text}); + } + } +} + +sub init { + +} +sub _clear_overlay { + Irssi::active_win->view->redraw(); +} + +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_replace.pl b/prompt_info/prompt_replace.pl index 3b28a05..93558de 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -31,70 +31,10 @@ my ($term_w, $term_h) = (0, 0); my ($region_start, $region_end) = (0, 0); -# overlay := { $num1 => line1, $num2 => line2 } -# line := [ region, region, region ] -# region := { start => x, end => y, ...? } - -my $overlay; my $prompt_format; my $prompt_format_str = ''; - -sub _add_overlay_region { - my ($line, $start, $end, $text, $len) = @_; - my $region = { start => $start, - end => $end, - text => $text, - len => $len }; - - my $o_line = $overlay->{$line}; - - unless (defined $o_line) { - $o_line = []; - $overlay->{$line} = $o_line; - } - - foreach my $cur_region (@$o_line) { - if (_region_overlaps($cur_region, $region)) { - # do something. - print "Region overlaps"; - last; - } - } - - push @$o_line, $region; - -} - -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 { - foreach my $line_num (sort keys %$overlay) { - my $line = $overlay->{$line_num}; - - foreach my $region (@$line) { - Irssi::gui_printtext($region->{start}, $line_num, - $region->{text}); - } - } -} - - init(); sub update_terminal_size { @@ -281,31 +221,6 @@ sub _draw_overlay { Irssi::gui_printtext($offset, $term_h, $text); } -sub _clear_overlay { - Irssi::active_win->view->redraw(); -} - -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 replace_prompt_items { # remove existing ones. print "Removing original prompt" if DEBUG; -- cgit v1.2.3 From d205b2cb75d88ea468087d833d92483a141783ce Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 6 Oct 2010 22:29:13 +0100 Subject: general cleanup and refactoring. Need to figure out how to handle regions going backwards as well as forwards. Also better ways to remove them when no longer active. --- prompt_info/prompt_replace.pl | 122 ++++++++++++++++++++++++++++++------------ 1 file changed, 87 insertions(+), 35 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 93558de..9b5d229 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -25,15 +25,15 @@ sub DEBUG () { 1 } my $prompt_data = undef; my $prompt_item = undef; -my $vis_enabled = 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 = ''; - -my $prompt_format; -my $prompt_format_str = ''; +my $prompt_format = ''; init(); @@ -51,30 +51,40 @@ sub update_terminal_size { } } -sub subcmd_handler { +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", \&subcmd_handler); + 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 { $prompt_data = shift; uberprompt_refresh(); }); + sub { Irssi::signal_emit 'change prompt', shift; }); Irssi::command_bind('prompt clear', - sub { undef $prompt_data; uberprompt_refresh(); }); + sub { Irssi::signal_emit 'change prompt', '$p'; }); # misc faff - Irssi::command_bind('visual', \&cmd_toggle_visual); - Irssi::command("^BIND meta-l /visual"); - Irssi::command_bind('menu', \&draw_menu); + 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"); + # redraw interception Irssi::signal_add_last('command redraw', \&augment_redraw); @@ -100,8 +110,30 @@ sub init { # 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) = @_; + + print "Got prompt change sig with: $text" if DEBUG; + + my $changed = ($prompt_data ne $text); + + $prompt_data = $text; + + if ($changed) { + print "Redrawing prompt" if DEBUG; + uberprompt_refresh(); + } } + sub UNLOAD { # remove uberprompt and return the original ones. restore_prompt_items(); @@ -109,10 +141,10 @@ sub UNLOAD { sub reload_settings { my $new = Irssi::settings_get_str('uberprompt_format'); - if ($prompt_format_str ne $new) { - print "Updated prompt format"; - $prompt_format_str = $new; - Irssi::abstracts_register(['uberprompt', $prompt_format_str]); + if ($prompt_format ne $new) { + print "Updated prompt format" if DEBUG; + $prompt_format = $new; + Irssi::abstracts_register(['uberprompt', $prompt_format]); } } @@ -139,7 +171,7 @@ sub uberprompt_draw { } else { $p_copy = $default_prompt; } - print "Redrawing with: $p_copy, size-only: $get_size_only"; + print "Redrawing with: $p_copy, size-only: $get_size_only" if DEBUG; $prompt_item = $sb_item; @@ -147,56 +179,75 @@ sub uberprompt_draw { } sub augment_redraw { - print "Redraw called"; + print "Redraw called" if DEBUG; uberprompt_refresh(); - Irssi::timeout_add_once(10, \&refresh_inputline, 0); + 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 { - $vis_enabled = not $vis_enabled; - if ($vis_enabled) { + + $region_active = not $region_active; + + if ($region_active) { $region_start = _pos(); $region_end = 0; # reset end marker. - print "visual mode started at $region_start"; + print "visual mode started at $region_start" if DEBUG; } else { $region_end = _pos(); - print "Visual mode ended at $region_end"; + 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"; + print "Region selected: $str" if DEBUG; } else { - print "Invalid region selection: [ $region_start - $region_end ]"; + 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) { - print "C-l pressed"; + if ($key == 12) { # C-l + print "C-l pressed" if DEBUG; Irssi::command("redraw"); Irssi::signal_stop(); - } - if ($key == 10) { - $region_end = $region_start = 0; + } elsif ($key == 10) { # RET + _clear_visual_region(); } } sub key_pressed { - my $key = shift; - return unless $vis_enabled; - refresh_inputline(); + # 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 refresh_inputline { +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. @@ -209,9 +260,9 @@ sub refresh_inputline { my $text = substr($input, $region_start, $len); - print "printing '$text' at $offset [$region_start, $end_pos] ($len)"; + print "printing '$text' at $offset [$region_start, $end_pos] ($len)" if DEBUG; - $text = '%k%2' . $text . '%n'; + $text = '%8' . $text . '%8'; _draw_overlay($offset, $text, $len); } @@ -240,6 +291,7 @@ 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 0/); _sbar_command('prompt', 'add', 'prompt_empty', -- cgit v1.2.3 From e28d05be15d078b28fa404ca4bc51d0c427eebbc Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 6 Oct 2010 22:34:04 +0100 Subject: modified the API signal handling to prepend $p by default (as prompt_info sort of worked). --- prompt_info/prompt_replace.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 9b5d229..9abf66d 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -22,7 +22,7 @@ our %IRSSI = sub DEBUG () { 1 } #sub DEBUG () { 0 } -my $prompt_data = undef; +my $prompt_data = ''; my $prompt_item = undef; my $region_active = 0; @@ -121,6 +121,7 @@ sub init { sub change_prompt_sig { my ($text) = @_; + $text = '$p' . $text; print "Got prompt change sig with: $text" if DEBUG; my $changed = ($prompt_data ne $text); -- cgit v1.2.3 From 0bf306b98d9d2493001c6b505533d0928f6cec67 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 6 Oct 2010 22:43:45 +0100 Subject: fixed a bug causing prompt to not get updated properly, and added a nasty compat hack so things expecting prompt_Info will still load. --- prompt_info/prompt_replace.pl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 9abf66d..350d74f 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -22,7 +22,7 @@ our %IRSSI = sub DEBUG () { 1 } #sub DEBUG () { 0 } -my $prompt_data = ''; +my $prompt_data = undef; my $prompt_item = undef; my $region_active = 0; @@ -124,7 +124,8 @@ sub change_prompt_sig { $text = '$p' . $text; print "Got prompt change sig with: $text" if DEBUG; - my $changed = ($prompt_data ne $text); + my $changed; + $changed = defined $prompt_data ? $prompt_data ne $text : 1; $prompt_data = $text; @@ -213,7 +214,7 @@ sub cmd_toggle_visual { 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 ]" + print "Invalid region selection: [ $region_start - $region_end ]" if DEBUG; $region_start = $region_end = 0; } @@ -316,3 +317,8 @@ sub _sbar_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:: = (); -- cgit v1.2.3 From 7b1700479745a48379fecd44d5a07a4436cb0444 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 6 Oct 2010 23:34:52 +0100 Subject: fixed priorities (-1) and position (100) of prompt statusbars --- prompt_info/prompt_replace.pl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 350d74f..3055afc 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -284,8 +284,9 @@ sub replace_prompt_items { # add the new one. _sbar_command('prompt', 'add', 'uberprompt', - qw/-alignment left -before input -priority 0/); + qw/-alignment left -before input -priority '-1'/); + _sbar_command('prompt', 'position', '100'); } sub restore_prompt_items { @@ -295,9 +296,12 @@ sub restore_prompt_items { print "Restoring original prompt" if DEBUG; _sbar_command('prompt', 'add', 'prompt', - qw/-alignment left -before input -priority 0/); + qw/-alignment left -before input -priority '-1'/); _sbar_command('prompt', 'add', 'prompt_empty', - qw/-alignment left -after prompt -priority 0/); + qw/-alignment left -after prompt -priority '-1'/); + + _sbar_command('prompt', 'position', '100'); + } sub _sbar_command { @@ -305,7 +309,7 @@ sub _sbar_command { my $args_str = join ' ', @args; - $args_str .= ' ' if length $args_str; + $args_str .= ' ' if length $args_str && defined $item; my $command = sprintf 'STATUSBAR %s %s %s%s', $bar, $cmd, $args_str, defined($item)?$item:''; -- cgit v1.2.3 From bcb0c884b46815b889e5fd4011226feaba2b3369 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 6 Oct 2010 23:51:10 +0100 Subject: added /print_test to check rev. video stuff is behaving. --- prompt_info/prompt_replace.pl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 3055afc..7c8ecc1 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -46,8 +46,9 @@ sub update_terminal_size { if ($line =~ m/\s*(\d+)\s*rows\s*;\s*(\d+)\s*columns\s*;/) { $term_h = $1; $term_w = $2; + print "terminal size detected as $term_w x $term_h" if DEBUG; } else { - print "Failed to detect terminal size"; + print "Failed to detect terminal size" if DEBUG; } } @@ -85,6 +86,10 @@ sub init { 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); -- cgit v1.2.3 From 695488ce03c85c82d857b5c310c8edf4c0457649 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 7 Oct 2010 00:03:42 +0100 Subject: changed terminal size detection from stty to tput lines/cols --- prompt_info/prompt_replace.pl | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 7c8ecc1..19fa022 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -39,17 +39,14 @@ init(); sub update_terminal_size { - my @stty_lines = qx/stty -a/; - my $line = $stty_lines[0]; - @stty_lines = (); # don't need the rest. - - if ($line =~ m/\s*(\d+)\s*rows\s*;\s*(\d+)\s*columns\s*;/) { - $term_h = $1; - $term_w = $2; - print "terminal size detected as $term_w x $term_h" if DEBUG; - } else { - print "Failed to detect terminal size" if DEBUG; - } + + my $rows = qx/tput lines/; + my $cols = qx/tput cols/; + chomp $rows; + chomp $cols; + + $term_w = $cols; + $term_h = $rows; } sub prompt_subcmd_handler { -- cgit v1.2.3 From 435588d39c7212101b5188a35e4cc953473664c2 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 7 Oct 2010 00:08:17 +0100 Subject: added some debugging output to terminal size detection --- prompt_info/prompt_replace.pl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 19fa022..90bb6f6 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -45,8 +45,10 @@ sub update_terminal_size { chomp $rows; chomp $cols; - $term_w = $cols; - $term_h = $rows; + $term_w = 0+$cols; + $term_h = 0+$rows; + + print "Terminal detected as $term_w cols by $term_h rows" if DEBUG; } sub prompt_subcmd_handler { -- cgit v1.2.3 From 1a4fcd79fd841430365d2e184f82f5e4ac0f736b Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 7 Oct 2010 00:20:27 +0100 Subject: back to stty parsing, with linux and osx cases. Falls back to 80x24 if it doesn't match either. --- prompt_info/prompt_replace.pl | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'prompt_info') diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 90bb6f6..20fb7b1 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -39,14 +39,24 @@ init(); sub update_terminal_size { - - my $rows = qx/tput lines/; - my $cols = qx/tput cols/; - chomp $rows; - chomp $cols; - - $term_w = 0+$cols; - $term_h = 0+$rows; + 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; } -- cgit v1.2.3