2007-11-21 19:53:57 +00:00
|
|
|
/* $Id: status.c,v 1.11 2007-11-21 19:53:56 nicm Exp $ */
|
2007-10-01 14:53:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2007-11-20 18:11:37 +00:00
|
|
|
void printflike3 status_print(struct buffer *, size_t *, const char *, ...);
|
2007-10-01 14:53:29 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
status_write(struct client *c)
|
|
|
|
{
|
2007-10-26 12:29:07 +00:00
|
|
|
struct screen *s = &c->session->curw->window->screen;
|
2007-10-01 14:53:29 +00:00
|
|
|
struct buffer *b = c->out;
|
2007-10-26 12:29:07 +00:00
|
|
|
struct winlink *wl;
|
2007-10-01 14:53:29 +00:00
|
|
|
size_t size;
|
2007-10-12 12:37:48 +00:00
|
|
|
char flag;
|
2007-10-01 14:53:29 +00:00
|
|
|
|
|
|
|
input_store_zero(b, CODE_CURSOROFF);
|
2007-10-03 23:32:26 +00:00
|
|
|
input_store_two(b, CODE_CURSORMOVE, c->sy - status_lines + 1, 1);
|
2007-10-12 12:08:51 +00:00
|
|
|
input_store_two(b, CODE_ATTRIBUTES, 0, status_colour);
|
2007-10-01 14:53:29 +00:00
|
|
|
|
2007-10-04 19:03:52 +00:00
|
|
|
size = c->sx;
|
2007-10-26 12:29:07 +00:00
|
|
|
RB_FOREACH(wl, winlinks, &c->session->windows) {
|
2007-10-12 12:37:48 +00:00
|
|
|
flag = ' ';
|
2007-10-26 12:29:07 +00:00
|
|
|
if (wl == c->session->lastw)
|
2007-10-12 12:37:48 +00:00
|
|
|
flag = '-';
|
2007-10-26 12:29:07 +00:00
|
|
|
if (wl == c->session->curw)
|
2007-10-12 12:37:48 +00:00
|
|
|
flag = '*';
|
2007-10-26 12:29:07 +00:00
|
|
|
if (session_hasbell(c->session, wl))
|
2007-10-12 12:37:48 +00:00
|
|
|
flag = '!';
|
2007-10-26 12:29:07 +00:00
|
|
|
status_print(
|
2007-10-30 10:59:43 +00:00
|
|
|
b, &size, "%d:%s%c ", wl->idx, wl->window->name, flag);
|
2007-10-12 12:08:51 +00:00
|
|
|
|
2007-10-01 14:53:29 +00:00
|
|
|
if (size == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (size-- > 0)
|
|
|
|
input_store8(b, ' ');
|
|
|
|
|
|
|
|
input_store_two(b, CODE_ATTRIBUTES, s->attr, s->colr);
|
|
|
|
input_store_two(b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1);
|
2007-11-21 19:53:57 +00:00
|
|
|
if (!(s->mode & MODE_BACKGROUND) && s->mode & MODE_CURSOR)
|
2007-10-01 14:53:29 +00:00
|
|
|
input_store_zero(b, CODE_CURSORON);
|
|
|
|
}
|
|
|
|
|
2007-11-20 18:11:37 +00:00
|
|
|
void printflike3
|
2007-10-01 14:53:29 +00:00
|
|
|
status_print(struct buffer *b, size_t *size, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char *msg, *ptr;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
n = xvasprintf(&msg, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if ((size_t) n > *size) {
|
|
|
|
msg[*size] = '\0';
|
|
|
|
n = *size;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ptr = msg; *ptr != '\0'; ptr++)
|
|
|
|
input_store8(b, *ptr);
|
|
|
|
(*size) -= n;
|
|
|
|
|
|
|
|
xfree(msg);
|
|
|
|
}
|