# HG changeset patch # User Guido Berhoerster # Date 1426329851 -3600 # Node ID 1964c513723adda9e60af4e65d9843d11dcabf28 Initial revision diff -r 000000000000 -r 1964c513723a README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README Sat Mar 14 11:44:11 2015 +0100 @@ -0,0 +1,83 @@ +slrn Terminal Title Macro +========================= + +The slrn terminal title macro displays user-defined information in the +terminal title if supported by the terminal. + +Usage +----- + +The slrn terminal title macro can be used by including it in the .slrnrc user +initialization file via the `interpret` command, e.g. provided that the file +terminal-title.sl is located in one of the directories specified by the +macro_directory configuration variable: + + interpret "terminal-title.sl" + +The terminal title macro can be configured through the following slang +variables: + +TerminalTitle->article_title_format +: The string displayed in the terminal title in article mode. The string + may contain certain substitution identifiers in order to insert + information from slrn at runtime. + +TerminalTitle->group_title_format +: The string displayed in the terminal title in group mode. The string + may contain certain substitution identifiers in order to insert + information from slrn at runtime. + +Substitution identifiers always start with a "%" sign. The following +substitution identifiers can be referenced from +TerminalTitle->article_title_format and TerminalTitle->group_title_format: + +v +: The slrn version. + +s +: The name of the current news server. + +n +: The name of the current newsgroup. + +Contact +------- + +Please send any feedback, translations or bug reports via email to +. + +Bug Reports +----------- + +When sending bug reports, please always mention the exact version of the +macro with which the issue occurs as well as the version of slrn, slang and +the operating system you are using and make sure that you provide sufficient +information to reproduce the issue and include any input, output, any error +messages and slang stack traces. + +License +------- + +Except otherwise noted, all files are Copyright (C) 2009 Guido Berhoerster and +distributed under the following license terms: + +Copyright (C) 2009 Guido Berhoerster + +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. diff -r 000000000000 -r 1964c513723a terminal-title.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/terminal-title.sl Sat Mar 14 11:44:11 2015 +0100 @@ -0,0 +1,96 @@ +% terminal-title.sl - set the terminal title +% +% Copyright (C) 2009 Guido Berhoerster +% +% 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. + +%open_log_file(make_home_filename("slrn-debug.log")); +%_traceback = 1; + +implements("TerminalTitle"); + +static variable group_substitutions = Assoc_Type[Ref_Type]; +group_substitutions["s"] = &server_name; +group_substitutions["v"] = &_slrn_version_string; + +static variable article_substitutions = Assoc_Type[Ref_Type]; +article_substitutions["s"] = &server_name; +article_substitutions["v"] = &_slrn_version_string; +article_substitutions["n"] = ¤t_newsgroup; + +static variable config = struct +{ + article_title_format = "slrn %v -- Server: %s Group: %n", + group_title_format = "slrn %v -- Server: %s" +}; + +define format_str(str, substitutions) +{ + variable match_pos; + variable match_len; + variable format; + variable temp; + variable formatted_str = ""; + + while (string_match(str, "^\(%-?[0-9]*\(["R + + strjoin(assoc_get_keys(substitutions), "") + "]\)\)"R, 1) || + string_match(str, "\([^%]%-?[0-9]*\(["R + + strjoin(assoc_get_keys(substitutions), "") + "]\)\)"R, 1)) { + (match_pos, match_len) = string_match_nth(1); + temp = substr(str, 1, match_pos); + (temp, ) = strreplace(temp, "%%", "%", strlen(temp)); + format = substr(str, match_pos + 1, match_len - 1) + "s"; + (match_pos, match_len) = string_match_nth(2); + formatted_str += temp + sprintf(format, + @substitutions[substr(str, match_pos + 1, match_len)]); + str = substr(str, match_pos + 1 + match_len, -1); + } + (str, ) = strreplace(str, "%%", "%", strlen(str)); + formatted_str += str; + + return formatted_str; +} + +define set_terminal_title(title) +{ + variable term = getenv("TERM"); + + if (string_match(term, "screen", 1)) { + tt_send("\033_" + title + "\033\\"); + } else if (string_match(term, "xterm", 1)) { + tt_send("\033]0;" + title + "\007"); + } + return; +} + +define set_group_title() +{ + set_terminal_title(format_str(config.group_title_format, + group_substitutions)); +} + +define set_article_title() +{ + set_terminal_title(format_str(config.article_title_format, + article_substitutions)); +} + +() = register_hook("article_mode_hook", "TerminalTitle->set_article_title"); +() = register_hook("group_mode_hook", "TerminalTitle->set_group_title");