cmd-show-messages.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* $OpenBSD$ */
  2. /*
  3. * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
  14. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  15. * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <sys/types.h>
  18. #include <string.h>
  19. #include <time.h>
  20. #include <unistd.h>
  21. #include "tmux.h"
  22. /*
  23. * Show client message log.
  24. */
  25. enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_q *);
  26. const struct cmd_entry cmd_show_messages_entry = {
  27. .name = "show-messages",
  28. .alias = "showmsgs",
  29. .args = { "JTt:", 0, 0 },
  30. .usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
  31. .tflag = CMD_CLIENT,
  32. .flags = 0,
  33. .exec = cmd_show_messages_exec
  34. };
  35. const struct cmd_entry cmd_server_info_entry = {
  36. .name = "server-info",
  37. .alias = "info",
  38. .args = { "", 0, 0 },
  39. .usage = "",
  40. .flags = 0,
  41. .exec = cmd_show_messages_exec
  42. };
  43. int cmd_show_messages_terminals(struct cmd_q *, int);
  44. int cmd_show_messages_jobs(struct cmd_q *, int);
  45. int
  46. cmd_show_messages_terminals(struct cmd_q *cmdq, int blank)
  47. {
  48. struct tty_term *term;
  49. u_int i, n;
  50. n = 0;
  51. LIST_FOREACH(term, &tty_terms, entry) {
  52. if (blank) {
  53. cmdq_print(cmdq, "%s", "");
  54. blank = 0;
  55. }
  56. cmdq_print(cmdq, "Terminal %u: %s [references=%u, flags=0x%x]:",
  57. n, term->name, term->references, term->flags);
  58. n++;
  59. for (i = 0; i < tty_term_ncodes(); i++)
  60. cmdq_print(cmdq, "%s", tty_term_describe(term, i));
  61. }
  62. return (n != 0);
  63. }
  64. int
  65. cmd_show_messages_jobs(struct cmd_q *cmdq, int blank)
  66. {
  67. struct job *job;
  68. u_int n;
  69. n = 0;
  70. LIST_FOREACH(job, &all_jobs, lentry) {
  71. if (blank) {
  72. cmdq_print(cmdq, "%s", "");
  73. blank = 0;
  74. }
  75. cmdq_print(cmdq, "Job %u: %s [fd=%d, pid=%d, status=%d]",
  76. n, job->cmd, job->fd, job->pid, job->status);
  77. n++;
  78. }
  79. return (n != 0);
  80. }
  81. enum cmd_retval
  82. cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq)
  83. {
  84. struct args *args = self->args;
  85. struct client *c = cmdq->state.c;
  86. struct message_entry *msg;
  87. char *tim;
  88. int done, blank;
  89. done = blank = 0;
  90. if (args_has(args, 'T') || self->entry == &cmd_server_info_entry) {
  91. blank = cmd_show_messages_terminals(cmdq, blank);
  92. done = 1;
  93. }
  94. if (args_has(args, 'J') || self->entry == &cmd_server_info_entry) {
  95. cmd_show_messages_jobs(cmdq, blank);
  96. done = 1;
  97. }
  98. if (done)
  99. return (CMD_RETURN_NORMAL);
  100. TAILQ_FOREACH(msg, &c->message_log, entry) {
  101. tim = ctime(&msg->msg_time);
  102. *strchr(tim, '\n') = '\0';
  103. cmdq_print(cmdq, "%s %s", tim, msg->msg);
  104. }
  105. return (CMD_RETURN_NORMAL);
  106. }