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