diff options
-rw-r--r-- | prompt_info/uberprompt.pl | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index add8503..b4376ea 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -297,12 +297,14 @@ sub DEBUG { $DEBUG_ENABLED } my $prompt_data = ''; my $prompt_data_pos = 'UP_INNER'; -my $prompt_last = ''; -my $prompt_format = ''; +my $prompt_last = ''; +my $prompt_format = ''; +my $prompt_format_empty = ''; # flag to indicate whether rendering of hte prompt should allow the replaces # theme formats to be applied to the content. my $use_replaces = 0; +my $trim_data = 0; my $emit_request = 0; @@ -363,12 +365,15 @@ sub _print_help { "", "See Also:", '', - '/SET uberprompt_format -- defaults to [$*$uber]', - "/SET uberprompt_autostart -- determines whether /PROMPT ON is run", - " automatically when the script loads", - "/set uberprompt_use_replaces -- toggles the use of the current theme", + '/SET uberprompt_format -- defaults to "[$*$uber] "', + '/SET uberprompt_format_empty -- defaults to "[$*] "', + "/SET uberprompt_autostart -- determines whether /PROMPT ON is run", + " automatically when the script loads", + "/SET uberprompt_use_replaces -- toggles the use of the current theme", " \"replaces\" setting. Especially", " noticeable on brackets \"[ ]\" ", + "/SET uberprompt_trim_data -- defaults to off. Removes whitespace from", + " both sides of the $uber result.", "", ); @@ -403,6 +408,7 @@ sub init { Irssi::expando_create('rbrace', \&exp_rbrace, {}); Irssi::settings_add_str ('uberprompt', 'uberprompt_format', '[$*$uber] '); + Irssi::settings_add_str ('uberprompt', 'uberprompt_format_empty', '[$*] '); Irssi::settings_add_str ('uberprompt', 'uberprompt_load_hook', ''); Irssi::settings_add_str ('uberprompt', 'uberprompt_unload_hook', ''); @@ -412,7 +418,7 @@ sub init { Irssi::settings_add_bool ('uberprompt', 'uberprompt_restore_on_exit', 1); Irssi::settings_add_bool('uberprompt', 'uberprompt_use_replaces', 0); - + Irssi::settings_add_bool('uberprompt', 'uberprompt_trim_data', 0); Irssi::command_bind("prompt", \&prompt_subcmd_handler); Irssi::command_bind('prompt on', \&replace_prompt_items); @@ -549,6 +555,28 @@ sub reload_settings { $expando_vars->{$var_name} = Irssi::parse_special($1); } } + + $new = Irssi::settings_get_str('uberprompt_format_empty'); + + if ($prompt_format_empty ne $new) { + _debug_print("Updated prompt format"); + $prompt_format_empty = $new; + $prompt_format_empty =~ s/\$uber/\$\$uber/; + Irssi::abstracts_register(['uberprompt_empty', $prompt_format_empty]); + + $expando_vars = {}; + + # TODO: something clever here to check if we need to schedule + # an update timer or something, rather than just refreshing on + # every possible activity in init() + while ($prompt_format_empty =~ m/(?<!\$)(\$[A-Za-z,.:;][a-z_]*)/g) { + _debug_print("Detected Irssi expando variable $1"); + my $var_name = substr $1, 1; # strip the $ + $expando_vars->{$var_name} = Irssi::parse_special($1); + } + } + + $trim_data = Irssi::settings_get_bool('uberprompt_trim_data'); } sub debug_prompt_changed { @@ -607,7 +635,13 @@ sub uberprompt_render_prompt { my $theme = Irssi::current_theme; my $arg = $use_replaces ? 0 : Irssi::EXPAND_FLAG_IGNORE_REPLACES; - $prompt = $theme->format_expand("{uberprompt $prompt_arg}", $arg); + + if ($prompt_data && (!$trim_data || trim($prompt_data))) { + $prompt = $theme->format_expand("{uberprompt $prompt_arg}", $arg); + } + else { + $prompt = $theme->format_expand("{uberprompt_empty $prompt_arg}", $arg); + } if ($prompt_data_pos eq 'UP_ONLY') { $prompt =~ s/\$\$uber//; # no need for recursive prompting, I hope. @@ -626,6 +660,7 @@ sub uberprompt_render_prompt { } elsif ($prompt_data_pos eq 'UP_INNER' && defined $prompt_data) { my $esc = _escape_prompt_special($prompt_data); + $esc = $trim_data ? trim($esc) : $esc; $prompt =~ s/\$\$uber/$esc/; } else { @@ -729,3 +764,11 @@ sub _sbar_command { Irssi::command($command); } +sub trim { + my $string = shift; + + $string =~ s/^\s*//; + $string =~ s/\s*$//; + + return $string; +} |