Add compact relative date display mode
[tig.git] / include / tig / types.h
blobe8da897ed3f68d7c0b16aa7c0e0a39efbf0c2555
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_TYPES_H
15 #define TIG_TYPES_H
17 #include "tig/tig.h"
20 * Enumerations
23 struct enum_map_entry {
24 const char *name;
25 int namelen;
26 int value;
29 struct enum_map {
30 const struct enum_map_entry *entries;
31 const int size;
34 #define string_enum_sep(x) ((x) == '-' || (x) == '_')
35 int string_enum_compare(const char *str1, const char *str2, int len);
37 #define enum_equals(entry, str, len) \
38 ((entry).namelen == (len) && !string_enum_compare((entry).name, str, len))
40 #define enum_equals_static(str, name, namelen) \
41 (namelen == STRING_SIZE(str) && !string_enum_compare(str, name, namelen))
43 #define enum_equals_prefix(entry, name_, namelen_) \
44 ((namelen_) > (entry).namelen && \
45 string_enum_sep((name_)[(entry).namelen]) && \
46 enum_equals(entry, name_, (entry).namelen))
48 const char *enum_name(const char *name);
49 bool enum_name_copy(char buf[], size_t bufsize, const char *name);
50 bool enum_name_prefixed(char buf[], size_t bufsize, const char *prefix, const char *name);
52 const struct enum_map *find_enum_map(const char *type);
54 bool map_enum_do(const struct enum_map_entry *map, size_t map_size, int *value, const char *name);
56 #define map_enum(attr, map, name) \
57 map_enum_do(map, ARRAY_SIZE(map), attr, name)
59 #define ENUM_MAP_ENTRY(name, value) { name, STRING_SIZE(name), value }
61 #define ENUM_SYM_MACRO(prefix, name) prefix##_##name
62 #define ENUM_MAP_MACRO(prefix, name) ENUM_MAP_ENTRY(#name, ENUM_SYM_MACRO(prefix, name))
64 #define DEFINE_ENUM(name, info) \
65 enum name { info(ENUM_SYM_MACRO) }; \
66 extern const struct enum_map name##_map[];
68 #define DEFINE_ENUM_MAP(name, info) \
69 const struct enum_map_entry name##_map_entries[] = { info(ENUM_MAP_MACRO) }; \
70 const struct enum_map name##_map[] = { { name##_map_entries, ARRAY_SIZE(name##_map_entries) } }
72 #define VERTICAL_SPLIT_ENUM(_) \
73 _(VERTICAL_SPLIT, HORIZONTAL), \
74 _(VERTICAL_SPLIT, VERTICAL), \
75 _(VERTICAL_SPLIT, AUTO)
77 #define GRAPHIC_ENUM(_) \
78 _(GRAPHIC, ASCII), \
79 _(GRAPHIC, DEFAULT), \
80 _(GRAPHIC, UTF_8)
82 #define GRAPH_DISPLAY_ENUM(_) \
83 _(GRAPH_DISPLAY, NO), \
84 _(GRAPH_DISPLAY, V2), \
85 _(GRAPH_DISPLAY, V1)
87 #define DATE_ENUM(_) \
88 _(DATE, NO), \
89 _(DATE, DEFAULT), \
90 _(DATE, LOCAL), \
91 _(DATE, RELATIVE), \
92 _(DATE, RELATIVE_COMPACT), \
93 _(DATE, SHORT)
95 #define FILE_SIZE_ENUM(_) \
96 _(FILE_SIZE, NO), \
97 _(FILE_SIZE, DEFAULT), \
98 _(FILE_SIZE, UNITS)
100 #define AUTHOR_ENUM(_) \
101 _(AUTHOR, NO), \
102 _(AUTHOR, FULL), \
103 _(AUTHOR, ABBREVIATED), \
104 _(AUTHOR, EMAIL), \
105 _(AUTHOR, EMAIL_USER)
107 #define FILENAME_ENUM(_) \
108 _(FILENAME, NO), \
109 _(FILENAME, AUTO), \
110 _(FILENAME, ALWAYS)
112 #define IGNORE_SPACE_ENUM(_) \
113 _(IGNORE_SPACE, NO), \
114 _(IGNORE_SPACE, ALL), \
115 _(IGNORE_SPACE, SOME), \
116 _(IGNORE_SPACE, AT_EOL)
118 #define COMMIT_ORDER_ENUM(_) \
119 _(COMMIT_ORDER, AUTO), \
120 _(COMMIT_ORDER, DEFAULT), \
121 _(COMMIT_ORDER, TOPO), \
122 _(COMMIT_ORDER, DATE), \
123 _(COMMIT_ORDER, AUTHOR_DATE), \
124 _(COMMIT_ORDER, REVERSE)
126 #define VIEW_COLUMN_ENUM(_) \
127 _(VIEW_COLUMN, AUTHOR), \
128 _(VIEW_COLUMN, COMMIT_TITLE), \
129 _(VIEW_COLUMN, DATE), \
130 _(VIEW_COLUMN, FILE_NAME), \
131 _(VIEW_COLUMN, FILE_SIZE), \
132 _(VIEW_COLUMN, ID), \
133 _(VIEW_COLUMN, LINE_NUMBER), \
134 _(VIEW_COLUMN, MODE), \
135 _(VIEW_COLUMN, REF), \
136 _(VIEW_COLUMN, SECTION), \
137 _(VIEW_COLUMN, STATUS), \
138 _(VIEW_COLUMN, TEXT)
140 #define REFERENCE_ENUM(_) \
141 _(REFERENCE, HEAD), \
142 _(REFERENCE, BRANCH), \
143 _(REFERENCE, TRACKED_REMOTE), \
144 _(REFERENCE, REMOTE), \
145 _(REFERENCE, TAG), \
146 _(REFERENCE, LOCAL_TAG), \
147 _(REFERENCE, REPLACE), \
149 #define STATUS_LABEL_ENUM(_) \
150 _(STATUS_LABEL, NO), \
151 _(STATUS_LABEL, SHORT), \
152 _(STATUS_LABEL, LONG), \
154 #define REFRESH_MODE_ENUM(_) \
155 _(REFRESH_MODE, MANUAL), \
156 _(REFRESH_MODE, AUTO), \
157 _(REFRESH_MODE, AFTER_COMMAND), \
158 _(REFRESH_MODE, PERIODIC), \
160 #define ENUM_INFO(_) \
161 _(author, AUTHOR_ENUM) \
162 _(commit_order, COMMIT_ORDER_ENUM) \
163 _(date, DATE_ENUM) \
164 _(file_size, FILE_SIZE_ENUM) \
165 _(filename, FILENAME_ENUM) \
166 _(graphic, GRAPHIC_ENUM) \
167 _(graph_display, GRAPH_DISPLAY_ENUM) \
168 _(ignore_space, IGNORE_SPACE_ENUM) \
169 _(vertical_split, VERTICAL_SPLIT_ENUM) \
170 _(view_column_type, VIEW_COLUMN_ENUM) \
171 _(reference_type, REFERENCE_ENUM) \
172 _(refresh_mode, REFRESH_MODE_ENUM) \
173 _(status_label, STATUS_LABEL_ENUM) \
175 #define DEFINE_ENUMS(name, macro) DEFINE_ENUM(name, macro)
176 ENUM_INFO(DEFINE_ENUMS)
178 #endif
179 /* vim: set ts=8 sw=8 noexpandtab: */