Mercurial > addons > slrn-macros > slrn-terminal-title-macro
annotate terminal-title.sl @ 1:b5ca94cc74ae default tip
Change license to GPL-2.0+
author | Guido Berhoerster <guido+slrn@berhoerster.name> |
---|---|
date | Sat, 25 Jul 2015 17:12:50 +0200 |
parents | 1964c513723a |
children |
rev | line source |
---|---|
0
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
1 % terminal-title.sl - set the terminal title |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
2 % |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
3 % Copyright (C) 2009 Guido Berhoerster <guido+slrn@berhoerster.name> |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
4 % |
1
b5ca94cc74ae
Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
0
diff
changeset
|
5 % This program is free software; you can redistribute it and/or |
b5ca94cc74ae
Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
0
diff
changeset
|
6 % modify it under the terms of the GNU General Public License |
b5ca94cc74ae
Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
0
diff
changeset
|
7 % as published by the Free Software Foundation; either version 2 |
b5ca94cc74ae
Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
0
diff
changeset
|
8 % of the License, or (at your option) any later version. |
0
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
9 % |
1
b5ca94cc74ae
Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
0
diff
changeset
|
10 % This program is distributed in the hope that it will be useful, |
b5ca94cc74ae
Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
0
diff
changeset
|
11 % but WITHOUT ANY WARRANTY; without even the implied warranty of |
b5ca94cc74ae
Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
0
diff
changeset
|
12 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b5ca94cc74ae
Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
0
diff
changeset
|
13 % GNU General Public License for more details. |
0
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
14 % |
1
b5ca94cc74ae
Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
0
diff
changeset
|
15 % You should have received a copy of the GNU General Public License |
b5ca94cc74ae
Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
0
diff
changeset
|
16 % along with this program; if not, write to the Free Software |
b5ca94cc74ae
Change license to GPL-2.0+
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
0
diff
changeset
|
17 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
0
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
18 |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
19 %open_log_file(make_home_filename("slrn-debug.log")); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
20 %_traceback = 1; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
21 |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
22 implements("TerminalTitle"); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
23 |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
24 static variable group_substitutions = Assoc_Type[Ref_Type]; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
25 group_substitutions["s"] = &server_name; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
26 group_substitutions["v"] = &_slrn_version_string; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
27 |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
28 static variable article_substitutions = Assoc_Type[Ref_Type]; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
29 article_substitutions["s"] = &server_name; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
30 article_substitutions["v"] = &_slrn_version_string; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
31 article_substitutions["n"] = ¤t_newsgroup; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
32 |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
33 static variable config = struct |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
34 { |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
35 article_title_format = "slrn %v -- Server: %s Group: %n", |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
36 group_title_format = "slrn %v -- Server: %s" |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
37 }; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
38 |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
39 define format_str(str, substitutions) |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
40 { |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
41 variable match_pos; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
42 variable match_len; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
43 variable format; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
44 variable temp; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
45 variable formatted_str = ""; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
46 |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
47 while (string_match(str, "^\(%-?[0-9]*\(["R + |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
48 strjoin(assoc_get_keys(substitutions), "") + "]\)\)"R, 1) || |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
49 string_match(str, "\([^%]%-?[0-9]*\(["R + |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
50 strjoin(assoc_get_keys(substitutions), "") + "]\)\)"R, 1)) { |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
51 (match_pos, match_len) = string_match_nth(1); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
52 temp = substr(str, 1, match_pos); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
53 (temp, ) = strreplace(temp, "%%", "%", strlen(temp)); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
54 format = substr(str, match_pos + 1, match_len - 1) + "s"; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
55 (match_pos, match_len) = string_match_nth(2); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
56 formatted_str += temp + sprintf(format, |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
57 @substitutions[substr(str, match_pos + 1, match_len)]); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
58 str = substr(str, match_pos + 1 + match_len, -1); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
59 } |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
60 (str, ) = strreplace(str, "%%", "%", strlen(str)); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
61 formatted_str += str; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
62 |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
63 return formatted_str; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
64 } |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
65 |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
66 define set_terminal_title(title) |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
67 { |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
68 variable term = getenv("TERM"); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
69 |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
70 if (string_match(term, "screen", 1)) { |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
71 tt_send("\033_" + title + "\033\\"); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
72 } else if (string_match(term, "xterm", 1)) { |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
73 tt_send("\033]0;" + title + "\007"); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
74 } |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
75 return; |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
76 } |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
77 |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
78 define set_group_title() |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
79 { |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
80 set_terminal_title(format_str(config.group_title_format, |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
81 group_substitutions)); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
82 } |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
83 |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
84 define set_article_title() |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
85 { |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
86 set_terminal_title(format_str(config.article_title_format, |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
87 article_substitutions)); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
88 } |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
89 |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
90 () = register_hook("article_mode_hook", "TerminalTitle->set_article_title"); |
1964c513723a
Initial revision
Guido Berhoerster <guido+slrn@berhoerster.name>
parents:
diff
changeset
|
91 () = register_hook("group_mode_hook", "TerminalTitle->set_group_title"); |