Annotation of src/usr.bin/tmux/cmd-show-messages.c, Revision 1.26
1.26 ! nicm 1: /* $OpenBSD: cmd-show-messages.c,v 1.25 2017/03/17 14:51:41 nicm Exp $ */
1.1 nicm 2:
3: /*
1.20 nicm 4: * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1 nicm 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>
1.8 nicm 23: #include <unistd.h>
24: #include <vis.h>
1.1 nicm 25:
26: #include "tmux.h"
27:
28: /*
29: * Show client message log.
30: */
31:
1.23 nicm 32: static enum cmd_retval cmd_show_messages_exec(struct cmd *,
33: struct cmdq_item *);
1.1 nicm 34:
35: const struct cmd_entry cmd_show_messages_entry = {
1.18 nicm 36: .name = "show-messages",
37: .alias = "showmsgs",
38:
39: .args = { "JTt:", 0, 0 },
40: .usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
41:
1.19 nicm 42: .tflag = CMD_CLIENT,
43:
1.22 nicm 44: .flags = CMD_AFTERHOOK,
1.18 nicm 45: .exec = cmd_show_messages_exec
1.1 nicm 46: };
47:
1.23 nicm 48: static int cmd_show_messages_terminals(struct cmdq_item *, int);
49: static int cmd_show_messages_jobs(struct cmdq_item *, int);
1.8 nicm 50:
1.21 nicm 51: static int
1.23 nicm 52: cmd_show_messages_terminals(struct cmdq_item *item, int blank)
1.8 nicm 53: {
1.13 nicm 54: struct tty_term *term;
55: u_int i, n;
1.8 nicm 56:
57: n = 0;
58: LIST_FOREACH(term, &tty_terms, entry) {
1.12 nicm 59: if (blank) {
1.23 nicm 60: cmdq_print(item, "%s", "");
1.12 nicm 61: blank = 0;
62: }
1.23 nicm 63: cmdq_print(item, "Terminal %u: %s [references=%u, flags=0x%x]:",
1.8 nicm 64: n, term->name, term->references, term->flags);
65: n++;
1.13 nicm 66: for (i = 0; i < tty_term_ncodes(); i++)
1.23 nicm 67: cmdq_print(item, "%s", tty_term_describe(term, i));
1.8 nicm 68: }
1.12 nicm 69: return (n != 0);
1.8 nicm 70: }
71:
1.21 nicm 72: static int
1.23 nicm 73: cmd_show_messages_jobs(struct cmdq_item *item, int blank)
1.8 nicm 74: {
75: struct job *job;
76: u_int n;
77:
78: n = 0;
1.26 ! nicm 79: LIST_FOREACH(job, &all_jobs, entry) {
1.12 nicm 80: if (blank) {
1.23 nicm 81: cmdq_print(item, "%s", "");
1.12 nicm 82: blank = 0;
83: }
1.25 nicm 84: cmdq_print(item, "Job %u: %s [fd=%d, pid=%ld, status=%d]",
85: n, job->cmd, job->fd, (long)job->pid, job->status);
1.8 nicm 86: n++;
87: }
1.12 nicm 88: return (n != 0);
1.8 nicm 89: }
90:
1.21 nicm 91: static enum cmd_retval
1.23 nicm 92: cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item)
1.1 nicm 93: {
1.3 nicm 94: struct args *args = self->args;
1.23 nicm 95: struct client *c = item->state.c;
1.3 nicm 96: struct message_entry *msg;
97: char *tim;
1.12 nicm 98: int done, blank;
1.8 nicm 99:
1.12 nicm 100: done = blank = 0;
1.24 nicm 101: if (args_has(args, 'T')) {
1.23 nicm 102: blank = cmd_show_messages_terminals(item, blank);
1.8 nicm 103: done = 1;
104: }
1.24 nicm 105: if (args_has(args, 'J')) {
1.23 nicm 106: cmd_show_messages_jobs(item, blank);
1.8 nicm 107: done = 1;
108: }
109: if (done)
110: return (CMD_RETURN_NORMAL);
1.1 nicm 111:
1.11 nicm 112: TAILQ_FOREACH(msg, &c->message_log, entry) {
1.1 nicm 113: tim = ctime(&msg->msg_time);
114: *strchr(tim, '\n') = '\0';
1.2 nicm 115:
1.23 nicm 116: cmdq_print(item, "%s %s", tim, msg->msg);
1.1 nicm 117: }
118:
1.4 nicm 119: return (CMD_RETURN_NORMAL);
1.1 nicm 120: }