1/* $OpenBSD$ */
2
3/*
4 * Copyright (c) 2009 Nicholas Marriott <[email protected]>
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 <string.h>
22#include <time.h>
23#include <unistd.h>
24
25#include "tmux.h"
26
27/*
28 * Show client message log.
29 */
30
31static enum cmd_retval cmd_show_messages_exec(struct cmd *,
32 struct cmdq_item *);
33
34const struct cmd_entry cmd_show_messages_entry = {
35 .name = "show-messages",
36 .alias = "showmsgs",
37
38 .args = { "JTt:", 0, 0 },
39 .usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
40
41 .flags = CMD_AFTERHOOK,
42 .exec = cmd_show_messages_exec
43};
44
45static int cmd_show_messages_terminals(struct cmdq_item *, int);
46
47static int
48cmd_show_messages_terminals(struct cmdq_item *item, int blank)
49{
50 struct tty_term *term;
51 u_int i, n;
52
53 n = 0;
54 LIST_FOREACH(term, &tty_terms, entry) {
55 if (blank) {
56 cmdq_print(item, "%s", "");
57 blank = 0;
58 }
59 cmdq_print(item, "Terminal %u: %s [references=%u, flags=0x%x]:",
60 n, term->name, term->references, term->flags);
61 n++;
62 for (i = 0; i < tty_term_ncodes(); i++)
63 cmdq_print(item, "%s", tty_term_describe(term, i));
64 }
65 return (n != 0);
66}
67
68static enum cmd_retval
69cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item)
70{
71 struct args *args = self->args;
72 struct client *c;
73 struct message_entry *msg;
74 char *tim;
75 int done, blank;
76
77 if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
78 return (CMD_RETURN_ERROR);
79
80 done = blank = 0;
81 if (args_has(args, 'T')) {
82 blank = cmd_show_messages_terminals(item, blank);
83 done = 1;
84 }
85 if (args_has(args, 'J')) {
86 job_print_summary(item, blank);
87 done = 1;
88 }
89 if (done)
90 return (CMD_RETURN_NORMAL);
91
92 TAILQ_FOREACH(msg, &c->message_log, entry) {
93 tim = ctime(&msg->msg_time);
94 *strchr(tim, '\n') = '\0';
95
96 cmdq_print(item, "%s %s", tim, msg->msg);
97 }
98
99 return (CMD_RETURN_NORMAL);
100}
101