/* $Id: status.c,v 1.119 2009-09-20 22:11:27 tcunha Exp $ */
/*
* 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 <sys/time.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "tmux.h"
char *status_replace_popen(char **);
size_t status_width(struct winlink *);
char *status_print(struct session *, struct winlink *, struct grid_cell *);
void status_prompt_add_history(struct client *);
char *status_prompt_complete(const char *);
/* Draw status for client on the last lines of given context. */
int
status_redraw(struct client *c)
{
struct screen_write_ctx ctx;
struct session *s = c->session;
struct winlink *wl;
struct screen old_status;
char *left, *right, *text, *ptr;
size_t llen, llen2, rlen, rlen2, offset;
size_t ox, xx, yy, size, start, width;
struct grid_cell stdgc, sl_stdgc, sr_stdgc, gc;
int larrow, rarrow, utf8flag;
int sl_fg, sl_bg, sr_fg, sr_bg;
int sl_attr, sr_attr;
left = right = NULL;
/* No status line?*/
if (c->tty.sy == 0 || !options_get_number(&s->options, "status"))
return (1);
larrow = rarrow = 0;
/* Create the target screen. */
memcpy(&old_status, &c->status, sizeof old_status);
screen_init(&c->status, c->tty.sx, 1, 0);
if (gettimeofday(&c->status_timer, NULL) != 0)
fatal("gettimeofday failed");
memcpy(&stdgc, &grid_default_cell, sizeof gc);
colour_set_fg(&stdgc, options_get_number(&s->options, "status-fg"));
colour_set_bg(&stdgc, options_get_number(&s->options, "status-bg"));
stdgc.attr |= options_get_number(&s->options, "status-attr");
/*
* Set the status-left and status-right parts to the default status
* line options and only change them where they differ from the
* defaults.
*/
memcpy(&sl_stdgc, &stdgc, sizeof sl_stdgc);
memcpy(&sr_stdgc, &stdgc, sizeof sr_stdgc);
sl_fg = options_get_number(&s->options, "status-left-fg");
if (sl_fg != 8)
colour_set_fg(&sl_stdgc, sl_fg);
sl_bg = options_get_number(&s->options, "status-left-bg");
if (sl_bg != 8)
colour_set_bg(&sl_stdgc, sl_bg);
sl_attr = options_get_number(&s->options, "status-left-attr");
if (sl_attr != 0)
sl_stdgc.attr = sl_attr;
sr_fg = options_get_number(&s->options, "status-right-fg");
if (sr_fg != 8)
colour_set_fg(&sr_stdgc, sr_fg);
sr_bg = options_get_number(&s->options, "status-right-bg");
if (sr_bg != 8)
colour_set_bg(&sr_stdgc, sr_bg);
sr_attr = options_get_number(&s->options, "status-right-attr");
if (sr_attr != 0)
sr_stdgc.attr = sr_attr;
yy = c->tty.sy - 1;
if (yy == 0)
goto blank<