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>
31 #define SHOW_MESSAGES_TEMPLATE \
32 "#{t/p:message_time}: #{message_text}"
34 static enum cmd_retval
cmd_show_messages_exec(struct cmd
*,
37 const struct cmd_entry cmd_show_messages_entry
= {
38 .name
= "show-messages",
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
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
;
57 LIST_FOREACH(term
, &tty_terms
, entry
) {
58 if (args_has(args
, 't') && term
!= tc
->tty
.term
)
61 cmdq_print(item
, "%s", "");
64 cmdq_print(item
, "Terminal %u: %s for %s, flags=0x%x:", n
,
65 term
->name
, term
->tty
->client
->name
, term
->flags
);
67 for (i
= 0; i
< tty_term_ncodes(); i
++)
68 cmdq_print(item
, "%s", tty_term_describe(term
, i
));
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
;
80 struct format_tree
*ft
;
83 if (args_has(args
, 'T')) {
84 blank
= cmd_show_messages_terminals(self
, item
, blank
);
87 if (args_has(args
, 'J')) {
88 job_print_summary(item
, blank
);
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
);
106 return (CMD_RETURN_NORMAL
);