Merge branch 'obsd-master'
[tmux.git] / cmd-show-messages.c
blobdca3ab31347f2d4096109d091ce12b7482291090
1 /* $OpenBSD$ */
3 /*
4 * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
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.
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.
19 #include <sys/types.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
25 #include "tmux.h"
28 * Show message log.
31 #define SHOW_MESSAGES_TEMPLATE \
32 "#{t/p:message_time}: #{message_text}"
34 static enum cmd_retval cmd_show_messages_exec(struct cmd *,
35 struct cmdq_item *);
37 const struct cmd_entry cmd_show_messages_entry = {
38 .name = "show-messages",
39 .alias = "showmsgs",
41 .args = { "JTt:", 0, 0, NULL },
42 .usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
44 .flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
45 .exec = cmd_show_messages_exec
48 static int
49 cmd_show_messages_terminals(struct cmd *self, struct cmdq_item *item, int blank)
51 struct args *args = cmd_get_args(self);
52 struct client *tc = cmdq_get_target_client(item);
53 struct tty_term *term;
54 u_int i, n;
56 n = 0;
57 LIST_FOREACH(term, &tty_terms, entry) {
58 if (args_has(args, 't') && term != tc->tty.term)
59 continue;
60 if (blank) {
61 cmdq_print(item, "%s", "");
62 blank = 0;
64 cmdq_print(item, "Terminal %u: %s for %s, flags=0x%x:", n,
65 term->name, term->tty->client->name, term->flags);
66 n++;
67 for (i = 0; i < tty_term_ncodes(); i++)
68 cmdq_print(item, "%s", tty_term_describe(term, i));
70 return (n != 0);
73 static enum cmd_retval
74 cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item)
76 struct args *args = cmd_get_args(self);
77 struct message_entry *msg;
78 char *s;
79 int done, blank;
80 struct format_tree *ft;
82 done = blank = 0;
83 if (args_has(args, 'T')) {
84 blank = cmd_show_messages_terminals(self, item, blank);
85 done = 1;
87 if (args_has(args, 'J')) {
88 job_print_summary(item, blank);
89 done = 1;
91 if (done)
92 return (CMD_RETURN_NORMAL);
94 ft = format_create_from_target(item);
95 TAILQ_FOREACH_REVERSE(msg, &message_log, message_list, entry) {
96 format_add(ft, "message_text", "%s", msg->msg);
97 format_add(ft, "message_number", "%u", msg->msg_num);
98 format_add_tv(ft, "message_time", &msg->msg_time);
100 s = format_expand(ft, SHOW_MESSAGES_TEMPLATE);
101 cmdq_print(item, "%s", s);
102 free(s);
104 format_free(ft);
106 return (CMD_RETURN_NORMAL);