aboutsummaryrefslogtreecommitdiff
path: root/server-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'server-client.c')
-rw-r--r--server-client.c157
1 files changed, 90 insertions, 67 deletions
diff --git a/server-client.c b/server-client.c
index eb29aebb..6e24fdf3 100644
--- a/server-client.c
+++ b/server-client.c
@@ -23,8 +23,6 @@
#include <errno.h>
#include <event.h>
#include <fcntl.h>
-#include <imsg.h>
-#include <paths.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -213,23 +211,12 @@ server_client_create(int fd)
c->queue = cmdq_new();
c->tty.fd = -1;
- c->title = NULL;
-
- c->session = NULL;
- c->last_session = NULL;
c->tty.sx = 80;
c->tty.sy = 24;
status_init(c);
- c->message_string = NULL;
- TAILQ_INIT(&c->message_log);
-
- c->prompt_string = NULL;
- c->prompt_buffer = NULL;
- c->prompt_index = 0;
-
RB_INIT(&c->files);
c->flags |= CLIENT_FOCUSED;
@@ -249,11 +236,22 @@ server_client_create(int fd)
int
server_client_open(struct client *c, char **cause)
{
+ const char *ttynam = _PATH_TTY;
+
if (c->flags & CLIENT_CONTROL)
return (0);
- if (strcmp(c->ttyname, "/dev/tty") == 0) {
- *cause = xstrdup("can't use /dev/tty");
+ if (strcmp(c->ttyname, ttynam) == 0||
+ ((isatty(STDIN_FILENO) &&
+ (ttynam = ttyname(STDIN_FILENO)) != NULL &&
+ strcmp(c->ttyname, ttynam) == 0) ||
+ (isatty(STDOUT_FILENO) &&
+ (ttynam = ttyname(STDOUT_FILENO)) != NULL &&
+ strcmp(c->ttyname, ttynam) == 0) ||
+ (isatty(STDERR_FILENO) &&
+ (ttynam = ttyname(STDERR_FILENO)) != NULL &&
+ strcmp(c->ttyname, ttynam) == 0))) {
+ xasprintf(cause, "can't use %s", c->ttyname);
return (-1);
}
@@ -272,7 +270,6 @@ server_client_open(struct client *c, char **cause)
void
server_client_lost(struct client *c)
{
- struct message_entry *msg, *msg1;
struct client_file *cf;
c->flags |= CLIENT_DEAD;
@@ -296,7 +293,9 @@ server_client_lost(struct client *c)
if (c->flags & CLIENT_TERMINAL)
tty_free(&c->tty);
free(c->ttyname);
+
free(c->term_name);
+ free(c->term_type);
status_free(c);
@@ -311,11 +310,6 @@ server_client_lost(struct client *c)
free(c->message_string);
if (event_initialized(&c->message_timer))
evtimer_del(&c->message_timer);
- TAILQ_FOREACH_SAFE(msg, &c->message_log, entry, msg1) {
- free(msg->msg);
- TAILQ_REMOVE(&c->message_log, msg, entry);
- free(msg);
- }
free(c->prompt_saved);
free(c->prompt_string);
@@ -1126,6 +1120,7 @@ server_client_key_callback(struct cmdq_item *item, void *data)
c->tty.mouse_drag_update(c, m);
goto out;
}
+ event->key = key;
}
/* Find affected pane. */
@@ -1294,10 +1289,6 @@ server_client_handle_key(struct client *c, struct key_event *event)
*/
if (~c->flags & CLIENT_READONLY) {
status_message_clear(c);
- if (c->prompt_string != NULL) {
- if (status_prompt_key(c, event->key) == 0)
- return (0);
- }
if (c->overlay_key != NULL) {
switch (c->overlay_key(c, event)) {
case 0:
@@ -1308,6 +1299,10 @@ server_client_handle_key(struct client *c, struct key_event *event)
}
}
server_client_clear_overlay(c);
+ if (c->prompt_string != NULL) {
+ if (status_prompt_key(c, event->key) == 0)
+ return (0);
+ }
}
/*
@@ -1540,9 +1535,9 @@ server_client_reset_state(struct client *c)
struct tty *tty = &c->tty;
struct window *w = c->session->curw->window;
struct window_pane *wp = w->active, *loop;
- struct screen *s;
+ struct screen *s = NULL;
struct options *oo = c->session->options;
- int mode, cursor, flags;
+ int mode = 0, cursor, flags;
u_int cx = 0, cy = 0, ox, oy, sx, sy;
if (c->flags & (CLIENT_CONTROL|CLIENT_SUSPENDED))
@@ -1554,15 +1549,14 @@ server_client_reset_state(struct client *c)
/* Get mode from overlay if any, else from screen. */
if (c->overlay_draw != NULL) {
- s = NULL;
- if (c->overlay_mode == NULL)
- mode = 0;
- else
- mode = c->overlay_mode(c, &cx, &cy);
- } else {
+ if (c->overlay_mode != NULL)
+ s = c->overlay_mode(c, &cx, &cy);
+ } else
s = wp->screen;
+ if (s != NULL)
mode = s->mode;
- }
+ if (c->prompt_string != NULL || c->message_string != NULL)
+ mode &= ~MODE_CURSOR;
log_debug("%s: client %s mode %x", __func__, c->name, mode);
/* Reset region and margin. */
@@ -1780,7 +1774,6 @@ server_client_check_redraw(struct client *c)
if (!redraw)
continue;
log_debug("%s: redrawing pane %%%u", __func__, wp->id);
- tty_update_mode(tty, mode, NULL);
screen_redraw_pane(c, wp);
}
c->redraw_panes = 0;
@@ -1788,7 +1781,6 @@ server_client_check_redraw(struct client *c)
}
if (c->flags & CLIENT_ALLREDRAWFLAGS) {
- tty_update_mode(tty, mode, NULL);
if (options_get_number(s->options, "set-titles"))
server_client_set_title(c);
screen_redraw_screen(c);
@@ -2099,6 +2091,10 @@ server_client_dispatch_identify(struct client *c, struct imsg *imsg)
c->name = name;
log_debug("client %p name is %s", c, c->name);
+#ifdef __CYGWIN__
+ c->fd = open(c->ttyname, O_RDWR|O_NOCTTY);
+#endif
+
if (c->flags & CLIENT_CONTROL) {
close(c->fd);
c->fd = -1;
@@ -2205,37 +2201,6 @@ server_client_dispatch_read_done(struct client *c, struct imsg *imsg)
file_fire_done(cf);
}
-/* Add to client message log. */
-void
-server_client_add_message(struct client *c, const char *fmt, ...)
-{
- struct message_entry *msg, *msg1;
- char *s;
- va_list ap;
- u_int limit;
-
- va_start(ap, fmt);
- xvasprintf(&s, fmt, ap);
- va_end(ap);
-
- log_debug("message %s (client %p)", s, c);
-
- msg = xcalloc(1, sizeof *msg);
- msg->msg_time = time(NULL);
- msg->msg_num = c->message_next++;
- msg->msg = s;
- TAILQ_INSERT_TAIL(&c->message_log, msg, entry);
-
- limit = options_get_number(global_options, "message-limit");
- TAILQ_FOREACH_SAFE(msg, &c->message_log, entry, msg1) {
- if (msg->msg_num + limit >= c->message_next)
- break;
- free(msg->msg);
- TAILQ_REMOVE(&c->message_log, msg, entry);
- free(msg);
- }
-}
-
/* Get client working directory. */
const char *
server_client_get_cwd(struct client *c, struct session *s)
@@ -2254,3 +2219,61 @@ server_client_get_cwd(struct client *c, struct session *s)
return (home);
return ("/");
}
+
+/* Set client flags. */
+void
+server_client_set_flags(struct client *c, const char *flags)
+{
+ char *s, *copy, *next;
+ int flag, not;
+
+ s = copy = xstrdup (flags);
+ while ((next = strsep(&s, ",")) != NULL) {
+ not = (*next == '!');
+ if (not)
+ next++;
+
+ if (strcmp(next, "no-output") == 0)
+ flag = CLIENT_CONTROL_NOOUTPUT;
+ else if (strcmp(next, "read-only") == 0)
+ flag = CLIENT_READONLY;
+ else if (strcmp(next, "ignore-size") == 0)
+ flag = CLIENT_IGNORESIZE;
+ else
+ continue;
+
+ log_debug("client %s set flag %s", c->name, next);
+ if (not)
+ c->flags &= ~flag;
+ else
+ c->flags |= flag;
+ }
+ free(copy);
+
+}
+
+/*Get client flags. This is only flags useful to show to users. */
+const char *
+server_client_get_flags(struct client *c)
+{
+ static char s[256];
+
+ *s = '\0';
+ if (c->flags & CLIENT_ATTACHED)
+ strlcat(s, "attached,", sizeof s);
+ if (c->flags & CLIENT_CONTROL)
+ strlcat(s, "control-mode,", sizeof s);
+ if (c->flags & CLIENT_IGNORESIZE)
+ strlcat(s, "ignore-size,", sizeof s);
+ if (c->flags & CLIENT_CONTROL_NOOUTPUT)
+ strlcat(s, "no-output,", sizeof s);
+ if (c->flags & CLIENT_READONLY)
+ strlcat(s, "read-only,", sizeof s);
+ if (c->flags & CLIENT_SUSPENDED)
+ strlcat(s, "suspended,", sizeof s);
+ if (c->flags & CLIENT_UTF8)
+ strlcat(s, "UTF-8,", sizeof s);
+ if (*s != '\0')
+ s[strlen(s) - 1] = '\0';
+ return (s);
+}