changeset 0:1964c513723a

Initial revision
author Guido Berhoerster <guido+slrn@berhoerster.name>
date Sat, 14 Mar 2015 11:44:11 +0100
parents
children b5ca94cc74ae
files README terminal-title.sl
diffstat 2 files changed, 179 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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
+<guido+weechat@berhoerster.name>.
+
+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 <guido+slrn@berhoerster.name>
+
+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.
--- /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 <guido+slrn@berhoerster.name>
+%
+% 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"] = &current_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");