mirror of
https://github.com/tmux/tmux.git
synced 2025-09-04 06:56:58 +00:00
Move status prompt/message init and teardown into status.c.
This commit is contained in:
74
status.c
74
status.c
@ -1,4 +1,4 @@
|
||||
/* $Id: status.c,v 1.73 2009-02-11 17:50:36 nicm Exp $ */
|
||||
/* $Id: status.c,v 1.74 2009-02-13 18:57:55 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -488,6 +488,38 @@ status_print(struct session *s, struct winlink *wl, struct grid_cell *gc)
|
||||
return (text);
|
||||
}
|
||||
|
||||
void
|
||||
status_message_set(struct client *c, const char *msg)
|
||||
{
|
||||
struct timeval tv;
|
||||
int delay;
|
||||
|
||||
delay = options_get_number(&c->session->options, "display-time");
|
||||
tv.tv_sec = delay / 1000;
|
||||
tv.tv_usec = (delay % 1000) * 1000L;
|
||||
|
||||
c->message_string = xstrdup(msg);
|
||||
if (gettimeofday(&c->message_timer, NULL) != 0)
|
||||
fatal("gettimeofday");
|
||||
timeradd(&c->message_timer, &tv, &c->message_timer);
|
||||
|
||||
c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE);
|
||||
c->flags |= CLIENT_STATUS;
|
||||
}
|
||||
|
||||
void
|
||||
status_message_clear(struct client *c)
|
||||
{
|
||||
if (c->message_string == NULL)
|
||||
return;
|
||||
|
||||
xfree(c->message_string);
|
||||
c->message_string = NULL;
|
||||
|
||||
c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
|
||||
c->flags |= CLIENT_REDRAW;
|
||||
}
|
||||
|
||||
/* Draw client message on status line of present else on last line. */
|
||||
int
|
||||
status_message_redraw(struct client *c)
|
||||
@ -529,6 +561,42 @@ status_message_redraw(struct client *c)
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
status_prompt_set(struct client *c,
|
||||
const char *msg, int (*fn)(void *, const char *), void *data, int hide)
|
||||
{
|
||||
c->prompt_string = xstrdup(msg);
|
||||
|
||||
c->prompt_buffer = xstrdup("");
|
||||
c->prompt_index = 0;
|
||||
|
||||
c->prompt_callback = fn;
|
||||
c->prompt_data = data;
|
||||
|
||||
c->prompt_hindex = 0;
|
||||
|
||||
c->prompt_hidden = hide;
|
||||
|
||||
c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE);
|
||||
c->flags |= CLIENT_STATUS;
|
||||
}
|
||||
|
||||
void
|
||||
status_prompt_clear(struct client *c)
|
||||
{
|
||||
if (c->prompt_string == NULL)
|
||||
return;
|
||||
|
||||
xfree(c->prompt_string);
|
||||
c->prompt_string = NULL;
|
||||
|
||||
xfree(c->prompt_buffer);
|
||||
c->prompt_buffer = NULL;
|
||||
|
||||
c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
|
||||
c->flags |= CLIENT_REDRAW;
|
||||
}
|
||||
|
||||
/* Draw client prompt on status line of present else on last line. */
|
||||
int
|
||||
status_prompt_redraw(struct client *c)
|
||||
@ -744,13 +812,13 @@ status_prompt_key(struct client *c, int key)
|
||||
status_prompt_add_history(c);
|
||||
if (c->prompt_callback(
|
||||
c->prompt_data, c->prompt_buffer) == 0)
|
||||
server_clear_client_prompt(c);
|
||||
status_prompt_clear(c);
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
case '\033': /* escape */
|
||||
if (c->prompt_callback(c->prompt_data, NULL) == 0)
|
||||
server_clear_client_prompt(c);
|
||||
status_prompt_clear(c);
|
||||
break;
|
||||
default:
|
||||
if (key < 32)
|
||||
|
Reference in New Issue
Block a user