Merge pull request #457 from vivien/text-variable
[tig.git] / include / tig / options.h
blob737489a02e9711ef8ae13d9999ea58b32c3b0fa6
1 /* Copyright (c) 2006-2015 Jonas Fonseca <jonas.fonseca@gmail.com>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #ifndef TIG_OPTIONS_H
15 #define TIG_OPTIONS_H
17 #include "tig/tig.h"
18 #include "tig/util.h"
19 #include "tig/line.h"
22 * Option variables.
25 struct ref_format;
26 struct view_column;
27 typedef struct view_column *view_settings;
29 #define OPTION_INFO(_) \
30 _(blame_options, const char **, VIEW_BLAME_LIKE) \
31 _(blame_view, view_settings, VIEW_NO_FLAGS) \
32 _(blob_view, view_settings, VIEW_NO_FLAGS) \
33 _(commit_order, enum commit_order, VIEW_LOG_LIKE) \
34 _(diff_context, int, VIEW_DIFF_LIKE) \
35 _(diff_options, const char **, VIEW_DIFF_LIKE) \
36 _(diff_view, view_settings, VIEW_NO_FLAGS) \
37 _(editor_line_number, bool, VIEW_NO_FLAGS) \
38 _(file_args, const char **, VIEW_NO_FLAGS) \
39 _(file_filter, bool, VIEW_DIFF_LIKE | VIEW_LOG_LIKE) \
40 _(focus_child, bool, VIEW_NO_FLAGS) \
41 _(git_colors, const char **, VIEW_NO_FLAGS) \
42 _(grep_view, view_settings, VIEW_NO_FLAGS) \
43 _(horizontal_scroll, double, VIEW_NO_FLAGS) \
44 _(id_width, int, VIEW_NO_FLAGS) \
45 _(ignore_case, bool, VIEW_NO_FLAGS) \
46 _(ignore_space, enum ignore_space, VIEW_DIFF_LIKE) \
47 _(line_graphics, enum graphic, VIEW_NO_FLAGS) \
48 _(log_options, const char **, VIEW_LOG_LIKE) \
49 _(log_view, view_settings, VIEW_NO_FLAGS) \
50 _(mailmap, bool, VIEW_DIFF_LIKE | VIEW_LOG_LIKE) \
51 _(main_options, const char **, VIEW_LOG_LIKE) \
52 _(main_view, view_settings, VIEW_NO_FLAGS) \
53 _(mouse, bool, VIEW_NO_FLAGS) \
54 _(mouse_scroll, int, VIEW_NO_FLAGS) \
55 _(pager_view, view_settings, VIEW_NO_FLAGS) \
56 _(reference_format, struct ref_format **, VIEW_NO_FLAGS) \
57 _(refresh_interval, int, VIEW_NO_FLAGS) \
58 _(refresh_mode, enum refresh_mode, VIEW_NO_FLAGS) \
59 _(refs_view, view_settings, VIEW_NO_FLAGS) \
60 _(rev_args, const char **, VIEW_NO_FLAGS) \
61 _(show_changes, bool, VIEW_NO_FLAGS) \
62 _(show_notes, bool, VIEW_NO_FLAGS) \
63 _(split_view_height, double, VIEW_RESET_DISPLAY) \
64 _(split_view_width, double, VIEW_RESET_DISPLAY) \
65 _(stage_view, view_settings, VIEW_NO_FLAGS) \
66 _(stash_view, view_settings, VIEW_NO_FLAGS) \
67 _(status_untracked_dirs, bool, VIEW_STATUS_LIKE) \
68 _(status_view, view_settings, VIEW_NO_FLAGS) \
69 _(tab_size, int, VIEW_NO_FLAGS) \
70 _(tree_view, view_settings, VIEW_NO_FLAGS) \
71 _(vertical_split, enum vertical_split, VIEW_RESET_DISPLAY | VIEW_DIFF_LIKE) \
72 _(wrap_lines, bool, VIEW_NO_FLAGS) \
73 _(wrap_search, bool, VIEW_NO_FLAGS) \
75 #define DEFINE_OPTION_EXTERNS(name, type, flags) extern type opt_##name;
76 OPTION_INFO(DEFINE_OPTION_EXTERNS)
79 * View column options.
82 #define AUTHOR_COLUMN_OPTIONS(_) \
83 _(display, enum author, VIEW_NO_FLAGS) \
84 _(width, int, VIEW_NO_FLAGS) \
86 #define COMMIT_TITLE_COLUMN_OPTIONS(_) \
87 _(display, bool, VIEW_NO_FLAGS) \
88 _(graph, enum graph_display, VIEW_LOG_LIKE) \
89 _(refs, bool, VIEW_NO_FLAGS) \
90 _(overflow, int, VIEW_NO_FLAGS) \
91 _(width, int, VIEW_NO_FLAGS) \
93 #define DATE_COLUMN_OPTIONS(_) \
94 _(display, enum date, VIEW_NO_FLAGS) \
95 _(width, int, VIEW_NO_FLAGS) \
97 #define FILE_NAME_COLUMN_OPTIONS(_) \
98 _(display, enum filename, VIEW_GREP_LIKE) \
99 _(width, int, VIEW_NO_FLAGS) \
101 #define FILE_SIZE_COLUMN_OPTIONS(_) \
102 _(display, enum file_size, VIEW_NO_FLAGS) \
103 _(width, int, VIEW_NO_FLAGS) \
105 #define ID_COLUMN_OPTIONS(_) \
106 _(display, bool, VIEW_NO_FLAGS) \
107 _(color, bool, VIEW_NO_FLAGS) \
108 _(width, int, VIEW_NO_FLAGS) \
110 #define LINE_NUMBER_COLUMN_OPTIONS(_) \
111 _(display, bool, VIEW_NO_FLAGS) \
112 _(interval, int, VIEW_NO_FLAGS) \
113 _(width, int, VIEW_NO_FLAGS) \
115 #define MODE_COLUMN_OPTIONS(_) \
116 _(display, bool, VIEW_NO_FLAGS) \
117 _(width, int, VIEW_NO_FLAGS) \
119 #define REF_COLUMN_OPTIONS(_) \
120 _(display, bool, VIEW_NO_FLAGS) \
121 _(width, int, VIEW_NO_FLAGS) \
123 #define SECTION_COLUMN_OPTIONS(_) \
124 _(type, enum line_type, VIEW_NO_FLAGS) \
125 _(text, const char *, VIEW_NO_FLAGS) \
127 #define STATUS_COLUMN_OPTIONS(_) \
128 _(display, enum status_label, VIEW_NO_FLAGS) \
129 _(width, int, VIEW_NO_FLAGS) \
131 #define TEXT_COLUMN_OPTIONS(_) \
132 _(display, bool, VIEW_NO_FLAGS) \
133 _(commit_title_overflow, int, VIEW_NO_FLAGS) \
134 _(width, int, VIEW_NO_FLAGS) \
136 #define COLUMN_OPTIONS(_) \
137 _(author, AUTHOR, AUTHOR_COLUMN_OPTIONS) \
138 _(commit_title, COMMIT_TITLE, COMMIT_TITLE_COLUMN_OPTIONS) \
139 _(date, DATE, DATE_COLUMN_OPTIONS) \
140 _(file_name, FILE_NAME, FILE_NAME_COLUMN_OPTIONS) \
141 _(file_size, FILE_SIZE, FILE_SIZE_COLUMN_OPTIONS) \
142 _(id, ID, ID_COLUMN_OPTIONS) \
143 _(line_number, LINE_NUMBER, LINE_NUMBER_COLUMN_OPTIONS) \
144 _(mode, MODE, MODE_COLUMN_OPTIONS) \
145 _(ref, REF, REF_COLUMN_OPTIONS) \
146 _(section, SECTION, SECTION_COLUMN_OPTIONS) \
147 _(status, STATUS, STATUS_COLUMN_OPTIONS) \
148 _(text, TEXT, TEXT_COLUMN_OPTIONS) \
150 #define DEFINE_COLUMN_OPTIONS_STRUCT_VALUE(name, type, flags) type name;
152 #define DEFINE_COLUMN_OPTIONS_STRUCT(name, id, options) \
153 struct name##_options { \
154 options(DEFINE_COLUMN_OPTIONS_STRUCT_VALUE) \
155 } name;
157 union view_column_options {
158 COLUMN_OPTIONS(DEFINE_COLUMN_OPTIONS_STRUCT)
162 * Global state variables.
165 extern iconv_t opt_iconv_out;
166 extern char opt_editor[SIZEOF_STR];
167 extern const char **opt_cmdline_args;
170 * Mapping between options and command argument mapping.
173 void update_options_from_argv(const char *argv[]);
175 const char *ignore_space_arg();
176 const char *commit_order_arg();
177 const char *commit_order_arg_with_graph(enum graph_display graph_display);
178 const char *log_custom_pretty_arg();
179 const char *use_mailmap_arg();
180 const char *diff_context_arg();
181 const char *show_notes_arg();
184 * Option loading and parsing.
187 struct option_info {
188 const char *name;
189 size_t namelen;
190 const char *type;
191 void *value;
192 int flags;
193 bool seen;
196 struct option_info *find_option_info(struct option_info *option, size_t options, const char *prefix, const char *name);
197 enum status_code parse_option(struct option_info *option, const char *prefix, const char *arg);
198 struct option_info *find_column_option_info(enum view_column_type type, union view_column_options *opts,
199 const char *option, struct option_info *column_info, const char **column_name);
200 enum status_code parse_int(int *opt, const char *arg, int min, int max);
201 enum status_code parse_step(double *opt, const char *arg);
202 enum status_code set_option(const char *opt, int argc, const char *argv[]);
203 enum status_code load_options(void);
204 enum status_code load_git_config(void);
205 enum status_code save_options(const char *path);
206 const char *format_option_value(const struct option_info *option, char buf[], size_t bufsize);
208 #endif
209 /* vim: set ts=8 sw=8 noexpandtab: */