Пример #1
0
static char *
readline_set_generator(const char *text, int state)
{
	static const char *words[] = {
#define DEFINE_OPTION_NAME(name, type, flags) #name " = ",
		OPTION_INFO(DEFINE_OPTION_NAME)
#undef DEFINE_OPTION_NAME
		NULL
	};

	static int index, len;
	const char *name;
	char *match = NULL; /* No match */

	/* If it is a new word to complete, initialize */
	if (!state) {
		index = 0;
		len = strlen(text);
	}

	/* Return the next name which partially matches */
	while ((name = words[index])) {
		name = enum_name(name);
		index++;

		if (strncmp(name, text, len) == 0) {
			/* Ignore exact completion */
			if (strlen(name) > len)
				match = strdup(name);
			break;
		}
	}

	return match;
}
Пример #2
0
static char *
readline_toggle_generator(const char *text, int state)
{
	static const char **words;
	static int index, len;
	const char *name;
	char *match = NULL; /* No match */

	if (!words) {
		/* TODO: Only complete column options that are defined
		 * for the view. */

#define DEFINE_OPTION_WORD(name, type, flags) argv_append(&words, #name);
#define DEFINE_COLUMN_OPTIONS_WORD(name, type, flags) #name,
#define DEFINE_COLUMN_OPTIONS_WORDS(name, id, options) \
	if (VIEW_COLUMN_##id != VIEW_COLUMN_SECTION) { \
		const char *vars[] = { \
			options(DEFINE_COLUMN_OPTIONS_WORD) \
		}; \
		char buf[SIZEOF_STR]; \
		int i; \
		for (i = 0; i < ARRAY_SIZE(vars); i++) { \
			if (enum_name_prefixed(buf, sizeof(buf), #name, vars[i])) \
				argv_append(&words, buf); \
		} \
	}

		OPTION_INFO(DEFINE_OPTION_WORD)
		COLUMN_OPTIONS(DEFINE_COLUMN_OPTIONS_WORDS);
	}

	/* If it is a new word to complete, initialize */
	if (!state) {
		index = 0;
		len = strlen(text);
	}

	/* Return the next name which partially matches */
	while ((name = words[index])) {
		name = enum_name(name);
		index++;

		if (strncmp(name, text, len) == 0) {
			/* Ignore exact completion */
			if (strlen(name) > len)
				match = strdup(name);
			break;
		}
	}

	return match;
}
Пример #3
0
static enum view_flag
prompt_toggle(struct view *view, const char *argv[], char msg[SIZEOF_STR])
{
	struct prompt_toggle option_toggles[] = {
#define TOGGLE_OPTIONS(name, type, flags) { #name, #type, flags, &opt_ ## name },
		OPTION_INFO(TOGGLE_OPTIONS)
	};
	const char *option = argv[1];
	size_t optionlen = option ? strlen(option) : 0;
	struct prompt_toggle *toggle;

	if (!option) {
		string_format_size(msg, SIZEOF_STR, "%s", "No option name given to :toggle");
		return VIEW_NO_FLAGS;
	}

	if (enum_equals_static("sort-field", option, optionlen) ||
	    enum_equals_static("sort-order", option, optionlen)) {
		if (!view_has_flags(view, VIEW_SORTABLE)) {
			report("Sorting is not yet supported for the %s view", view->name);
		} else {
			bool sort_field = enum_equals_static("sort-field", option, optionlen);
			struct sort_state *sort = &view->sort;

			sort_view(view, sort_field);
			string_format_size(msg, SIZEOF_STR, "set %s = %s", option,
				sort_field ? enum_name(view_column_type_map->entries[get_sort_field(view)])
					   : sort->reverse ? "descending" : "ascending");
		}
		return VIEW_NO_FLAGS;
	}

	toggle = find_prompt_toggle(option_toggles, ARRAY_SIZE(option_toggles),
				    option, optionlen);
	if (toggle)
		return prompt_toggle_option(view, argv, toggle, msg);

	string_format_size(msg, SIZEOF_STR, "`:toggle %s` not supported", option);
	return VIEW_NO_FLAGS;
}
Пример #4
0
	report_clear();

	return status != INPUT_CANCEL;
}

struct prompt_toggle {
	const char *name;
	const char *type;
	enum view_flag flags;
	void *opt;
};

static struct prompt_toggle option_toggles[] = {
#define DEFINE_OPTION_TOGGLES(name, type, flags) { #name, #type, flags, &opt_ ## name },
	OPTION_INFO(DEFINE_OPTION_TOGGLES)
};

static bool
find_arg(const char *argv[], const char *arg)
{
	int i;

	for (i = 0; argv && argv[i]; i++)
		if (!strcmp(argv[i], arg))
			return TRUE;
	return FALSE;
}

static enum status_code
prompt_toggle_option(struct view *view, const char *argv[], const char *prefix,
Пример #5
0
#include "tig/options.h"
#include "tig/request.h"
#include "tig/line.h"
#include "tig/keys.h"
#include "tig/view.h"

/*
 * Option variables.
 */

#define DEFINE_OPTION_VARIABLES(name, type, flags) type opt_##name;
OPTION_INFO(DEFINE_OPTION_VARIABLES);

static struct option_info option_info[] = {
#define DEFINE_OPTION_INFO(name, type, flags) { #name, STRING_SIZE(#name), #type, &opt_##name },
	OPTION_INFO(DEFINE_OPTION_INFO)
};

struct option_info *
find_option_info(struct option_info *option, size_t options, const char *name)
{
	size_t namelen = strlen(name);
	int i;

	for (i = 0; i < options; i++)
		if (enum_equals(option[i], name, namelen))
			return &option[i];

	return NULL;
}