Make view columns configurable
[tig.git] / include / tig / options.h
blobcf0c6ec04d2be4d8a079e09099a7b8bcbf216e98
1 /* Copyright (c) 2006-2014 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"
21 * Option variables.
24 #define OPTION_INFO(_) \
25 _(blame_options, const char **, VIEW_BLAME_LIKE) \
26 _(blame_view, const char **, VIEW_NO_FLAGS) \
27 _(blob_view, const char **, VIEW_NO_FLAGS) \
28 _(commit_order, enum commit_order, VIEW_LOG_LIKE) \
29 _(diff_context, int, VIEW_DIFF_LIKE) \
30 _(diff_options, const char **, VIEW_DIFF_LIKE) \
31 _(diff_view, const char **, VIEW_NO_FLAGS) \
32 _(editor_line_number, bool, VIEW_NO_FLAGS) \
33 _(file_filter, bool, VIEW_DIFF_LIKE | VIEW_LOG_LIKE) \
34 _(focus_child, bool, VIEW_NO_FLAGS) \
35 _(grep_view, const char **, VIEW_NO_FLAGS) \
36 _(horizontal_scroll, double, VIEW_NO_FLAGS) \
37 _(id_width, int, VIEW_NO_FLAGS) \
38 _(ignore_case, bool, VIEW_NO_FLAGS) \
39 _(ignore_space, enum ignore_space, VIEW_DIFF_LIKE) \
40 _(line_graphics, enum graphic, VIEW_NO_FLAGS) \
41 _(log_view, const char **, VIEW_NO_FLAGS) \
42 _(main_view, const char **, VIEW_NO_FLAGS) \
43 _(mouse, bool, VIEW_NO_FLAGS) \
44 _(mouse_scroll, int, VIEW_NO_FLAGS) \
45 _(pager_view, const char **, VIEW_NO_FLAGS) \
46 _(read_git_colors, bool, VIEW_NO_FLAGS) \
47 _(refs_view, const char **, VIEW_NO_FLAGS) \
48 _(show_changes, bool, VIEW_NO_FLAGS) \
49 _(show_notes, bool, VIEW_NO_FLAGS) \
50 _(split_view_height, double, VIEW_RESET_DISPLAY) \
51 _(stage_view, const char **, VIEW_NO_FLAGS) \
52 _(status_untracked_dirs, bool, VIEW_STATUS_LIKE) \
53 _(stash_view, const char **, VIEW_NO_FLAGS) \
54 _(tab_size, int, VIEW_NO_FLAGS) \
55 _(tree_view, const char **, VIEW_NO_FLAGS) \
56 _(vertical_split, enum vertical_split, VIEW_RESET_DISPLAY | VIEW_DIFF_LIKE) \
57 _(wrap_lines, bool, VIEW_NO_FLAGS) \
59 #define DEFINE_OPTION_EXTERNS(name, type, flags) extern type opt_##name;
60 OPTION_INFO(DEFINE_OPTION_EXTERNS);
63 * View column options.
66 #define AUTHOR_COLUMN_OPTIONS(_) \
67 _(show, enum author, VIEW_NO_FLAGS) \
68 _(width, int, VIEW_NO_FLAGS) \
70 #define COMMIT_TITLE_COLUMN_OPTIONS(_) \
71 _(show, bool, VIEW_NO_FLAGS) \
72 _(graph, bool, VIEW_LOG_LIKE) \
73 _(refs, bool, VIEW_NO_FLAGS) \
74 _(overflow, int, VIEW_NO_FLAGS) \
75 _(width, int, VIEW_NO_FLAGS) \
77 #define DATE_COLUMN_OPTIONS(_) \
78 _(show, enum date, VIEW_NO_FLAGS) \
79 _(width, int, VIEW_NO_FLAGS) \
81 #define FILE_NAME_COLUMN_OPTIONS(_) \
82 _(show, enum filename, VIEW_GREP_LIKE) \
83 _(width, int, VIEW_NO_FLAGS) \
85 #define FILE_SIZE_COLUMN_OPTIONS(_) \
86 _(show, enum file_size, VIEW_NO_FLAGS) \
87 _(width, int, VIEW_NO_FLAGS) \
89 #define ID_COLUMN_OPTIONS(_) \
90 _(show, bool, VIEW_NO_FLAGS) \
91 _(color, bool, VIEW_NO_FLAGS) \
92 _(width, int, VIEW_NO_FLAGS) \
94 #define LINE_NUMBER_COLUMN_OPTIONS(_) \
95 _(show, bool, VIEW_NO_FLAGS) \
96 _(interval, int, VIEW_NO_FLAGS) \
97 _(width, int, VIEW_NO_FLAGS) \
99 #define MODE_COLUMN_OPTIONS(_) \
100 _(show, bool, VIEW_NO_FLAGS) \
101 _(width, int, VIEW_NO_FLAGS) \
103 #define REF_COLUMN_OPTIONS(_) \
104 _(show, bool, VIEW_NO_FLAGS) \
105 _(width, int, VIEW_NO_FLAGS) \
107 #define TEXT_COLUMN_OPTIONS(_) \
108 _(show, bool, VIEW_NO_FLAGS) \
109 _(commit_title_overflow, int, VIEW_NO_FLAGS) \
110 _(width, int, VIEW_NO_FLAGS) \
112 #define COLUMN_OPTIONS(_) \
113 _(author, AUTHOR, AUTHOR_COLUMN_OPTIONS) \
114 _(commit_title, COMMIT_TITLE, COMMIT_TITLE_COLUMN_OPTIONS) \
115 _(date, DATE, DATE_COLUMN_OPTIONS) \
116 _(file_name, FILE_NAME, FILE_NAME_COLUMN_OPTIONS) \
117 _(file_size, FILE_SIZE, FILE_SIZE_COLUMN_OPTIONS) \
118 _(id, ID, ID_COLUMN_OPTIONS) \
119 _(line_number, LINE_NUMBER, LINE_NUMBER_COLUMN_OPTIONS) \
120 _(mode, MODE, MODE_COLUMN_OPTIONS) \
121 _(ref, REF, REF_COLUMN_OPTIONS) \
122 _(text, TEXT, TEXT_COLUMN_OPTIONS) \
124 #define DEFINE_COLUMN_OPTIONS_STRUCT_VALUE(name, type, flags) type name;
126 #define DEFINE_COLUMN_OPTIONS_STRUCT(name, id, options) \
127 struct name##_options { \
128 options(DEFINE_COLUMN_OPTIONS_STRUCT_VALUE) \
129 } name;
131 union view_column_options {
132 COLUMN_OPTIONS(DEFINE_COLUMN_OPTIONS_STRUCT);
136 * Global state variables.
139 extern iconv_t opt_iconv_out;
140 extern char opt_editor[SIZEOF_STR];
141 extern const char **opt_cmdline_argv;
142 extern const char **opt_rev_argv;
143 extern const char **opt_file_argv;
144 extern char opt_env_lines[64];
145 extern char opt_env_columns[64];
146 extern char *opt_env[];
149 * Mapping between options and command argument mapping.
152 void update_options_from_argv(const char *argv[]);
154 const char *ignore_space_arg();
155 const char *commit_order_arg();
156 const char *diff_context_arg();
157 const char *show_notes_arg();
160 * Option loading and parsing.
163 struct option_info {
164 const char *name;
165 size_t namelen;
166 const char *type;
167 void *value;
168 bool seen;
171 struct option_info *find_option_info(struct option_info *option, size_t options, const char *name);
172 enum status_code parse_option(struct option_info *option, const char *arg);
173 enum status_code parse_int(int *opt, const char *arg, int min, int max);
174 enum status_code parse_step(double *opt, const char *arg);
175 enum status_code set_option(const char *opt, int argc, const char *argv[]);
176 int load_options(void);
177 int load_git_config(void);
179 #endif
180 /* vim: set ts=8 sw=8 noexpandtab: */