1 /* vifm
2  * Copyright (C) 2001 Ken Steen.
3  * Copyright (C) 2011 xaizek.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19 
20 #ifndef VIFM__CFG__CONFIG_H__
21 #define VIFM__CFG__CONFIG_H__
22 
23 #include <stddef.h> /* size_t wchar_t */
24 
25 #include "../compat/fs_limits.h"
26 #include "../ui/color_scheme.h"
27 #include "../types.h"
28 
29 /* Name of help file in plain text format. */
30 #define VIFM_HELP "vifm-help.txt"
31 
32 /* Name help file in Vim-documentation format. */
33 #define VIFM_VIM_HELP "vifm-app.txt"
34 
35 /* Name of directory in main configuration directory that contains scripts
36  * implicitly included into $PATH for Vifm only. */
37 #define SCRIPTS_DIR "scripts"
38 
39 /* Path to global directory for color schemes. */
40 #define GLOBAL_COLORS_DIR PACKAGE_SYSCONF_DIR "/colors/"
41 
42 /* When to show "../" directories. */
43 typedef enum
44 {
45 	DD_ROOT_PARENT       = 1 << 0, /* In root directories of file systems. */
46 	DD_NONROOT_PARENT    = 1 << 1, /* In non-root directories of file systems. */
47 	DD_TREE_LEAFS_PARENT = 1 << 2, /* In empty directories of tree view. */
48 	NUM_DOT_DIRS         =      3  /* Number of options for compile checks. */
49 }
50 DotDirs;
51 
52 /* Tweaks of case sensitivity. */
53 typedef enum
54 {
55 	CO_PATH_COMPL = 1 << 0, /* Completion of paths. */
56 	CO_GOTO_FILE  = 1 << 1, /* Navigation to files via f/F/,/;. */
57 	NUM_CASE_OPTS =      2  /* Number of case options for compile checks. */
58 }
59 CaseOpts;
60 
61 /* Possible flags that regulate key suggestions. */
62 typedef enum
63 {
64 	SF_NORMAL            = 1 << 0, /* Display in normal mode. */
65 	SF_VISUAL            = 1 << 1, /* Display in visual mode. */
66 	SF_VIEW              = 1 << 2, /* Display in view mode. */
67 	SF_OTHERPANE         = 1 << 3, /* Display list in other pane, if available. */
68 	SF_DELAY             = 1 << 4, /* Postpone suggestions by small delay. */
69 	SF_KEYS              = 1 << 5, /* Include keys suggestions in results. */
70 	SF_MARKS             = 1 << 6, /* Include marks suggestions in results. */
71 	SF_REGISTERS         = 1 << 7, /* Include registers suggestions in results. */
72 	SF_FOLDSUBKEYS       = 1 << 8, /* Fold multiple keys with common prefix. */
73 	NUM_SUGGESTION_FLAGS =      9  /* Number of flags. */
74 }
75 SuggestionFlags;
76 
77 /* What should be displayed as size of a directory in a view by default. */
78 typedef enum
79 {
80 	VDS_SIZE,   /* Size of a directory (not its content). */
81 	VDS_NITEMS, /* Number of items in a directory. */
82 }
83 ViewDirSize;
84 
85 /* Possible values of cfg.show_tab_line. */
86 enum
87 {
88 	STL_NEVER,    /* Tab line should never be displayed. */
89 	STL_MULTIPLE, /* Display tab line only if there are at least two tabs. */
90 	STL_ALWAYS,   /* Display tab line always. */
91 };
92 
93 /* Indexes for cfg.type_decs. */
94 enum
95 {
96 	DECORATION_PREFIX, /* The symbol, which is prepended to file name. */
97 	DECORATION_SUFFIX, /* The symbol, which is appended to file name. */
98 };
99 
100 /* Operations that require user confirmation. */
101 enum
102 {
103 	CONFIRM_DELETE      = 1, /* Deletion to trash. */
104 	CONFIRM_PERM_DELETE = 2, /* Permanent deletion. */
105 };
106 
107 /* Custom view configuration. */
108 enum
109 {
110 	CVO_AUTOCMDS    = 1, /* Trigger autocommands on entering/leaving [v]cv. */
111 	CVO_LOCALOPTS   = 2, /* Reset local options on entering/leaving [v]cv. */
112 	CVO_LOCALFILTER = 4, /* Reset local filter on entering/leaving [v]cv. */
113 };
114 
115 /* Which elements of runtime state should be stored in vifminfo. */
116 enum
117 {
118 	VINFO_OPTIONS   = 1 << 0,  /* 'options'. */
119 	VINFO_FILETYPES = 1 << 1,  /* File associations and viewers. */
120 	VINFO_COMMANDS  = 1 << 2,  /* User-defined :commands. */
121 	VINFO_MARKS     = 1 << 3,  /* Vim-like marks. */
122 	VINFO_BOOKMARKS = 1 << 4,  /* Named bookmarks. */
123 	VINFO_TUI       = 1 << 5,  /* TUI state. */
124 	VINFO_STATE     = 1 << 6,  /* State of filters and multiplexer support. */
125 	VINFO_CS        = 1 << 7,  /* Active color scheme. */
126 	VINFO_REGISTERS = 1 << 8,  /* Contents of registers. */
127 	VINFO_CHISTORY  = 1 << 9,  /* Command-line history. */
128 	VINFO_DHISTORY  = 1 << 10, /* Directory history. */
129 	VINFO_DIRSTACK  = 1 << 11, /* Directory stack. */
130 	VINFO_FHISTORY  = 1 << 12, /* Filter history. */
131 	VINFO_PHISTORY  = 1 << 13, /* Prompt history. */
132 	VINFO_SHISTORY  = 1 << 14, /* Search history. */
133 	VINFO_SAVEDIRS  = 1 << 15, /* Restore last used directories on startup. */
134 	VINFO_TABS      = 1 << 16, /* Restore global or pane tabs. */
135 	NUM_VINFO       = 17,      /* Number of VINFO_* constants. */
136 
137 	EMPTY_VINFO = 0,                   /* Empty set of flags. */
138 	FULL_VINFO  = (1 << NUM_VINFO) - 1 /* Full set of flags. */
139 };
140 
141 /* When cursor position should be adjusted according to directory history. */
142 typedef enum
143 {
144 	CHPOS_STARTUP = 1 << 0, /* On loading views during startup. */
145 	CHPOS_DIRMARK = 1 << 1, /* On navigating to a mark targeting directory. */
146 	CHPOS_ENTER   = 1 << 2, /* On entering a directory by picking it. */
147 	NUM_CHPOS     = 3       /* Number of CHPOS_* constants. */
148 }
149 ChposWhen;
150 
151 /* File decoration description. */
152 typedef struct
153 {
154 	struct matchers_t *matchers; /* Name matcher object. */
155 	char prefix[9];              /* File name prefix. */
156 	char suffix[9];              /* File name suffix. */
157 }
158 file_dec_t;
159 
160 typedef struct config_t
161 {
162 	char home_dir[PATH_MAX + 1];    /* Ends with a slash. */
163 	char config_dir[PATH_MAX + 1];  /* Where local configuration files are
164 	                                   stored. */
165 	char colors_dir[PATH_MAX + 16]; /* Where local color files are stored. */
166 	char data_dir[PATH_MAX + 1];    /* Where to store data files. */
167 
168 	char *session; /* Name of current session or NULL. */
169 
170 	/* This one should be set using trash_set_specs() function. */
171 	char trash_dir[PATH_MAX + 64];
172 	char log_file[PATH_MAX + 8];
173 	char *vi_command;
174 	int vi_cmd_bg;
175 	char *vi_x_command;
176 	int vi_x_cmd_bg;
177 	int use_trash;
178 
179 	/* Whether support of terminal multiplexers is enabled. */
180 	int use_term_multiplexer;
181 
182 	int use_vim_help;
183 	int history_len;
184 
185 	int auto_execute;
186 	int wrap_quick_view;
187 	char *time_format;
188 	/* This one should be set using cfg_set_fuse_home() function. */
189 	char *fuse_home;
190 
191 	col_scheme_t cs; /* Storage of primary (global) color scheme. */
192 
193 	int undo_levels;  /* Maximum number of changes that can be undone. */
194 	int sort_numbers; /* Natural sort of (version) numbers within text. */
195 	int follow_links; /* Follow links on l or Enter. */
196 	int fast_run;
197 
198 	int confirm; /* About which operations user should be asked (CONFIRM_*). */
199 
200 	/* Whether wild menu should be used. */
201 	int wild_menu;
202 	/* Whether wild menu should be a popup instead of a bar. */
203 	int wild_popup;
204 
205 	/* Settings related to suggestions. */
206 	struct
207 	{
208 		/* Combination of SuggestionFlags, configures when and how to show
209 		 * suggestions. */
210 		int flags;
211 		/* Maximum number of register files to display in suggestions. */
212 		int maxregfiles;
213 		/* Delay before displaying suggestions (in milliseconds). */
214 		int delay;
215 	}
216 	sug;
217 
218 	int ignore_case;
219 	int smart_case;
220 	int hl_search;
221 
222 	/* Values of these two are combinations of VINFO_* flags. */
223 	int vifm_info;       /* What is stored in vifminfo file. */
224 	int session_options; /* What is stored in a session. */
225 
226 	char *shell;          /* Shell interpreter command. */
227 	char *shell_cmd_flag; /* Argument for the shell to pass command. */
228 
229 	int scroll_off;
230 	int gdefault;
231 	int scroll_bind;
232 	int wrap_scan;
233 	int inc_search;
234 	int selection_is_primary; /* For yy, dd and DD: act on selection not file. */
235 	int tab_switches_pane; /* Whether <tab> is switch pane or history forward. */
236 	int use_system_calls; /* Prefer performing operations with system calls. */
237 	int tab_stop;
238 	char *ruler_format;
239 	char *status_line;
240 	int lines; /* Terminal height in lines. */
241 	int columns; /* Terminal width in characters. */
242 	/* Controls displaying of dot directories.  Combination of DotDirs flags. */
243 	int dot_dirs;
244 	/* File type specific prefixes and suffixes ('classify'). */
245 	char type_decs[FT_COUNT][2][9];
246 	/* File name specific prefixes and suffixes ('classify'). */
247 	file_dec_t *name_decs;
248 	/* Size of name_decs array. */
249 	int name_dec_count;
250 	int filter_inverted_by_default; /* Default inversion value for :filter. */
251 
252 	/* Invocation formats for external applications. */
253 	char *apropos_prg; /* apropos tool calling pattern. */
254 	char *find_prg;    /* find tool calling pattern. */
255 	char *grep_prg;    /* grep tool calling pattern. */
256 	char *locate_prg;  /* locate tool calling pattern. */
257 	char *delete_prg;  /* File removal application. */
258 	char *media_prg;   /* Helper for managing media devices. */
259 
260 	/* Message shortening controlled by 'shortmess'. */
261 	int tail_tab_line_paths;   /* Display only last directory in tab line. */
262 	int trunc_normal_sb_msgs;  /* Truncate normal status bar msgs if needed. */
263 	int shorten_title_paths;   /* Use tilde shortening in view titles. */
264 	int short_term_mux_titles; /* Use only file name for titles of screen/tmux. */
265 
266 	/* Comma-separated list of file system types which are slow to respond. */
267 	char *slow_fs_list;
268 
269 	/* Coma separated list of places to look for relative path to directories. */
270 	char *cd_path;
271 
272 	/* Whether there should be reserved single character width space before and
273 	 * after file list column inside a view and first and last columns and lines
274 	 * for a quick view. */
275 	int extra_padding;
276 
277 	/* Whether side borders are visible (separator in the middle isn't
278 	 * affected). */
279 	int side_borders_visible;
280 
281 	/* Whether employing Unicode characters in the interface is allowed. */
282 	int use_unicode_characters;
283 
284 	/* Whether vertical splitter should change its width to equalize view
285 	 * sizes. */
286 	int flexible_splitter;
287 
288 	/* Whether statusline is visible. */
289 	int display_statusline;
290 
291 	/* Per line pattern for borders. */
292 	char *border_filler;
293 
294 	/* Whether terminal title should be updated or not. */
295 	int set_title;
296 
297 	/* Whether directory path should always be resolved to real path (all symbolic
298 	 * link expanded). */
299 	int chase_links;
300 
301 	int timeout_len;     /* Maximum period on waiting for the input. */
302 	int min_timeout_len; /* Minimum period on waiting for the input. */
303 
304 	char word_chars[256]; /* Whether corresponding character is a word char. */
305 
306 	ViewDirSize view_dir_size; /* Type of size display for directories in view. */
307 
308 	/* Controls use of fast file cloning for file systems that support it. */
309 	int fast_file_cloning;
310 
311 	/* Whether various things should be reset on entering/leaving custom views. */
312 	int cvoptions;
313 
314 	/* Tweaks of case sensitivity.  Values of these variables change the default
315 	 * behaviour with regard to case sensitivity of various aspects.  These are
316 	 * bit sets of CO_* flags. */
317 	int case_override; /* Flag set here means the fact of the override. */
318 	int case_ignore;   /* Flag here means case should be either always ignored or
319 	                      always respected. */
320 
321 	/* Settings of size formatting. */
322 	struct
323 	{
324 		int base;          /* Base of units to use (either 1000 or 1024). */
325 		int precision;     /* Number of digits after dot to consider (0 for old
326 		                      behaviour). */
327 		int ieci_prefixes; /* When base is 1024, whether to say KiB instead of K. */
328 		int space;         /* Whether a space should be displayed between numbers
329 		                      and unit symbols. */
330 	}
331 	sizefmt;
332 
333 	/* Settings related to tabs. */
334 	int pane_tabs;     /* Whether tabs are local to panes. */
335 	int show_tab_line; /* When tab line should be displayed. */
336 	char *tab_prefix;  /* Format of single tab's label prefix. */
337 	char *tab_label;   /* Format of a single tab's label. */
338 	char *tab_suffix;  /* Format of single tab's label suffix. */
339 
340 	/* Control over automatic cursor positioning. */
341 	int auto_ch_pos; /* Weird option that drops positions from histories. */
342 	int ch_pos_on;   /* List of cases when historical cursor position is used. */
343 }
344 config_t;
345 
346 extern config_t cfg;
347 
348 /* Initializes cfg global variable with initial values.  Re-initialization is
349  * not supported. */
350 void cfg_init(void);
351 
352 /* Searches for configuration file and directories, stores them and ensures
353  * existence of some of them.  This routine is separated from cfg_init() to
354  * allow logging of path discovery. */
355 void cfg_discover_paths(void);
356 
357 /* Sources vifmrc file (pointed to by the $MYVIFMRC). */
358 void cfg_load(void);
359 
360 /* Returns non-zero on error. */
361 int cfg_source_file(const char filename[]);
362 
363 /* Gets editor invocation command.  Sets *bg to indicate whether the command
364  * should be executed in background.  Returns pointer to a string from
365  * configuration variables. */
366 const char * cfg_get_vicmd(int *bg);
367 
368 /* Clears histories.  Leaving directory history as is used during restart. */
369 void cfg_clear_histories(int clear_dhistory);
370 
371 /* Changes size of all histories.  Zero or negative length disables history. */
372 void cfg_resize_histories(int new_len);
373 
374 /* Sets value of cfg.fuse_home.  Returns non-zero in case of error, otherwise
375  * zero is returned. */
376 int cfg_set_fuse_home(const char new_value[]);
377 
378 /* Sets whether support of terminal multiplexers is enabled. */
379 void cfg_set_use_term_multiplexer(int use_term_multiplexer);
380 
381 /* Sets shell invocation command. */
382 void cfg_set_shell(const char shell[]);
383 
384 /* Checks whether given wide character should be considered as part of a word
385  * according to current settings.  Returns non-zero if so, otherwise zero is
386  * returned. */
387 int cfg_is_word_wchar(wchar_t c);
388 
389 /* Whether ../ directory should appear in file list.  Returns non-zero if so,
390  * and zero otherwise. */
391 int cfg_parent_dir_is_visible(int in_root);
392 
393 /* Checks whether file deletion (possibly into trash) requires user confirmation
394  * according to current configuration.  Returns non-zero if so, otherwise zero
395  * is returned. */
396 int cfg_confirm_delete(int to_trash);
397 
398 /* Checks whether cursor should be automatically positioned in specified case.
399  * Returns non-zero if so, otherwise zero is returned. */
400 int cfg_ch_pos_on(ChposWhen when);
401 
402 #endif /* VIFM__CFG__CONFIG_H__ */
403 
404 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
405 /* vim: set cinoptions+=t0 filetype=c : */
406