/* $OpenBSD$ */
/*
* Copyright (c) 2020 Nicholas Marriott <nicholas.marriott@gmail.com>
*
* 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 <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
static struct screen *window_customize_init(struct window_mode_entry *,
struct cmd_find_state *, struct args *);
static void window_customize_free(struct window_mode_entry *);
static void window_customize_resize(struct window_mode_entry *,
u_int, u_int);
static void window_customize_key(struct window_mode_entry *,
struct client *, struct session *,
struct winlink *, key_code, struct mouse_event *);
#define WINDOW_CUSTOMIZE_DEFAULT_FORMAT \
"#{?is_option," \
"#{?option_is_global,,#[reverse](#{option_scope})#[default] }" \
"#[ignore]" \
"#{option_value}#{?option_unit, #{option_unit},}" \
"," \
"#{key}" \
"}"
static const struct menu_item window_customize_menu_items[] = {
{ "Select", '\r', NULL },
{ "Expand", KEYC_RIGHT, NULL },
{ "", KEYC_NONE, NULL },
{ "Tag", 't', NULL },
{ "Tag All", '\024', NULL },
{ "Tag None", 'T', NULL },
{ "", KEYC_NONE, NULL },
{ "Cancel", 'q', NULL },
{ NULL, KEYC_NONE, NULL }
};
const struct window_mode window_customize_mode = {
.name = "options-mode",
.default_format = WINDOW_CUSTOMIZE_DEFAULT_FORMAT,
.init = window_customize_init,
.free = window_customize_free,
.resize = window_customize_resize,
.key = window_customize_key,
};
enum window_customize_scope {
WINDOW_CUSTOMIZE_NONE,
WINDOW_CUSTOMIZE_KEY,
WINDOW_CUSTOMIZE_SERVER,
WINDOW_CUSTOMIZE_GLOBAL_SESSION,
WINDOW_CUSTOMIZE_SESSION,
WINDOW_CUSTOMIZE_GLOBAL_WINDOW,
WINDOW_CUSTOMIZE_WINDOW,
WINDOW_CUSTOMIZE_PANE
};
struct window_customize_itemdata {
struct window_customize_modedata *data;
enum window_customize_scope scope;
char *table;
key_code key;
struct options *oo;
char *name;
int idx;
};
struct window_customize_modedata {
struct window_pane *wp;
int dead;
int references;
struct mode_tree_data *data;
char *format;
int hide_global;
struct window_customize_itemdata **item_list;
u_int item_size;
struct cmd_find_state fs;
};
static uint64_t
window_customize_get_tag(struct options_entry *o, int idx,
const struct options_table_entry *oe)
{
uint64_t offset;
if (oe == NULL)
return ((uint64_t)o);
offset = ((char *)oe - (char *)options_table) / sizeof *options_table;
return ((2ULL << 62)|(offset << 32)|((idx + 1) << 1)|1);
}
static struct options *
window_customize_get_tree(enum window_customize_scope scope,
struct cmd_find_state *fs)
{
switch (scope) {
case WINDOW_CUSTOMIZE_NONE:
case WINDOW_CUSTOMIZE_KEY:
return (NULL);
case WINDOW_CUSTOMIZE_SERVER:
return (global_options);
case WINDOW_CUSTOMIZE_GLOBAL_SESSION:
return (global_s_options);
case WINDOW_CUSTOMIZE_SESSION:
return (fs->s->options);
case WINDOW_CUSTOMIZE_GLOBAL_WINDOW:
return (global_w_options);
case WINDOW_CUSTOMIZE_WINDOW:
return (fs->w
|