mirror of
https://github.com/tmux/tmux.git
synced 2024-12-12 17:38:48 +00:00
Move status prompt/message init and teardown into status.c.
This commit is contained in:
parent
fdafe63004
commit
0450b4a5d4
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-command-prompt.c,v 1.13 2009-01-30 21:10:10 nicm Exp $ */
|
||||
/* $Id: cmd-command-prompt.c,v 1.14 2009-02-13 18:57:55 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -96,7 +96,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cdata->template = NULL;
|
||||
hdr = xstrdup(":");
|
||||
}
|
||||
server_set_client_prompt(c, hdr, cmd_command_prompt_callback, cdata, 0);
|
||||
status_prompt_set(c, hdr, cmd_command_prompt_callback, cdata, 0);
|
||||
xfree(hdr);
|
||||
|
||||
return (0);
|
||||
@ -148,7 +148,7 @@ cmd_command_prompt_callback(void *data, const char *s)
|
||||
if (cause == NULL)
|
||||
return (0);
|
||||
*cause = toupper((u_char) *cause);
|
||||
server_set_client_message(c, cause);
|
||||
status_message_set(c, cause);
|
||||
xfree(cause);
|
||||
cmdlist = NULL;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-select-prompt.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-select-prompt.c,v 1.7 2009-02-13 18:57:55 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -55,7 +55,7 @@ cmd_select_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (c->prompt_string != NULL)
|
||||
return (0);
|
||||
|
||||
server_set_client_prompt(c, "index ", cmd_select_prompt_callback, c, 0);
|
||||
status_prompt_set(c, "index ", cmd_select_prompt_callback, c, 0);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -74,14 +74,14 @@ cmd_select_prompt_callback(void *data, const char *s)
|
||||
idx = strtonum(s, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xsnprintf(msg, sizeof msg, "Index %s: %s", errstr, s);
|
||||
server_set_client_message(c, msg);
|
||||
status_message_set(c, msg);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (winlink_find_by_index(&c->session->windows, idx) == NULL) {
|
||||
xsnprintf(msg, sizeof msg,
|
||||
"Window not found: %s:%d", c->session->name, idx);
|
||||
server_set_client_message(c, msg);
|
||||
status_message_set(c, msg);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: key-bindings.c,v 1.59 2009-01-30 21:10:10 nicm Exp $ */
|
||||
/* $Id: key-bindings.c,v 1.60 2009-02-13 18:57:55 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -168,7 +168,7 @@ key_bindings_error(struct cmd_ctx *ctx, const char *fmt, ...)
|
||||
va_end(ap);
|
||||
|
||||
*msg = toupper((u_char) *msg);
|
||||
server_set_client_message(ctx->curclient, msg);
|
||||
status_message_set(ctx->curclient, msg);
|
||||
xfree(msg);
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ key_bindings_info(struct cmd_ctx *ctx, const char *fmt, ...)
|
||||
va_end(ap);
|
||||
|
||||
*msg = toupper((u_char) *msg);
|
||||
server_set_client_message(ctx->curclient, msg);
|
||||
status_message_set(ctx->curclient, msg);
|
||||
xfree(msg);
|
||||
}
|
||||
|
||||
|
77
server-fn.c
77
server-fn.c
@ -1,4 +1,4 @@
|
||||
/* $Id: server-fn.c,v 1.53 2009-01-11 00:48:42 nicm Exp $ */
|
||||
/* $Id: server-fn.c,v 1.54 2009-02-13 18:57:55 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -26,74 +26,6 @@
|
||||
|
||||
int server_lock_callback(void *, const char *);
|
||||
|
||||
void
|
||||
server_set_client_message(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
|
||||
server_clear_client_message(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;
|
||||
}
|
||||
|
||||
void
|
||||
server_set_client_prompt(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
|
||||
server_clear_client_prompt(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;
|
||||
}
|
||||
|
||||
void
|
||||
server_write_client(
|
||||
struct client *c, enum hdrtype type, const void *buf, size_t len)
|
||||
@ -232,9 +164,8 @@ server_lock(void)
|
||||
if (c == NULL)
|
||||
continue;
|
||||
|
||||
server_clear_client_prompt(c);
|
||||
server_set_client_prompt(
|
||||
c, "Password: ", server_lock_callback, c, 1);
|
||||
status_prompt_clear(c);
|
||||
status_prompt_set(c, "Password: ", server_lock_callback, c, 1);
|
||||
server_redraw_client(c);
|
||||
}
|
||||
server_locked = 1;
|
||||
@ -269,7 +200,7 @@ server_unlock(const char *s)
|
||||
if (c == NULL)
|
||||
continue;
|
||||
|
||||
server_clear_client_prompt(c);
|
||||
status_prompt_clear(c);
|
||||
server_redraw_client(c);
|
||||
}
|
||||
server_locked = 0;
|
||||
|
6
server.c
6
server.c
@ -1,4 +1,4 @@
|
||||
/* $Id: server.c,v 1.120 2009-02-11 17:50:35 nicm Exp $ */
|
||||
/* $Id: server.c,v 1.121 2009-02-13 18:57:55 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -556,7 +556,7 @@ server_check_timers(struct client *c)
|
||||
fatal("gettimeofday");
|
||||
|
||||
if (c->message_string != NULL && timercmp(&tv, &c->message_timer, >))
|
||||
server_clear_client_message(c);
|
||||
status_message_clear(c);
|
||||
|
||||
if (c->message_string != NULL || c->prompt_string != NULL) {
|
||||
/*
|
||||
@ -694,7 +694,7 @@ server_handle_client(struct client *c)
|
||||
return;
|
||||
wp = c->session->curw->window->active; /* could die */
|
||||
|
||||
server_clear_client_message(c);
|
||||
status_message_clear(c);
|
||||
if (c->prompt_string != NULL) {
|
||||
status_prompt_key(c, key);
|
||||
continue;
|
||||
|
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)
|
||||
|
12
tmux.h
12
tmux.h
@ -1,4 +1,4 @@
|
||||
/* $Id: tmux.h,v 1.271 2009-02-13 00:43:04 nicm Exp $ */
|
||||
/* $Id: tmux.h,v 1.272 2009-02-13 18:57:55 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -1277,11 +1277,6 @@ int server_start(const char *);
|
||||
int server_msg_dispatch(struct client *);
|
||||
|
||||
/* server-fn.c */
|
||||
void server_set_client_message(struct client *, const char *);
|
||||
void server_clear_client_message(struct client *);
|
||||
void server_set_client_prompt(struct client *,
|
||||
const char *, int (*)(void *, const char *), void *, int);
|
||||
void server_clear_client_prompt(struct client *);
|
||||
struct session *server_extract_session(
|
||||
struct msg_command_data *, char *, char **);
|
||||
void server_write(struct client *, enum hdrtype, const void *, size_t);
|
||||
@ -1302,7 +1297,12 @@ int server_unlock(const char *);
|
||||
|
||||
/* status.c */
|
||||
int status_redraw(struct client *);
|
||||
void status_message_set(struct client *, const char *);
|
||||
void status_message_clear(struct client *);
|
||||
int status_message_redraw(struct client *);
|
||||
void status_prompt_set(struct client *,
|
||||
const char *, int (*)(void *, const char *), void *, int);
|
||||
void status_prompt_clear(struct client *);
|
||||
int status_prompt_redraw(struct client *);
|
||||
void status_prompt_key(struct client *, int);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user