Add support for custom strftime(3) date formats
[tig.git] / include / tig / options.h
blob8933acf2adb4d549b4c06271dd43fe4104952368
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 #ifndef TIG_USER_CONFIG
30 #define TIG_USER_CONFIG "~/.tigrc"
31 #endif
33 #define OPTION_INFO(_) \
34 _(blame_options, const char **, VIEW_BLAME_LIKE) \
35 _(blame_view, view_settings, VIEW_NO_FLAGS) \
36 _(blob_view, view_settings, VIEW_NO_FLAGS) \
37 _(commit_order, enum commit_order, VIEW_LOG_LIKE) \
38 _(diff_context, int, VIEW_DIFF_LIKE) \
39 _(diff_options, const char **, VIEW_DIFF_LIKE) \
40 _(diff_view, view_settings, VIEW_NO_FLAGS) \
41 _(editor_line_number, bool, VIEW_NO_FLAGS) \
42 _(file_args, const char **, VIEW_NO_FLAGS) \
43 _(file_filter, bool, VIEW_DIFF_LIKE | VIEW_LOG_LIKE) \
44 _(focus_child, bool, VIEW_NO_FLAGS) \
45 _(git_colors, const char **, VIEW_NO_FLAGS) \
46 _(grep_view, view_settings, VIEW_NO_FLAGS) \
47 _(horizontal_scroll, double, VIEW_NO_FLAGS) \
48 _(id_width, int, VIEW_NO_FLAGS) \
49 _(ignore_case, bool, VIEW_NO_FLAGS) \
50 _(ignore_space, enum ignore_space, VIEW_DIFF_LIKE) \
51 _(line_graphics, enum graphic, VIEW_NO_FLAGS) \
52 _(log_options, const char **, VIEW_LOG_LIKE) \
53 _(log_view, view_settings, VIEW_NO_FLAGS) \
54 _(mailmap, bool, VIEW_DIFF_LIKE | VIEW_LOG_LIKE) \
55 _(main_options, const char **, VIEW_LOG_LIKE) \
56 _(main_view, view_settings, VIEW_NO_FLAGS) \
57 _(mouse, bool, VIEW_NO_FLAGS) \
58 _(mouse_scroll, int, VIEW_NO_FLAGS) \
59 _(pager_view, view_settings, VIEW_NO_FLAGS) \
60 _(reference_format, struct ref_format **, VIEW_NO_FLAGS) \
61 _(refresh_interval, int, VIEW_NO_FLAGS) \
62 _(refresh_mode, enum refresh_mode, VIEW_NO_FLAGS) \
63 _(refs_view, view_settings, VIEW_NO_FLAGS) \
64 _(rev_args, const char **, VIEW_NO_FLAGS) \
65 _(show_changes, bool, VIEW_NO_FLAGS) \
66 _(show_notes, bool, VIEW_NO_FLAGS) \
67 _(split_view_height, double, VIEW_RESET_DISPLAY) \
68 _(split_view_width, double, VIEW_RESET_DISPLAY) \
69 _(stage_view, view_settings, VIEW_NO_FLAGS) \
70 _(stash_view, view_settings, VIEW_NO_FLAGS) \
71 _(status_untracked_dirs, bool, VIEW_STATUS_LIKE) \
72 _(status_view, view_settings, VIEW_NO_FLAGS) \
73 _(tab_size, int, VIEW_NO_FLAGS) \
74 _(tree_view, view_settings, VIEW_NO_FLAGS) \
75 _(vertical_split, enum vertical_split, VIEW_RESET_DISPLAY | VIEW_DIFF_LIKE) \
76 _(wrap_lines, bool, VIEW_NO_FLAGS) \
77 _(wrap_search, bool, VIEW_NO_FLAGS) \
79 #define DEFINE_OPTION_EXTERNS(name, type, flags) extern type opt_##name;
80 OPTION_INFO(DEFINE_OPTION_EXTERNS)
83 * View column options.
86 #define AUTHOR_COLUMN_OPTIONS(_) \
87 _(display, enum author, VIEW_NO_FLAGS) \
88 _(width, int, VIEW_NO_FLAGS) \
90 #define COMMIT_TITLE_COLUMN_OPTIONS(_) \
91 _(display, bool, VIEW_NO_FLAGS) \
92 _(graph, enum graph_display, VIEW_LOG_LIKE) \
93 _(refs, bool, VIEW_NO_FLAGS) \
94 _(overflow, int, VIEW_NO_FLAGS) \
95 _(width, int, VIEW_NO_FLAGS) \
97 #define DATE_COLUMN_OPTIONS(_) \
98 _(display, enum date, VIEW_NO_FLAGS) \
99 _(local, bool, VIEW_NO_FLAGS) \
100 _(format, const char *, VIEW_NO_FLAGS) \
101 _(width, int, VIEW_NO_FLAGS) \
103 #define FILE_NAME_COLUMN_OPTIONS(_) \
104 _(display, enum filename, VIEW_GREP_LIKE) \
105 _(width, int, VIEW_NO_FLAGS) \
107 #define FILE_SIZE_COLUMN_OPTIONS(_) \
108 _(display, enum file_size, VIEW_NO_FLAGS) \
109 _(width, int, VIEW_NO_FLAGS) \
111 #define ID_COLUMN_OPTIONS(_) \
112 _(display, bool, VIEW_NO_FLAGS) \
113 _(color, bool, VIEW_NO_FLAGS) \
114 _(width, int, VIEW_NO_FLAGS) \
116 #define LINE_NUMBER_COLUMN_OPTIONS(_) \
117 _(display, bool, VIEW_NO_FLAGS) \
118 _(interval, int, VIEW_NO_FLAGS) \
119 _(width, int, VIEW_NO_FLAGS) \
121 #define MODE_COLUMN_OPTIONS(_) \
122 _(display, bool, VIEW_NO_FLAGS) \
123 _(width, int, VIEW_NO_FLAGS) \
125 #define REF_COLUMN_OPTIONS(_) \
126 _(display, bool, VIEW_NO_FLAGS) \
127 _(width, int, VIEW_NO_FLAGS) \
129 #define SECTION_COLUMN_OPTIONS(_) \
130 _(type, enum line_type, VIEW_NO_FLAGS) \
131 _(text, const char *, VIEW_NO_FLAGS) \
133 #define STATUS_COLUMN_OPTIONS(_) \
134 _(display, enum status_label, VIEW_NO_FLAGS) \
135 _(width, int, VIEW_NO_FLAGS) \
137 #define TEXT_COLUMN_OPTIONS(_) \
138 _(display, bool, VIEW_NO_FLAGS) \
139 _(commit_title_overflow, int, VIEW_NO_FLAGS) \
140 _(width, int, VIEW_NO_FLAGS) \
142 #define COLUMN_OPTIONS(_) \
143 _(author, AUTHOR, AUTHOR_COLUMN_OPTIONS) \
144 _(commit_title, COMMIT_TITLE, COMMIT_TITLE_COLUMN_OPTIONS) \
145 _(date, DATE, DATE_COLUMN_OPTIONS) \
146 _(file_name, FILE_NAME, FILE_NAME_COLUMN_OPTIONS) \
147 _(file_size, FILE_SIZE, FILE_SIZE_COLUMN_OPTIONS) \
148 _(id, ID, ID_COLUMN_OPTIONS) \
149 _(line_number, LINE_NUMBER, LINE_NUMBER_COLUMN_OPTIONS) \
150 _(mode, MODE, MODE_COLUMN_OPTIONS) \
151 _(ref, REF, REF_COLUMN_OPTIONS) \
152 _(section, SECTION, SECTION_COLUMN_OPTIONS) \
153 _(status, STATUS, STATUS_COLUMN_OPTIONS) \
154 _(text, TEXT, TEXT_COLUMN_OPTIONS) \
156 #define DEFINE_COLUMN_OPTIONS_STRUCT_VALUE(name, type, flags) type name;
158 #define DEFINE_COLUMN_OPTIONS_STRUCT(name, id, options) \
159 struct name##_options { \
160 options(DEFINE_COLUMN_OPTIONS_STRUCT_VALUE) \
161 } name;
163 union view_column_options {
164 COLUMN_OPTIONS(DEFINE_COLUMN_OPTIONS_STRUCT)
168 * Global state variables.
171 extern iconv_t opt_iconv_out;
172 extern char opt_editor[SIZEOF_STR];
173 extern const char **opt_cmdline_args;
176 * Mapping between options and command argument mapping.
179 void update_options_from_argv(const char *argv[]);
181 const char *ignore_space_arg();
182 const char *commit_order_arg();
183 const char *commit_order_arg_with_graph(enum graph_display graph_display);
184 const char *log_custom_pretty_arg();
185 const char *use_mailmap_arg();
186 const char *diff_context_arg();
187 const char *show_notes_arg();
190 * Option loading and parsing.
193 struct option_info {
194 const char *name;
195 size_t namelen;
196 const char *type;
197 void *value;
198 int flags;
199 bool seen;
202 struct option_info *find_option_info(struct option_info *option, size_t options, const char *prefix, const char *name);
203 enum status_code parse_option(struct option_info *option, const char *prefix, const char *arg);
204 struct option_info *find_column_option_info(enum view_column_type type, union view_column_options *opts,
205 const char *option, struct option_info *column_info, const char **column_name);
206 enum status_code parse_int(int *opt, const char *arg, int min, int max);
207 enum status_code parse_step(double *opt, const char *arg);
208 enum status_code set_option(const char *opt, int argc, const char *argv[]);
209 enum status_code load_options(void);
210 enum status_code load_git_config(void);
211 enum status_code save_options(const char *path);
212 const char *format_option_value(const struct option_info *option, char buf[], size_t bufsize);
214 #endif
215 /* vim: set ts=8 sw=8 noexpandtab: */