[BACK]Return to cmd-show-messages.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/cmd-show-messages.c, Revision 1.22

1.22    ! nicm        1: /* $OpenBSD: cmd-show-messages.c,v 1.21 2016/10/10 21:51:39 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.21      nicm       32: static enum cmd_retval  cmd_show_messages_exec(struct cmd *, struct cmd_q *);
1.1       nicm       33:
                     34: const struct cmd_entry cmd_show_messages_entry = {
1.18      nicm       35:        .name = "show-messages",
                     36:        .alias = "showmsgs",
                     37:
                     38:        .args = { "JTt:", 0, 0 },
                     39:        .usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
                     40:
1.19      nicm       41:        .tflag = CMD_CLIENT,
                     42:
1.22    ! nicm       43:        .flags = CMD_AFTERHOOK,
1.18      nicm       44:        .exec = cmd_show_messages_exec
1.1       nicm       45: };
                     46:
1.8       nicm       47: const struct cmd_entry cmd_server_info_entry = {
1.18      nicm       48:        .name = "server-info",
                     49:        .alias = "info",
                     50:
                     51:        .args = { "", 0, 0 },
                     52:        .usage = "",
                     53:
1.22    ! nicm       54:        .flags = CMD_AFTERHOOK,
1.18      nicm       55:        .exec = cmd_show_messages_exec
1.8       nicm       56: };
                     57:
1.21      nicm       58: static int     cmd_show_messages_terminals(struct cmd_q *, int);
                     59: static int     cmd_show_messages_jobs(struct cmd_q *, int);
1.8       nicm       60:
1.21      nicm       61: static int
1.12      nicm       62: cmd_show_messages_terminals(struct cmd_q *cmdq, int blank)
1.8       nicm       63: {
1.13      nicm       64:        struct tty_term *term;
                     65:        u_int            i, n;
1.8       nicm       66:
                     67:        n = 0;
                     68:        LIST_FOREACH(term, &tty_terms, entry) {
1.12      nicm       69:                if (blank) {
                     70:                        cmdq_print(cmdq, "%s", "");
                     71:                        blank = 0;
                     72:                }
                     73:                cmdq_print(cmdq, "Terminal %u: %s [references=%u, flags=0x%x]:",
1.8       nicm       74:                    n, term->name, term->references, term->flags);
                     75:                n++;
1.13      nicm       76:                for (i = 0; i < tty_term_ncodes(); i++)
                     77:                        cmdq_print(cmdq, "%s", tty_term_describe(term, i));
1.8       nicm       78:        }
1.12      nicm       79:        return (n != 0);
1.8       nicm       80: }
                     81:
1.21      nicm       82: static int
1.12      nicm       83: cmd_show_messages_jobs(struct cmd_q *cmdq, int blank)
1.8       nicm       84: {
                     85:        struct job      *job;
                     86:        u_int            n;
                     87:
                     88:        n = 0;
                     89:        LIST_FOREACH(job, &all_jobs, lentry) {
1.12      nicm       90:                if (blank) {
                     91:                        cmdq_print(cmdq, "%s", "");
                     92:                        blank = 0;
                     93:                }
                     94:                cmdq_print(cmdq, "Job %u: %s [fd=%d, pid=%d, status=%d]",
1.8       nicm       95:                    n, job->cmd, job->fd, job->pid, job->status);
                     96:                n++;
                     97:        }
1.12      nicm       98:        return (n != 0);
1.8       nicm       99: }
                    100:
1.21      nicm      101: static enum cmd_retval
1.6       nicm      102: cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq)
1.1       nicm      103: {
1.3       nicm      104:        struct args             *args = self->args;
1.17      nicm      105:        struct client           *c = cmdq->state.c;
1.3       nicm      106:        struct message_entry    *msg;
                    107:        char                    *tim;
1.12      nicm      108:        int                      done, blank;
1.8       nicm      109:
1.12      nicm      110:        done = blank = 0;
1.9       nicm      111:        if (args_has(args, 'T') || self->entry == &cmd_server_info_entry) {
1.12      nicm      112:                blank = cmd_show_messages_terminals(cmdq, blank);
1.8       nicm      113:                done = 1;
                    114:        }
1.9       nicm      115:        if (args_has(args, 'J') || self->entry == &cmd_server_info_entry) {
1.12      nicm      116:                cmd_show_messages_jobs(cmdq, blank);
1.8       nicm      117:                done = 1;
                    118:        }
                    119:        if (done)
                    120:                return (CMD_RETURN_NORMAL);
1.1       nicm      121:
1.11      nicm      122:        TAILQ_FOREACH(msg, &c->message_log, entry) {
1.1       nicm      123:                tim = ctime(&msg->msg_time);
                    124:                *strchr(tim, '\n') = '\0';
1.2       nicm      125:
1.6       nicm      126:                cmdq_print(cmdq, "%s %s", tim, msg->msg);
1.1       nicm      127:        }
                    128:
1.4       nicm      129:        return (CMD_RETURN_NORMAL);
1.1       nicm      130: }