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__UI__COLOR_SCHEME_H__ 21 #define VIFM__UI__COLOR_SCHEME_H__ 22 23 #include <regex.h> /* regex_t */ 24 25 #include <stddef.h> /* size_t */ 26 27 #include "../compat/fs_limits.h" 28 #include "colors.h" 29 30 /* Pseudo name of the default built-in color scheme. */ 31 #define DEF_CS_NAME "<built-in default>" 32 33 /* State of a color scheme. */ 34 typedef enum 35 { 36 CSS_NORMAL, /* Color scheme is ready to be used. */ 37 CSS_DEFAULTED, /* Color scheme was defaulted to have builtin values. */ 38 CSS_LOADING, /* Color scheme is being constructed at the moment. */ 39 CSS_BROKEN, /* Color scheme is broken and should be defaulted. */ 40 } 41 ColorSchemeState; 42 43 struct matchers_t; 44 45 /* Single file highlight description. */ 46 typedef struct 47 { 48 struct matchers_t *matchers; /* Name matcher object. */ 49 col_attr_t hi; /* File appearance parameters. */ 50 } 51 file_hi_t; 52 53 /* Color scheme description. */ 54 typedef struct 55 { 56 char name[NAME_MAX + 1]; /* Name of the color scheme. */ 57 ColorSchemeState state; /* Current state. */ 58 col_attr_t color[MAXNUM_COLOR]; /* Colors with their attributes. */ 59 int pair[MAXNUM_COLOR]; /* Pairs for corresponding color. */ 60 61 file_hi_t *file_hi; /* List of file highlight preferences. */ 62 int file_hi_count; /* Number of file highlight definitions. */ 63 } 64 col_scheme_t; 65 66 /* Names of highlight groups. Contains MAXNUM_COLOR elements. */ 67 extern char *HI_GROUPS[]; 68 /* Descriptions of highlight groups. Contains MAXNUM_COLOR elements. */ 69 extern const char *HI_GROUPS_DESCR[]; 70 /* Names of light versions of standard colors. */ 71 extern char *LIGHT_COLOR_NAMES[8]; 72 /* Names from 256-color palette. */ 73 extern char *XTERM256_COLOR_NAMES[256]; 74 75 /* Loads primary color scheme specified by the name. */ 76 void cs_load_primary(const char name[]); 77 78 /* Loads the first color scheme in the order given that exists and is supported 79 * by the terminal. If none matches, current one remains unchanged. */ 80 void cs_load_primary_list(char *names[], int count); 81 82 /* Loads color pairs of all active color schemes, so the colors are actually 83 * visible on the screen. */ 84 void cs_load_pairs(void); 85 86 /* Resets all color schemes and everything related to default (or empty) 87 * state. */ 88 void cs_load_defaults(void); 89 90 /* Resets color scheme to default builtin values and reloads them (color 91 * pairs). */ 92 void cs_reset(col_scheme_t *cs); 93 94 /* Copies data from *from to *to. */ 95 void cs_assign(col_scheme_t *to, const col_scheme_t *from); 96 97 /* The color scheme with the longest matching directory path is the one that 98 * is chosen. Left chooses the left pane over the right one. Return non-zero 99 * if non-default color scheme should be used for the specified directory, 100 * otherwise zero is returned. */ 101 int cs_load_local(int left, const char dir[]); 102 103 /* Checks whether local color schemes do not have file extensions. Returns 104 * non-zero if so, otherwise zero is returned. */ 105 int cs_have_no_extensions(void); 106 107 /* Adds ".vifm" extension to color scheme files as per new format. */ 108 void cs_rename_all(void); 109 110 /* Lists names of all color schemes. Allocates an array of strings, which 111 * should be freed by the caller. Always sets *len. Returns NULL on error. */ 112 char ** cs_list(int *len); 113 114 /* Checks existence of the specified color scheme. Returns non-zero if color 115 * scheme named name exists, otherwise zero is returned. */ 116 int cs_exists(const char name[]); 117 118 /* Performs completion of color names. */ 119 void cs_complete(const char name[]); 120 121 /* Converts set of attributes into a string. Returns pointer to a statically 122 * allocated buffer. */ 123 const char * cs_attrs_to_str(int attrs); 124 125 /* Associates color scheme specified by its name with the given path. */ 126 void cs_assoc_dir(const char name[], const char dir[]); 127 128 /* Does nothing if color schemes directory exists, otherwise creates one 129 * containing "Default" color scheme. */ 130 void cs_write(void); 131 132 /* Converts color specified by an integer to a string and writes result in a 133 * buffer of length buf_len pointed to by str_buf. */ 134 void cs_color_to_str(int color, size_t buf_len, char str_buf[]); 135 136 /* Mixes colors of *mixup into the base color. Non-transparent properties of 137 * *mixup are transferred onto *base. */ 138 void cs_mix_colors(col_attr_t *base, const col_attr_t *mixup); 139 140 /* Registers pattern-highlight pair for active color scheme. Reports memory 141 * error to the user. */ 142 void cs_add_file_hi(struct matchers_t *matchers, const col_attr_t *hi); 143 144 /* Gets filename-specific highlight. hi_hint can't be NULL and should be equal 145 * to -1 initially. Returns NULL if nothing is found, otherwise returns pointer 146 * to one of color scheme's highlights. */ 147 const col_attr_t * cs_get_file_hi(const col_scheme_t *cs, const char fname[], 148 int *hi_hint); 149 150 /* Removes filename-specific highlight by its pattern. Returns non-zero on 151 * successful removal and zero if pattern wasn't found. */ 152 int cs_del_file_hi(const char matchers_expr[]); 153 154 /* Checks that color is non-empty (i.e. has at least one property set). Returns 155 * non-zero if so, otherwise zero is returned. */ 156 int cs_is_color_set(const col_attr_t *color); 157 158 #endif /* VIFM__UI__COLOR_SCHEME_H__ */ 159 160 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ 161 /* vim: set cinoptions+=t0 filetype=c : */ 162