[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.33

1.33    ! nicm        1: /* $OpenBSD: cmd-show-messages.c,v 1.32 2020/04/20 13:25:36 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.30      nicm       42:        .flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
1.18      nicm       43:        .exec = cmd_show_messages_exec
1.1       nicm       44: };
                     45:
1.21      nicm       46: static int
1.32      nicm       47: cmd_show_messages_terminals(struct cmd *self, struct cmdq_item *item, int blank)
1.8       nicm       48: {
1.32      nicm       49:        struct args     *args = cmd_get_args(self);
                     50:        struct client   *tc = cmdq_get_target_client(item);
1.13      nicm       51:        struct tty_term *term;
                     52:        u_int            i, n;
1.8       nicm       53:
                     54:        n = 0;
                     55:        LIST_FOREACH(term, &tty_terms, entry) {
1.32      nicm       56:                if (args_has(args, 't') && term != tc->tty.term)
                     57:                        continue;
1.12      nicm       58:                if (blank) {
1.23      nicm       59:                        cmdq_print(item, "%s", "");
1.12      nicm       60:                        blank = 0;
                     61:                }
1.32      nicm       62:                cmdq_print(item, "Terminal %u: %s for %s, flags=0x%x:", n,
                     63:                    term->name, term->tty->client->name, term->flags);
1.8       nicm       64:                n++;
1.13      nicm       65:                for (i = 0; i < tty_term_ncodes(); i++)
1.23      nicm       66:                        cmdq_print(item, "%s", tty_term_describe(term, i));
1.8       nicm       67:        }
1.12      nicm       68:        return (n != 0);
1.8       nicm       69: }
                     70:
1.21      nicm       71: static enum cmd_retval
1.23      nicm       72: cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item)
1.1       nicm       73: {
1.29      nicm       74:        struct args             *args = cmd_get_args(self);
1.3       nicm       75:        struct message_entry    *msg;
1.33    ! nicm       76:        char                    *s;
1.12      nicm       77:        int                      done, blank;
1.33    ! nicm       78:        struct format_tree      *ft;
1.8       nicm       79:
1.12      nicm       80:        done = blank = 0;
1.24      nicm       81:        if (args_has(args, 'T')) {
1.32      nicm       82:                blank = cmd_show_messages_terminals(self, item, blank);
1.8       nicm       83:                done = 1;
                     84:        }
1.24      nicm       85:        if (args_has(args, 'J')) {
1.28      nicm       86:                job_print_summary(item, blank);
1.8       nicm       87:                done = 1;
                     88:        }
                     89:        if (done)
                     90:                return (CMD_RETURN_NORMAL);
1.1       nicm       91:
1.33    ! nicm       92:        ft = format_create_from_target(item);
        !            93:        TAILQ_FOREACH_REVERSE(msg, &message_log, message_list, entry) {
        !            94:                format_add(ft, "message_text", "%s", msg->msg);
        !            95:                format_add(ft, "message_number", "%u", msg->msg_num);
        !            96:                format_add_tv(ft, "message_time", &msg->msg_time);
        !            97:
        !            98:                s = format_expand(ft, SHOW_MESSAGES_TEMPLATE);
        !            99:                cmdq_print(item, "%s", s);
        !           100:                free(s);
1.1       nicm      101:        }
1.33    ! nicm      102:        format_free(ft);
1.1       nicm      103:
1.4       nicm      104:        return (CMD_RETURN_NORMAL);
1.1       nicm      105: }