/src/tmux/cmd-show-messages.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* $OpenBSD$ */ |
2 | | |
3 | | /* |
4 | | * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> |
5 | | * |
6 | | * Permission to use, copy, modify, and distribute this software for any |
7 | | * purpose with or without fee is hereby granted, provided that the above |
8 | | * copyright notice and this permission notice appear in all copies. |
9 | | * |
10 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
12 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
13 | | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
14 | | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER |
15 | | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING |
16 | | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 | | */ |
18 | | |
19 | | #include <sys/types.h> |
20 | | |
21 | | #include <stdlib.h> |
22 | | #include <string.h> |
23 | | #include <unistd.h> |
24 | | |
25 | | #include "tmux.h" |
26 | | |
27 | | /* |
28 | | * Show message log. |
29 | | */ |
30 | | |
31 | | #define SHOW_MESSAGES_TEMPLATE \ |
32 | 0 | "#{t/p:message_time}: #{message_text}" |
33 | | |
34 | | static enum cmd_retval cmd_show_messages_exec(struct cmd *, |
35 | | struct cmdq_item *); |
36 | | |
37 | | const struct cmd_entry cmd_show_messages_entry = { |
38 | | .name = "show-messages", |
39 | | .alias = "showmsgs", |
40 | | |
41 | | .args = { "JTt:", 0, 0, NULL }, |
42 | | .usage = "[-JT] " CMD_TARGET_CLIENT_USAGE, |
43 | | |
44 | | .flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG, |
45 | | .exec = cmd_show_messages_exec |
46 | | }; |
47 | | |
48 | | static int |
49 | | cmd_show_messages_terminals(struct cmd *self, struct cmdq_item *item, int blank) |
50 | 0 | { |
51 | 0 | struct args *args = cmd_get_args(self); |
52 | 0 | struct client *tc = cmdq_get_target_client(item); |
53 | 0 | struct tty_term *term; |
54 | 0 | u_int i, n; |
55 | |
|
56 | 0 | n = 0; |
57 | 0 | LIST_FOREACH(term, &tty_terms, entry) { |
58 | 0 | if (args_has(args, 't') && term != tc->tty.term) |
59 | 0 | continue; |
60 | 0 | if (blank) { |
61 | 0 | cmdq_print(item, "%s", ""); |
62 | 0 | blank = 0; |
63 | 0 | } |
64 | 0 | cmdq_print(item, "Terminal %u: %s for %s, flags=0x%x:", n, |
65 | 0 | term->name, term->tty->client->name, term->flags); |
66 | 0 | n++; |
67 | 0 | for (i = 0; i < tty_term_ncodes(); i++) |
68 | 0 | cmdq_print(item, "%s", tty_term_describe(term, i)); |
69 | 0 | } |
70 | 0 | return (n != 0); |
71 | 0 | } |
72 | | |
73 | | static enum cmd_retval |
74 | | cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item) |
75 | 0 | { |
76 | 0 | struct args *args = cmd_get_args(self); |
77 | 0 | struct message_entry *msg; |
78 | 0 | char *s; |
79 | 0 | int done, blank; |
80 | 0 | struct format_tree *ft; |
81 | |
|
82 | 0 | done = blank = 0; |
83 | 0 | if (args_has(args, 'T')) { |
84 | 0 | blank = cmd_show_messages_terminals(self, item, blank); |
85 | 0 | done = 1; |
86 | 0 | } |
87 | 0 | if (args_has(args, 'J')) { |
88 | 0 | job_print_summary(item, blank); |
89 | 0 | done = 1; |
90 | 0 | } |
91 | 0 | if (done) |
92 | 0 | return (CMD_RETURN_NORMAL); |
93 | | |
94 | 0 | ft = format_create_from_target(item); |
95 | 0 | TAILQ_FOREACH_REVERSE(msg, &message_log, message_list, entry) { |
96 | 0 | format_add(ft, "message_text", "%s", msg->msg); |
97 | 0 | format_add(ft, "message_number", "%u", msg->msg_num); |
98 | 0 | format_add_tv(ft, "message_time", &msg->msg_time); |
99 | |
|
100 | 0 | s = format_expand(ft, SHOW_MESSAGES_TEMPLATE); |
101 | 0 | cmdq_print(item, "%s", s); |
102 | 0 | free(s); |
103 | 0 | } |
104 | 0 | format_free(ft); |
105 | |
|
106 | 0 | return (CMD_RETURN_NORMAL); |
107 | 0 | } |