enum cmd_retval cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct winlink *wl; const char *layoutname; int next, previous, layout; if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL) return (CMD_RETURN_ERROR); server_unzoom_window(wl->window); next = self->entry == &cmd_next_layout_entry; if (args_has(self->args, 'n')) next = 1; previous = self->entry == &cmd_previous_layout_entry; if (args_has(self->args, 'p')) previous = 1; if (next || previous) { if (next) layout = layout_set_next(wl->window); else layout = layout_set_previous(wl->window); server_redraw_window(wl->window); cmdq_info(cmdq, "arranging in: %s", layout_set_name(layout)); return (CMD_RETURN_NORMAL); } if (args->argc == 0) layout = wl->window->lastlayout; else layout = layout_set_lookup(args->argv[0]); if (layout != -1) { layout = layout_set_select(wl->window, layout); server_redraw_window(wl->window); cmdq_info(cmdq, "arranging in: %s", layout_set_name(layout)); return (CMD_RETURN_NORMAL); } if (args->argc != 0) { layoutname = args->argv[0]; if (layout_parse(wl->window, layoutname) == -1) { cmdq_error(cmdq, "can't set layout: %s", layoutname); return (CMD_RETURN_ERROR); } server_redraw_window(wl->window); cmdq_info(cmdq, "arranging in: %s", layoutname); } return (CMD_RETURN_NORMAL); }
/* Set an option. */ int cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { struct args *args = self->args; struct options_entry *o; const char *s; if (oe->type != OPTIONS_TABLE_FLAG && value == NULL) { cmdq_error(cmdq, "empty value"); return (-1); } o = NULL; switch (oe->type) { case OPTIONS_TABLE_STRING: o = cmd_set_option_string(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_NUMBER: o = cmd_set_option_number(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_KEY: o = cmd_set_option_key(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_COLOUR: o = cmd_set_option_colour(self, cmdq, oe, oo, value); if (o != NULL) style_update_new(oo, o->name, oe->style); break; case OPTIONS_TABLE_ATTRIBUTES: o = cmd_set_option_attributes(self, cmdq, oe, oo, value); if (o != NULL) style_update_new(oo, o->name, oe->style); break; case OPTIONS_TABLE_FLAG: o = cmd_set_option_flag(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_CHOICE: o = cmd_set_option_choice(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_STYLE: o = cmd_set_option_style(self, cmdq, oe, oo, value); break; } if (o == NULL) return (-1); s = options_table_print_entry(oe, o, 0); if (!args_has(args, 'q')) cmdq_info(cmdq, "set option: %s -> %s", oe->name, s); return (0); }
void cmd_run_shell_callback(struct job *job) { struct cmd_run_shell_data *cdata = job->data; struct cmd_q *cmdq = cdata->cmdq; char *cmd, *msg, *line; size_t size; int retcode; u_int lines; if (cmdq->dead) return; cmd = cdata->cmd; lines = 0; do { if ((line = evbuffer_readline(job->event->input)) != NULL) { cmd_run_shell_print(job, line); free(line); lines++; } } while (line != NULL); size = EVBUFFER_LENGTH(job->event->input); if (size != 0) { line = xmalloc(size + 1); memcpy(line, EVBUFFER_DATA(job->event->input), size); line[size] = '\0'; cmd_run_shell_print(job, line); lines++; free(line); } msg = NULL; if (WIFEXITED(job->status)) { if ((retcode = WEXITSTATUS(job->status)) != 0) xasprintf(&msg, "'%s' returned %d", cmd, retcode); } else if (WIFSIGNALED(job->status)) { retcode = WTERMSIG(job->status); xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode); } if (msg != NULL) { if (lines == 0) cmdq_info(cmdq, "%s", msg); else cmd_run_shell_print(job, msg); free(msg); } }
/* Unset an option. */ int cmd_set_option_unset(struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { struct args *args = self->args; if (args_has(args, 'g')) { cmdq_error(cmdq, "can't unset global option: %s", oe->name); return (-1); } if (value != NULL) { cmdq_error(cmdq, "value passed to unset option: %s", oe->name); return (-1); } options_remove(oo, oe->name); if (!args_has(args, 'q')) cmdq_info(cmdq, "unset option: %s", oe->name); return (0); }
/* Set user option. */ enum cmd_retval cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char* optstr, const char *valstr) { struct args *args = self->args; struct session *s; struct winlink *wl; struct options *oo; if (args_has(args, 's')) oo = &global_options; else if (args_has(self->args, 'w') || self->entry == &cmd_set_window_option_entry) { if (args_has(self->args, 'g')) oo = &global_w_options; else { wl = cmd_find_window(cmdq, args_get(args, 't'), NULL); if (wl == NULL) return (CMD_RETURN_ERROR); oo = &wl->window->options; } } else { if (args_has(self->args, 'g')) oo = &global_s_options; else { s = cmd_find_session(cmdq, args_get(args, 't'), 0); if (s == NULL) return (CMD_RETURN_ERROR); oo = &s->options; } } if (args_has(args, 'u')) { if (options_find1(oo, optstr) == NULL) { cmdq_error(cmdq, "unknown option: %s", optstr); return (CMD_RETURN_ERROR); } if (valstr != NULL) { cmdq_error(cmdq, "value passed to unset option: %s", optstr); return (CMD_RETURN_ERROR); } options_remove(oo, optstr); } else { if (valstr == NULL) { cmdq_error(cmdq, "empty value"); return (CMD_RETURN_ERROR); } if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) { if (!args_has(args, 'q')) cmdq_print(cmdq, "already set: %s", optstr); return (CMD_RETURN_NORMAL); } options_set_string(oo, optstr, "%s", valstr); if (!args_has(args, 'q')) { cmdq_info(cmdq, "set option: %s -> %s", optstr, valstr); } } return (CMD_RETURN_NORMAL); }
enum cmd_retval cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct client *c; struct session *s = NULL; struct winlink *wl = NULL; struct window *w = NULL; struct window_pane *wp = NULL; const char *tflag; if ((c = cmd_find_client(cmdq, args_get(args, 'c'), 0)) == NULL) return (CMD_RETURN_ERROR); if (args_has(args, 'r')) { if (c->flags & CLIENT_READONLY) { c->flags &= ~CLIENT_READONLY; cmdq_info(cmdq, "made client writable"); } else { c->flags |= CLIENT_READONLY; cmdq_info(cmdq, "made client read-only"); } } tflag = args_get(args, 't'); if (args_has(args, 'n')) { if ((s = session_next_session(c->session)) == NULL) { cmdq_error(cmdq, "can't find next session"); return (CMD_RETURN_ERROR); } } else if (args_has(args, 'p')) { if ((s = session_previous_session(c->session)) == NULL) { cmdq_error(cmdq, "can't find previous session"); return (CMD_RETURN_ERROR); } } else if (args_has(args, 'l')) { if (c->last_session != NULL && session_alive(c->last_session)) s = c->last_session; if (s == NULL) { cmdq_error(cmdq, "can't find last session"); return (CMD_RETURN_ERROR); } } else { if (tflag == NULL) { if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL) return (CMD_RETURN_ERROR); } else if (tflag[strcspn(tflag, ":.")] != '\0') { if ((wl = cmd_find_pane(cmdq, tflag, &s, &wp)) == NULL) return (CMD_RETURN_ERROR); } else { if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL) return (CMD_RETURN_ERROR); w = cmd_lookup_windowid(tflag); if (w == NULL && (wp = cmd_lookup_paneid(tflag)) != NULL) w = wp->window; if (w != NULL) wl = winlink_find_by_window(&s->windows, w); } if (cmdq->client == NULL) return (CMD_RETURN_NORMAL); if (wl != NULL) { if (wp != NULL) window_set_active_pane(wp->window, wp); session_set_current(s, wl); } } if (c->session != NULL) c->last_session = c->session; c->session = s; session_update_activity(s); recalculate_sizes(); server_check_unattached(); server_redraw_client(c); s->curw->flags &= ~WINLINK_ALERTFLAGS; return (CMD_RETURN_NORMAL); }