blob: 8d0f778b8c69d6819490c46e6acf42e133e6ddbd [file] [log] [blame] [raw]
Nicholas Marriotte7f68a02008-01-03 19:18:14 +00001/* $Id: status.c,v 1.16 2008-01-03 19:18:14 nicm Exp $ */
Nicholas Marriottbfccbc62007-10-01 14:53:29 +00002
3/*
4 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
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 <stdarg.h>
22
23#include "tmux.h"
24
Nicholas Marriottc0572ea2007-11-20 18:11:37 +000025void printflike3 status_print(struct buffer *, size_t *, const char *, ...);
Nicholas Marriottbfccbc62007-10-01 14:53:29 +000026
27void
Nicholas Marriott76c8a592007-11-27 19:23:34 +000028status_write_client(struct client *c)
Nicholas Marriottbfccbc62007-10-01 14:53:29 +000029{
Nicholas Marriott103748d2007-12-06 09:46:23 +000030 struct screen_redraw_ctx ctx;
31 struct winlink *wl;
32 char flag;
Nicholas Marriottbfccbc62007-10-01 14:53:29 +000033
Nicholas Marriott76c8a592007-11-27 19:23:34 +000034 if (status_lines == 0 || c->sy <= status_lines)
35 return;
Nicholas Marriottbfccbc62007-10-01 14:53:29 +000036
Nicholas Marriott103748d2007-12-06 09:46:23 +000037 screen_redraw_start_client(&ctx, c);
38 screen_redraw_move_cursor(&ctx, 0, c->sy - status_lines);
39 screen_redraw_set_attributes(&ctx, 0, status_colour);
Nicholas Marriott76c8a592007-11-27 19:23:34 +000040
Nicholas Marriott4ba3cf62007-10-26 12:29:07 +000041 RB_FOREACH(wl, winlinks, &c->session->windows) {
Nicholas Marriotte5b70012007-10-12 12:37:48 +000042 flag = ' ';
Nicholas Marriott4ba3cf62007-10-26 12:29:07 +000043 if (wl == c->session->lastw)
Nicholas Marriotte5b70012007-10-12 12:37:48 +000044 flag = '-';
Nicholas Marriott4ba3cf62007-10-26 12:29:07 +000045 if (wl == c->session->curw)
Nicholas Marriotte5b70012007-10-12 12:37:48 +000046 flag = '*';
Nicholas Marriott4ba3cf62007-10-26 12:29:07 +000047 if (session_hasbell(c->session, wl))
Nicholas Marriotte5b70012007-10-12 12:37:48 +000048 flag = '!';
Nicholas Marriott103748d2007-12-06 09:46:23 +000049 screen_redraw_write_string(
Nicholas Marriott76c8a592007-11-27 19:23:34 +000050 &ctx, "%d:%s%c ", wl->idx, wl->window->name, flag);
Nicholas Marriott7ec5be32007-10-12 12:08:51 +000051
Nicholas Marriotte7f68a02008-01-03 19:18:14 +000052 if (ctx.s->cx > screen_size_x(ctx.s))
Nicholas Marriottbfccbc62007-10-01 14:53:29 +000053 break;
54 }
Nicholas Marriott103748d2007-12-06 09:46:23 +000055 screen_redraw_clear_end_of_line(&ctx);
Nicholas Marriottbfccbc62007-10-01 14:53:29 +000056
Nicholas Marriott103748d2007-12-06 09:46:23 +000057 screen_redraw_stop(&ctx);
Nicholas Marriott76c8a592007-11-27 19:23:34 +000058}
59
60void
61status_write_window(struct window *w)
62{
63 struct client *c;
64 u_int i;
65
Nicholas Marriott103748d2007-12-06 09:46:23 +000066 if (w->flags & WINDOW_HIDDEN)
Nicholas Marriott76c8a592007-11-27 19:23:34 +000067 return;
68
69 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
70 c = ARRAY_ITEM(&clients, i);
71 if (c == NULL || c->session == NULL)
72 continue;
73 if (c->session->curw->window != w)
74 continue;
75
76 status_write_client(c);
Nicholas Marriott18d72e62007-11-22 18:09:43 +000077 }
Nicholas Marriottbfccbc62007-10-01 14:53:29 +000078}
79
Nicholas Marriott76c8a592007-11-27 19:23:34 +000080void
81status_write_session(struct session *s)
Nicholas Marriottbfccbc62007-10-01 14:53:29 +000082{
Nicholas Marriott76c8a592007-11-27 19:23:34 +000083 struct client *c;
84 u_int i;
Nicholas Marriottbfccbc62007-10-01 14:53:29 +000085
Nicholas Marriott76c8a592007-11-27 19:23:34 +000086 if (s->flags & SESSION_UNATTACHED)
87 return;
Nicholas Marriottbfccbc62007-10-01 14:53:29 +000088
Nicholas Marriott76c8a592007-11-27 19:23:34 +000089 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
90 c = ARRAY_ITEM(&clients, i);
91 if (c == NULL || c->session != s)
92 continue;
93 status_write_client(c);
Nicholas Marriottbfccbc62007-10-01 14:53:29 +000094 }
Nicholas Marriottbfccbc62007-10-01 14:53:29 +000095}