Blame
Date:
Sun Apr 24 12:24:18 2022 UTC
Message:
replace has_prefix with strncmp
001
2021-06-15
op
/*
002
2021-06-15
op
* Copyright (c) 2021 Omar Polo <op@omarpolo.com>
003
2021-06-15
op
*
004
2021-06-15
op
* Permission to use, copy, modify, and distribute this software for any
005
2021-06-15
op
* purpose with or without fee is hereby granted, provided that the above
006
2021-06-15
op
* copyright notice and this permission notice appear in all copies.
007
2021-06-15
op
*
008
2021-06-15
op
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
009
2021-06-15
op
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
010
2021-06-15
op
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
011
2021-06-15
op
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
012
2021-06-15
op
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
013
2021-06-15
op
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
014
2021-06-15
op
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
015
2021-06-15
op
*/
016
2021-07-21
op
017
2021-07-21
op
#include "compat.h"
018
2021-06-15
op
019
2021-06-15
op
#include <curses.h>
020
2021-06-19
op
#include <limits.h>
021
2021-06-19
op
#include <stdlib.h>
022
2021-06-15
op
#include <string.h>
023
2021-06-27
op
#include <unistd.h>
024
2021-06-15
op
025
2021-07-13
op
#include "defaults.h"
026
2021-07-12
op
#include "telescope.h"
027
2021-07-12
op
#include "ui.h"
028
2022-01-11
op
#include "utils.h"
029
2021-07-12
op
030
2021-08-29
op
char *download_path = NULL;
031
2021-08-29
op
char *new_tab_url = NULL;
032
2021-08-14
op
033
2021-08-14
op
int autosave = 20;
034
2021-08-14
op
int dont_wrap_pre = 0;
035
2021-08-14
op
int emojify_link = 1;
036
2021-06-21
op
int enable_colors = 1;
037
2021-01-02
op
int fill_column = 120;
038
2022-01-10
op
int fringe_ignore_offset = 1;
039
2021-07-05
op
int hide_pre_blocks = 0;
040
2021-07-15
op
int hide_pre_closing_line = 0;
041
2021-08-14
op
int hide_pre_context = 0;
042
2022-01-05
op
int max_killed_tabs = 10;
043
2021-08-14
op
int olivetti_mode = 1;
044
2021-07-17
op
int set_title = 1;
045
2021-08-18
op
int tab_bar_show = 1;
046
2022-01-10
op
047
2022-01-10
op
static struct line fringe_line = {
048
2022-01-10
op
.type = LINE_FRINGE,
049
2022-01-10
op
};
050
2022-01-10
op
struct vline fringe = {
051
2022-01-10
op
.parent = &fringe_line,
052
2022-01-10
op
};
053
2021-06-19
op
054
2021-06-15
op
struct lineprefix line_prefixes[] = {
055
2021-06-15
op
[LINE_TEXT] = { "", "" },
056
2021-07-19
op
[LINE_LINK] = { "→ ", " " },
057
2021-06-15
op
[LINE_TITLE_1] = { "# ", " " },
058
2021-06-15
op
[LINE_TITLE_2] = { "## ", " " },
059
2021-06-15
op
[LINE_TITLE_3] = { "### ", " " },
060
2021-07-19
op
[LINE_ITEM] = { " • ", " " },
061
2021-07-19
op
[LINE_QUOTE] = { " ┃ ", " ┃ " },
062
2021-07-19
op
[LINE_PRE_START] = { "─── ", " " },
063
2021-06-15
op
[LINE_PRE_CONTENT] = { "", "" },
064
2021-07-19
op
[LINE_PRE_END] = { "─── ", "" },
065
2021-07-14
op
066
2021-07-30
op
[LINE_PATCH] = {"", ""},
067
2021-07-30
op
[LINE_PATCH_HDR] = {"", ""},
068
2021-07-30
op
[LINE_PATCH_HUNK_HDR] = {"", ""},
069
2021-07-30
op
[LINE_PATCH_ADD] = {"", ""},
070
2021-07-30
op
[LINE_PATCH_DEL] = {"", ""},
071
2021-07-30
op
072
2021-07-14
op
[LINE_COMPL] = {"", ""},
073
2021-07-14
op
[LINE_COMPL_CURRENT] = {"", ""},
074
2021-07-21
op
075
2021-07-21
op
[LINE_HELP] = {"", ""},
076
2021-11-05
op
077
2021-11-05
op
[LINE_DOWNLOAD] = {" Fetching ", " "},
078
2021-11-05
op
[LINE_DOWNLOAD_DONE] = {" Done ", " "},
079
2021-11-05
op
[LINE_DOWNLOAD_INFO] = {" ", " "},
080
2022-01-10
op
081
2022-01-10
op
[LINE_FRINGE] = {"~", ""},
082
2021-06-15
op
};
083
2021-06-15
op
084
2021-06-15
op
struct line_face line_faces[] = {
085
2021-06-24
op
[LINE_TEXT] = {
086
2021-06-24
op
.prfx_pair = PT_PRFX,
087
2021-06-24
op
.pair = PT,
088
2021-06-24
op
.trail_pair = PT_TRAIL,
089
2021-06-24
op
},
090
2021-06-24
op
[LINE_LINK] = {
091
2021-06-24
op
.prfx_pair = PL_PRFX,
092
2021-06-24
op
.pair = PL,
093
2021-06-24
op
.trail_pair = PL_TRAIL,
094
2021-07-19
op
.attr = A_UNDERLINE,
095
2021-06-24
op
},
096
2021-06-24
op
[LINE_TITLE_1] = {
097
2021-06-24
op
.prfx_pair = PT1_PRFX,
098
2021-06-24
op
.pair = PT1,
099
2021-06-24
op
.trail_pair = PT1_TRAIL,
100
2021-06-24
op
.attr = A_BOLD,
101
2021-06-24
op
},
102
2021-06-24
op
[LINE_TITLE_2] = {
103
2021-06-24
op
.prfx_pair = PT2_PRFX,
104
2021-06-24
op
.pair = PT2,
105
2021-06-24
op
.trail_pair = PT2_TRAIL,
106
2021-06-24
op
.attr = A_BOLD,
107
2021-06-24
op
},
108
2021-06-24
op
[LINE_TITLE_3] = {
109
2021-06-24
op
.prfx_pair = PT3_PRFX,
110
2021-06-24
op
.pair = PT3,
111
2021-06-24
op
.trail_pair = PT3_TRAIL,
112
2021-06-24
op
.attr = A_BOLD,
113
2021-06-24
op
},
114
2021-06-24
op
[LINE_ITEM] = {
115
2021-06-24
op
.prfx_pair = PI_PRFX,
116
2021-06-24
op
.pair = PI,
117
2021-06-24
op
.trail_pair = PI_TRAIL,
118
2021-06-24
op
},
119
2021-06-24
op
[LINE_QUOTE] = {
120
2021-06-24
op
.prfx_pair = PQ_PRFX,
121
2021-06-24
op
.pair = PQ,
122
2021-06-24
op
.trail_pair = PQ_TRAIL,
123
2021-06-24
op
.attr = A_DIM,
124
2021-06-24
op
},
125
2021-06-24
op
[LINE_PRE_START] = {
126
2021-06-24
op
.prfx_pair = PPSTART_PRFX,
127
2021-06-24
op
.pair = PPSTART,
128
2021-06-24
op
.trail_pair = PPSTART_TRAIL,
129
2021-06-24
op
},
130
2021-06-24
op
[LINE_PRE_CONTENT] = {
131
2021-06-24
op
.prfx_pair = PP_PRFX,
132
2021-06-24
op
.pair = PP,
133
2021-06-24
op
.trail_pair = PP_TRAIL,
134
2021-06-24
op
},
135
2021-06-24
op
[LINE_PRE_END] = {
136
2021-06-24
op
.prfx_pair = PPEND_PRFX,
137
2021-06-24
op
.pair = PPEND,
138
2021-06-24
op
.trail_pair = PPEND_TRAIL,
139
2021-07-30
op
},
140
2021-07-30
op
141
2021-07-30
op
/* text/x-patch */
142
2021-07-30
op
[LINE_PATCH] = {
143
2021-07-30
op
.prfx_pair = PPATCH_PRFX,
144
2021-07-30
op
.pair = PPATCH,
145
2021-07-30
op
.trail_pair = PPATCH_TRAIL,
146
2021-07-30
op
},
147
2021-07-30
op
[LINE_PATCH_HDR] = {
148
2021-07-30
op
.prfx_pair = PPATCH_HDR_PRFX,
149
2021-07-30
op
.pair = PPATCH_HDR,
150
2021-07-30
op
.trail_pair = PPATCH_HDR_TRAIL,
151
2021-07-30
op
},
152
2021-07-30
op
[LINE_PATCH_HUNK_HDR] = {
153
2021-07-30
op
.prfx_pair = PPATCH_HUNK_HDR_PRFX,
154
2021-07-30
op
.pair = PPATCH_HUNK_HDR,
155
2021-07-30
op
.trail_pair = PPATCH_HUNK_HDR_TRAIL,
156
2021-07-30
op
},
157
2021-07-30
op
[LINE_PATCH_ADD] = {
158
2021-07-30
op
.prfx_pair = PPATCH_ADD_PRFX,
159
2021-07-30
op
.pair = PPATCH_ADD,
160
2021-07-30
op
.trail_pair = PPATCH_ADD_TRAIL,
161
2021-07-30
op
},
162
2021-07-30
op
[LINE_PATCH_DEL] = {
163
2021-07-30
op
.prfx_pair = PPATCH_DEL_PRFX,
164
2021-07-30
op
.pair = PPATCH_DEL,
165
2021-07-30
op
.trail_pair = PPATCH_DEL_TRAIL,
166
2021-06-24
op
},
167
2021-07-14
op
168
2021-07-14
op
/* minibuffer */
169
2021-07-14
op
[LINE_COMPL] = {
170
2021-07-14
op
.prfx_pair = PCOMPL_PRFX,
171
2021-07-14
op
.pair = PCOMPL,
172
2021-07-14
op
.trail_pair = PCOMPL_TRAIL,
173
2021-07-14
op
},
174
2021-07-14
op
[LINE_COMPL_CURRENT] = {
175
2021-07-14
op
.prfx_pair = PCOMPL_CURR_PRFX,
176
2021-07-14
op
.pair = PCOMPL_CURR,
177
2021-07-14
op
.trail_pair = PCOMPL_CURR_TRAIL,
178
2021-07-15
op
.attr = A_REVERSE,
179
2021-07-15
op
.trail_attr = A_REVERSE,
180
2021-07-21
op
},
181
2021-07-21
op
182
2021-07-21
op
/* help */
183
2021-07-21
op
[LINE_HELP] = {
184
2021-07-21
op
.prfx_pair = PHELP_PRFX,
185
2021-07-21
op
.pair = PHELP,
186
2021-07-21
op
.trail_pair = PHELP_TRAIL,
187
2021-07-14
op
},
188
2021-11-05
op
189
2021-11-05
op
/* download */
190
2021-11-05
op
[LINE_DOWNLOAD] = {
191
2021-11-05
op
.prfx_pair = PDOWNLOAD_PRFX,
192
2021-11-05
op
.pair = PDOWNLOAD,
193
2021-11-05
op
.trail_pair = PDOWNLOAD_TRAIL
194
2021-11-05
op
},
195
2021-11-05
op
[LINE_DOWNLOAD_DONE] = {
196
2021-11-05
op
.prfx_pair = PDOWNLOAD_DONE_PRFX,
197
2021-11-05
op
.pair = PDOWNLOAD_DONE,
198
2021-11-05
op
.trail_pair = PDOWNLOAD_DONE_TRAIL
199
2021-11-05
op
},
200
2021-11-05
op
[LINE_DOWNLOAD_INFO] = {
201
2021-11-05
op
.prfx_pair = PDOWNLOAD_INFO_PRFX,
202
2021-11-05
op
.pair = PDOWNLOAD_INFO,
203
2021-11-05
op
.trail_pair = PDOWNLOAD_INFO_TRAIL
204
2021-11-05
op
},
205
2022-01-10
op
206
2022-01-10
op
/* misc ui */
207
2022-01-10
op
[LINE_FRINGE] = {
208
2022-01-10
op
.prfx_pair = PFRINGE_PRFX,
209
2022-01-10
op
.pair = PFRINGE,
210
2022-01-10
op
.trail_pair = PFRINGE_TRAIL,
211
2022-01-10
op
}
212
2021-06-15
op
};
213
2021-06-15
op
214
2021-06-15
op
struct tab_face tab_face = {
215
2021-06-22
op
.bg_attr = A_REVERSE, .bg_bg = -1, .bg_fg = -1,
216
2021-06-22
op
.t_attr = A_REVERSE, .t_bg = -1, .t_fg = -1,
217
2021-06-22
op
.c_attr = A_NORMAL, .c_bg = -1, .c_fg = -1,
218
2021-06-22
op
219
2021-06-22
op
/*
220
2021-06-22
op
* set these so that even when enable-color=0 the bar has some
221
2021-06-22
op
* sane defaults.
222
2021-06-22
op
*/
223
2021-06-22
op
.background = A_REVERSE,
224
2021-06-22
op
.tab = A_REVERSE,
225
2021-06-22
op
.current = A_NORMAL,
226
2021-06-15
op
};
227
2021-06-15
op
228
2021-06-21
op
struct body_face body_face = {
229
2021-06-21
op
.lbg = -1, .lfg = -1,
230
2021-06-21
op
.bg = -1, .fg = -1,
231
2021-06-21
op
.rbg = -1, .rfg = -1,
232
2021-11-05
op
};
233
2021-11-05
op
234
2021-11-05
op
struct download_face download_face = {
235
2021-11-05
op
.bg = -1,
236
2021-11-05
op
.fg = -1,
237
2021-11-05
op
.attr = A_NORMAL,
238
2021-06-21
op
};
239
2021-06-21
op
240
2021-06-15
op
struct modeline_face modeline_face = {
241
2021-06-25
op
.bg = -1,
242
2021-06-25
op
.fg = -1,
243
2021-06-25
op
.attr = A_REVERSE,
244
2021-06-15
op
};
245
2021-06-15
op
246
2021-06-15
op
struct minibuffer_face minibuffer_face = {
247
2021-06-25
op
.bg = -1,
248
2021-06-25
op
.fg = -1,
249
2021-06-25
op
.attr = A_NORMAL,
250
2021-06-15
op
};
251
2021-06-15
op
252
2021-06-21
op
struct mapping {
253
2021-06-21
op
const char *label;
254
2021-06-21
op
int linetype;
255
2021-06-21
op
} mappings[] = {
256
2021-06-21
op
{"text", LINE_TEXT},
257
2021-06-21
op
{"link", LINE_LINK},
258
2021-06-21
op
{"title1", LINE_TITLE_1},
259
2021-06-21
op
{"title2", LINE_TITLE_2},
260
2021-06-21
op
{"title3", LINE_TITLE_3},
261
2021-06-21
op
{"item", LINE_ITEM},
262
2021-06-21
op
{"quote", LINE_QUOTE},
263
2021-06-21
op
{"pre.start", LINE_PRE_START},
264
2021-06-21
op
{"pre", LINE_PRE_CONTENT},
265
2021-06-21
op
{"pre.end", LINE_PRE_END},
266
2021-07-14
op
267
2021-07-30
op
/* text/x-patch */
268
2021-07-30
op
{"patch", LINE_PATCH},
269
2021-07-30
op
{"patch.hdr", LINE_PATCH_HDR},
270
2021-07-30
op
{"patch.hunk", LINE_PATCH_HUNK_HDR},
271
2021-07-30
op
{"patch.add", LINE_PATCH_ADD},
272
2021-07-30
op
{"patch.del", LINE_PATCH_DEL},
273
2021-07-30
op
274
2021-07-14
op
/* minibuffer */
275
2021-07-14
op
{"compl", LINE_COMPL},
276
2021-07-21
op
{"compl.current", LINE_COMPL_CURRENT},
277
2021-07-21
op
278
2021-07-21
op
/* help */
279
2021-07-21
op
{"help", LINE_HELP},
280
2021-11-05
op
281
2021-11-05
op
/* download */
282
2021-11-05
op
{"download.ongoing", LINE_DOWNLOAD},
283
2021-11-05
op
{"download.done", LINE_DOWNLOAD_DONE},
284
2021-11-05
op
{"download.info", LINE_DOWNLOAD_INFO},
285
2022-01-10
op
286
2022-01-10
op
/* misc ui */
287
2022-01-10
op
{"fringe", LINE_FRINGE},
288
2021-06-21
op
};
289
2021-06-21
op
290
2021-06-21
op
static struct mapping *
291
2021-06-21
op
mapping_by_name(const char *name)
292
2021-06-21
op
{
293
2021-06-21
op
size_t i;
294
2021-06-21
op
295
2021-06-21
op
for (i = 0; i < sizeof(mappings)/sizeof(mappings[0]); ++i) {
296
2021-06-21
op
if (!strcmp(name, mappings[i].label))
297
2021-06-21
op
return &mappings[i];
298
2021-06-21
op
}
299
2021-06-21
op
300
2021-06-21
op
return NULL;
301
2021-06-21
op
}
302
2021-06-21
op
303
2021-06-27
op
static inline void
304
2021-06-27
op
global_set_key(const char *key, void (*fn)(struct buffer*))
305
2021-06-27
op
{
306
2021-06-27
op
if (!kmap_define_key(&global_map, key, fn))
307
2021-06-27
op
_exit(1);
308
2021-06-27
op
}
309
2021-06-27
op
310
2021-06-27
op
static inline void
311
2021-06-27
op
minibuffer_set_key(const char *key, void (*fn)(struct buffer*))
312
2021-06-27
op
{
313
2021-06-27
op
if (!kmap_define_key(&minibuffer_map, key, fn))
314
2021-06-27
op
_exit(1);
315
2021-06-27
op
}
316
2021-06-27
op
317
2021-06-27
op
static void
318
2021-06-27
op
load_default_keys(void)
319
2021-06-27
op
{
320
2021-06-27
op
/* === global map === */
321
2021-06-27
op
322
2021-06-27
op
/* emacs */
323
2021-06-27
op
global_set_key("C-p", cmd_previous_line);
324
2021-06-27
op
global_set_key("C-n", cmd_next_line);
325
2021-06-27
op
global_set_key("C-f", cmd_forward_char);
326
2021-06-27
op
global_set_key("C-b", cmd_backward_char);
327
2021-06-27
op
global_set_key("M-{", cmd_backward_paragraph);
328
2021-06-27
op
global_set_key("M-}", cmd_forward_paragraph);
329
2021-06-27
op
global_set_key("C-a", cmd_move_beginning_of_line);
330
2021-06-27
op
global_set_key("C-e", cmd_move_end_of_line);
331
2021-06-27
op
332
2021-06-27
op
global_set_key("M-v", cmd_scroll_up);
333
2021-06-27
op
global_set_key("C-v", cmd_scroll_down);
334
2021-06-27
op
global_set_key("M-space", cmd_scroll_up);
335
2021-06-27
op
global_set_key("space", cmd_scroll_down);
336
2021-06-27
op
337
2021-06-27
op
global_set_key("M-<", cmd_beginning_of_buffer);
338
2021-06-27
op
global_set_key("M->", cmd_end_of_buffer);
339
2021-06-27
op
340
2021-06-27
op
global_set_key("C-x C-c", cmd_kill_telescope);
341
2022-04-13
op
global_set_key("C-x C-w", cmd_write_buffer);
342
2021-06-27
op
343
2021-06-27
op
global_set_key("C-g", cmd_clear_minibuf);
344
2021-06-27
op
345
2021-06-27
op
global_set_key("M-x", cmd_execute_extended_command);
346
2021-06-27
op
347
2021-06-27
op
global_set_key("C-c {", cmd_dec_fill_column);
348
2021-06-27
op
global_set_key("C-c }", cmd_inc_fill_column);
349
2021-06-27
op
350
2021-06-27
op
global_set_key("C-c p", cmd_previous_heading);
351
2021-06-27
op
global_set_key("C-c n", cmd_next_heading);
352
2021-06-27
op
353
2021-06-27
op
global_set_key(">", cmd_load_url);
354
2021-07-14
op
global_set_key("<", cmd_load_current_url);
355
2021-06-27
op
global_set_key("C-x C-f", cmd_load_url);
356
2021-06-27
op
global_set_key("C-x M-f", cmd_load_current_url);
357
2021-07-21
op
358
2021-07-21
op
global_set_key("C-x o", cmd_other_window);
359
2021-06-27
op
360
2021-06-27
op
global_set_key("C-x t 0", cmd_tab_close);
361
2021-06-27
op
global_set_key("C-x t 1", cmd_tab_close_other);
362
2021-06-27
op
global_set_key("C-x t 2", cmd_tab_new);
363
2021-06-27
op
global_set_key("C-x t o", cmd_tab_next);
364
2021-06-27
op
global_set_key("C-x t O", cmd_tab_previous);
365
2021-06-27
op
global_set_key("C-x t m", cmd_tab_move);
366
2021-06-27
op
global_set_key("C-x t M", cmd_tab_move_to);
367
2021-06-27
op
368
2021-07-13
op
global_set_key("B", cmd_previous_page);
369
2021-06-27
op
global_set_key("C-M-b", cmd_previous_page);
370
2021-07-13
op
global_set_key("F", cmd_next_page);
371
2021-06-27
op
global_set_key("C-M-f", cmd_next_page);
372
2021-06-27
op
373
2021-06-27
op
global_set_key("<f7> a", cmd_bookmark_page);
374
2021-06-27
op
global_set_key("<f7> <f7>", cmd_list_bookmarks);
375
2021-07-15
op
376
2021-07-15
op
global_set_key("C-z", cmd_suspend_telescope);
377
2021-06-27
op
378
2021-06-27
op
/* vi/vi-like */
379
2021-06-27
op
global_set_key("k", cmd_previous_line);
380
2021-06-27
op
global_set_key("j", cmd_next_line);
381
2021-06-27
op
global_set_key("l", cmd_forward_char);
382
2021-06-27
op
global_set_key("h", cmd_backward_char);
383
2021-06-27
op
global_set_key("{", cmd_backward_paragraph);
384
2021-06-27
op
global_set_key("}", cmd_forward_paragraph);
385
2021-06-27
op
global_set_key("^", cmd_move_beginning_of_line);
386
2021-06-27
op
global_set_key("$", cmd_move_end_of_line);
387
2021-06-27
op
388
2021-06-27
op
global_set_key("K", cmd_scroll_line_up);
389
2021-06-27
op
global_set_key("J", cmd_scroll_line_down);
390
2021-06-27
op
391
2021-06-27
op
global_set_key("g g", cmd_beginning_of_buffer);
392
2021-06-27
op
global_set_key("G", cmd_end_of_buffer);
393
2021-06-27
op
394
2021-06-27
op
global_set_key("g D", cmd_tab_close);
395
2021-06-27
op
global_set_key("g N", cmd_tab_new);
396
2021-06-27
op
global_set_key("g t", cmd_tab_next);
397
2021-06-27
op
global_set_key("g T", cmd_tab_previous);
398
2021-06-27
op
global_set_key("g M-t", cmd_tab_move);
399
2021-06-27
op
global_set_key("g M-T", cmd_tab_move_to);
400
2021-06-27
op
401
2021-06-27
op
global_set_key("H", cmd_previous_page);
402
2021-06-27
op
global_set_key("L", cmd_next_page);
403
2022-01-05
op
404
2022-01-05
op
global_set_key("u", cmd_tab_undo_close);
405
2021-06-27
op
406
2021-06-27
op
/* tmp */
407
2021-06-27
op
global_set_key("q", cmd_kill_telescope);
408
2021-06-27
op
409
2021-06-27
op
global_set_key("esc", cmd_clear_minibuf);
410
2021-06-27
op
411
2021-06-27
op
global_set_key(":", cmd_execute_extended_command);
412
2021-06-27
op
413
2021-06-27
op
/* cua */
414
2021-06-27
op
global_set_key("<up>", cmd_previous_line);
415
2021-06-27
op
global_set_key("<down>", cmd_next_line);
416
2021-06-27
op
global_set_key("<right>", cmd_forward_char);
417
2021-06-27
op
global_set_key("<left>", cmd_backward_char);
418
2021-07-15
op
global_set_key("<home>", cmd_move_beginning_of_line);
419
2021-07-15
op
global_set_key("<end>", cmd_move_end_of_line);
420
2021-06-27
op
global_set_key("<prior>", cmd_scroll_up);
421
2021-06-27
op
global_set_key("<next>", cmd_scroll_down);
422
2021-06-27
op
423
2021-07-08
op
global_set_key("C-w", cmd_tab_close);
424
2021-07-08
op
global_set_key("C-t", cmd_tab_new);
425
2021-07-06
op
global_set_key("M-<prior>", cmd_tab_previous);
426
2021-07-06
op
global_set_key("M-<next>", cmd_tab_next);
427
2021-07-06
op
428
2021-01-02
op
global_set_key("del", cmd_previous_page);
429
2021-06-27
op
global_set_key("M-<left>", cmd_previous_page);
430
2021-06-27
op
global_set_key("M-<right>", cmd_next_page);
431
2021-06-27
op
432
2021-07-14
op
global_set_key("<f5>", cmd_reload_page);
433
2021-07-14
op
global_set_key("r", cmd_reload_page);
434
2021-07-14
op
435
2021-06-27
op
/* "ncurses standard" */
436
2021-06-27
op
global_set_key("C-l", cmd_redraw);
437
2021-06-27
op
438
2021-06-27
op
/* global */
439
2021-06-27
op
global_set_key("<f1>", cmd_toggle_help);
440
2021-11-05
op
global_set_key("<f2>", cmd_toggle_downloads);
441
2021-06-27
op
global_set_key("C-m", cmd_push_button);
442
2021-06-27
op
global_set_key("M-enter", cmd_push_button_new_tab);
443
2021-06-27
op
global_set_key("M-tab", cmd_previous_button);
444
2021-06-27
op
global_set_key("backtab", cmd_previous_button);
445
2021-06-27
op
global_set_key("tab", cmd_next_button);
446
2021-07-14
op
global_set_key("M-t", cmd_tab_select);
447
2021-07-16
op
global_set_key("[", cmd_tab_previous);
448
2021-07-16
op
global_set_key("]", cmd_tab_next);
449
2021-08-18
op
global_set_key("M-[", cmd_tab_move_to);
450
2021-08-18
op
global_set_key("M-]", cmd_tab_move);
451
2021-07-15
op
global_set_key("M-l", cmd_link_select);
452
2021-07-14
op
global_set_key("M-/", cmd_swiper);
453
2021-07-15
op
global_set_key("t", cmd_toc);
454
2022-02-07
op
global_set_key("M-r", cmd_reply_last_input);
455
2021-06-27
op
456
2021-06-27
op
/* === minibuffer map === */
457
2022-04-15
op
minibuffer_set_key("ret", cmd_mini_complete_and_exit);
458
2022-04-15
op
minibuffer_set_key("C-g", cmd_mini_abort);
459
2022-04-15
op
minibuffer_set_key("esc", cmd_mini_abort);
460
2022-04-15
op
minibuffer_set_key("C-d", cmd_mini_delete_char);
461
2022-04-15
op
minibuffer_set_key("del", cmd_mini_delete_backward_char);
462
2022-04-15
op
minibuffer_set_key("backspace", cmd_mini_delete_backward_char);
463
2022-04-15
op
minibuffer_set_key("C-h", cmd_mini_delete_backward_char);
464
2021-06-27
op
465
2022-04-15
op
minibuffer_set_key("C-b", cmd_backward_char);
466
2022-04-15
op
minibuffer_set_key("C-f", cmd_forward_char);
467
2022-04-15
op
minibuffer_set_key("<left>", cmd_backward_char);
468
2022-04-15
op
minibuffer_set_key("<right>", cmd_forward_char);
469
2022-04-15
op
minibuffer_set_key("C-e", cmd_move_end_of_line);
470
2022-04-15
op
minibuffer_set_key("C-a", cmd_move_beginning_of_line);
471
2022-04-15
op
minibuffer_set_key("<end>", cmd_move_end_of_line);
472
2022-04-15
op
minibuffer_set_key("<home>", cmd_move_beginning_of_line);
473
2022-04-15
op
minibuffer_set_key("C-k", cmd_mini_kill_line);
474
2022-04-15
op
minibuffer_set_key("C-u", cmd_mini_kill_whole_line);
475
2021-07-14
op
476
2022-04-15
op
minibuffer_set_key("M-p", cmd_mini_previous_history_element);
477
2022-04-15
op
minibuffer_set_key("M-n", cmd_mini_next_history_element);
478
2021-07-24
op
479
2022-04-15
op
minibuffer_set_key("C-p", cmd_previous_completion);
480
2022-04-15
op
minibuffer_set_key("C-n", cmd_next_completion);
481
2022-04-15
op
minibuffer_set_key("<up>", cmd_previous_completion);
482
2022-04-15
op
minibuffer_set_key("<down>", cmd_next_completion);
483
2021-07-17
op
484
2022-04-15
op
minibuffer_set_key("C-v", cmd_mini_scroll_down);
485
2022-04-15
op
minibuffer_set_key("M-v", cmd_mini_scroll_up);
486
2022-04-15
op
minibuffer_set_key("<next>", cmd_mini_scroll_down);
487
2022-04-15
op
minibuffer_set_key("<prior>", cmd_mini_scroll_up);
488
2022-04-15
op
489
2022-04-15
op
minibuffer_set_key("M-<", cmd_mini_goto_beginning);
490
2022-04-15
op
minibuffer_set_key("M->", cmd_mini_goto_end);
491
2022-04-15
op
492
2022-04-15
op
minibuffer_set_key("tab", cmd_insert_current_candidate);
493
2021-06-27
op
}
494
2021-06-27
op
495
2021-06-21
op
void
496
2021-06-21
op
config_init(void)
497
2021-06-21
op
{
498
2021-06-24
op
struct line_face *f;
499
2021-06-21
op
size_t i, len;
500
2021-06-21
op
501
2021-06-24
op
len = sizeof(line_faces)/sizeof(line_faces[0]);
502
2021-06-21
op
for (i = 0; i < len; ++i) {
503
2021-06-24
op
f = &line_faces[i];
504
2021-06-21
op
505
2021-06-24
op
f->prfx_bg = f->bg = f->trail_bg = -1;
506
2021-06-24
op
f->prfx_fg = f->fg = f->trail_fg = -1;
507
2021-06-21
op
}
508
2021-06-25
op
509
2021-06-25
op
line_faces[LINE_LINK].fg = COLOR_BLUE;
510
2021-07-30
op
line_faces[LINE_PATCH_ADD].fg = COLOR_GREEN;
511
2021-07-30
op
line_faces[LINE_PATCH_DEL].fg = COLOR_RED;
512
2021-07-14
op
513
2021-06-27
op
load_default_keys();
514
2021-06-21
op
}
515
2021-06-21
op
516
2021-06-15
op
int
517
2021-06-21
op
config_setprfx(const char *name, const char *prfx, const char *cont)
518
2021-06-15
op
{
519
2021-06-15
op
struct lineprefix *p;
520
2021-06-21
op
struct mapping *m;
521
2021-06-15
op
522
2022-04-24
op
if (strncmp(name, "line.", 5) != 0)
523
2021-06-15
op
return 0;
524
2021-06-15
op
name += 5;
525
2021-06-15
op
526
2021-06-21
op
if ((m = mapping_by_name(name)) == NULL)
527
2021-06-21
op
return 0;
528
2021-06-15
op
529
2021-06-21
op
p = &line_prefixes[m->linetype];
530
2021-06-21
op
p->prfx1 = prfx;
531
2021-06-21
op
p->prfx2 = cont;
532
2021-06-15
op
533
2021-06-21
op
return 1;
534
2021-06-15
op
}
535
2021-06-19
op
536
2021-06-19
op
int
537
2021-06-19
op
config_setvari(const char *var, int val)
538
2021-06-19
op
{
539
2021-06-19
op
if (!strcmp(var, "fill-column")) {
540
2021-06-19
op
if ((fill_column = val) <= 0)
541
2021-06-19
op
fill_column = INT_MAX;
542
2021-06-19
op
} else if (!strcmp(var, "olivetti-mode")) {
543
2021-06-19
op
olivetti_mode = !!val;
544
2021-06-21
op
} else if (!strcmp(var, "enable-colors")) {
545
2021-06-21
op
enable_colors = !!val;
546
2021-07-05
op
} else if (!strcmp(var, "hide-pre-context")) {
547
2021-07-05
op
hide_pre_context = !!val;
548
2021-07-05
op
} else if (!strcmp(var, "hide-pre-blocks")) {
549
2021-07-05
op
hide_pre_blocks = !!val;
550
2021-07-15
op
} else if (!strcmp(var, "hide-pre-closing-line")) {
551
2021-07-15
op
hide_pre_closing_line = !!val;
552
2021-07-15
op
} else if (!strcmp(var, "dont-wrap-pre")) {
553
2021-07-15
op
dont_wrap_pre = !!val;
554
2021-07-16
op
} else if (!strcmp(var, "emojify-link")) {
555
2021-07-16
op
emojify_link = !!val;
556
2022-01-04
op
} else if (!strcmp(var, "update-title") || !strcmp(var, "set-title")) {
557
2021-07-17
op
set_title = !!val;
558
2021-08-14
op
} else if (!strcmp(var, "autosave")) {
559
2021-08-14
op
autosave = val;
560
2021-08-18
op
} else if (!strcmp(var, "tab-bar-show")) {
561
2021-08-18
op
if (val < 0)
562
2021-08-18
op
tab_bar_show = -1;
563
2021-08-18
op
else if (val == 0)
564
2021-08-18
op
tab_bar_show = 0;
565
2021-08-18
op
else
566
2021-08-18
op
tab_bar_show = 1;
567
2022-01-05
op
} else if (!strcmp(var, "max-killed-tabs")) {
568
2022-01-05
op
if (val >= 0)
569
2022-01-05
op
max_killed_tabs = MIN(val, 128);
570
2022-01-10
op
} else if (!strcmp(var, "fringe-ignore-offset")) {
571
2022-01-10
op
fringe_ignore_offset = !!val;
572
2021-07-15
op
} else {
573
2021-06-19
op
return 0;
574
2021-06-21
op
}
575
2021-06-21
op
576
2021-06-19
op
return 1;
577
2021-06-19
op
}
578
2021-06-19
op
579
2021-06-19
op
int
580
2021-06-19
op
config_setvars(const char *var, char *val)
581
2021-06-19
op
{
582
2021-08-29
op
if (!strcmp(var, "download-path")) {
583
2021-08-29
op
const char *prfx = "", *v = val, *sufx = "";
584
2021-08-29
op
585
2022-04-24
op
if (!strncmp(val, "~/", 2) &&
586
2021-08-29
op
v++ &&
587
2021-08-29
op
(prfx = getenv("HOME")) == NULL)
588
2021-08-29
op
return 0;
589
2021-08-29
op
590
2021-08-29
op
if (!has_suffix(val, "/"))
591
2021-08-29
op
sufx = "/";
592
2021-08-29
op
593
2021-08-29
op
free(download_path);
594
2021-08-29
op
if (asprintf(&download_path, "%s%s%s", prfx, v, sufx) == -1) {
595
2021-08-29
op
download_path = NULL;
596
2021-08-29
op
return 0;
597
2021-08-29
op
}
598
2021-08-29
op
599
2021-08-29
op
free(val);
600
2021-08-29
op
return 1;
601
2021-08-29
op
} else if (!strcmp(var, "new-tab-url")) {
602
2021-08-29
op
free(new_tab_url);
603
2021-06-19
op
new_tab_url = val;
604
2021-06-19
op
} else
605
2021-06-19
op
return 0;
606
2021-06-19
op
return 1;
607
2021-06-19
op
}
608
2021-06-21
op
609
2021-06-21
op
int
610
2021-06-21
op
config_setcolor(int bg, const char *name, int prfx, int line, int trail)
611
2021-06-21
op
{
612
2021-08-26
op
struct mapping *m;
613
2021-06-24
op
struct line_face *f;
614
2021-06-21
op
615
2021-06-22
op
if (!strcmp(name, "tabline")) {
616
2021-06-22
op
if (bg)
617
2021-06-22
op
tab_face.bg_bg = prfx;
618
2021-06-22
op
else
619
2021-06-22
op
tab_face.bg_fg = prfx;
620
2022-04-24
op
} else if (!strncmp(name, "tabline.", 8)) {
621
2021-06-22
op
name += 8;
622
2021-06-22
op
623
2021-06-22
op
if (!strcmp(name, "tab")) {
624
2021-06-22
op
if (bg)
625
2021-06-22
op
tab_face.t_bg = prfx;
626
2021-06-22
op
else
627
2021-06-22
op
tab_face.t_fg = prfx;
628
2021-06-22
op
} else if (!strcmp(name, "current")) {
629
2021-06-22
op
if (bg)
630
2021-06-22
op
tab_face.c_bg = prfx;
631
2021-06-22
op
else
632
2021-06-22
op
tab_face.c_fg = prfx;
633
2021-06-22
op
} else
634
2021-06-22
op
return 0;
635
2022-04-24
op
} else if (!strncmp(name, "line.", 5)) {
636
2021-06-21
op
name += 5;
637
2021-06-21
op
638
2021-06-21
op
if ((m = mapping_by_name(name)) == NULL)
639
2021-06-21
op
return 0;
640
2021-06-21
op
641
2021-06-24
op
f = &line_faces[m->linetype];
642
2021-06-21
op
643
2021-06-21
op
if (bg) {
644
2021-06-24
op
f->prfx_bg = prfx;
645
2021-06-24
op
f->bg = line;
646
2021-06-24
op
f->trail_bg = trail;
647
2021-06-21
op
} else {
648
2021-06-24
op
f->prfx_fg = prfx;
649
2021-06-24
op
f->fg = line;
650
2021-06-24
op
f->trail_fg = trail;
651
2021-06-21
op
}
652
2021-06-21
op
} else if (!strcmp(name, "line")) {
653
2021-06-21
op
if (bg) {
654
2021-06-21
op
body_face.lbg = prfx;
655
2021-06-21
op
body_face.bg = line;
656
2021-06-21
op
body_face.rbg = trail;
657
2021-06-21
op
} else {
658
2021-06-25
op
body_face.lfg = prfx;
659
2021-06-21
op
body_face.fg = line;
660
2021-06-25
op
body_face.rfg = trail;
661
2021-06-21
op
}
662
2021-11-05
op
} else if (!strcmp(name, "download")) {
663
2021-11-05
op
if (bg)
664
2021-11-05
op
download_face.bg = prfx;
665
2021-11-05
op
else
666
2021-11-05
op
download_face.fg = prfx;
667
2021-06-25
op
} else if (!strcmp(name, "minibuffer")) {
668
2021-06-25
op
if (bg)
669
2021-06-25
op
minibuffer_face.bg = prfx;
670
2021-06-25
op
else
671
2021-06-25
op
minibuffer_face.fg = prfx;
672
2021-06-25
op
} else if (!strcmp(name, "modeline")) {
673
2021-06-25
op
if (bg)
674
2021-06-25
op
modeline_face.bg = prfx;
675
2021-06-25
op
else
676
2021-06-25
op
modeline_face.fg = prfx;
677
2021-06-21
op
} else {
678
2021-06-21
op
return 0;
679
2021-06-21
op
}
680
2021-06-21
op
681
2021-06-21
op
return 1;
682
2021-06-21
op
}
683
2021-06-21
op
684
2021-06-22
op
int
685
2021-06-22
op
config_setattr(const char *name, int prfx, int line, int trail)
686
2021-06-22
op
{
687
2021-06-22
op
struct mapping *m;
688
2021-06-24
op
struct line_face *f;
689
2021-06-22
op
690
2021-06-22
op
if (!strcmp(name, "tabline")) {
691
2021-06-22
op
tab_face.bg_attr = prfx;
692
2022-04-24
op
} else if (!strncmp(name, "tabline.", 8)) {
693
2021-06-22
op
name += 8;
694
2021-06-22
op
695
2021-06-22
op
if (!strcmp(name, "tab"))
696
2021-06-22
op
tab_face.t_attr = prfx;
697
2021-06-22
op
else if (!strcmp(name, "current"))
698
2021-06-22
op
tab_face.c_attr = prfx;
699
2021-06-22
op
else
700
2021-06-22
op
return 0;
701
2022-04-24
op
} else if (!strncmp(name, "line.", 5)) {
702
2021-06-22
op
name += 5;
703
2021-06-22
op
704
2021-06-22
op
if ((m = mapping_by_name(name)) == NULL)
705
2021-06-22
op
return 0;
706
2021-06-22
op
707
2021-06-24
op
f = &line_faces[m->linetype];
708
2021-06-22
op
709
2021-06-24
op
f->prfx_attr = prfx;
710
2021-06-24
op
f->attr = line;
711
2021-06-24
op
f->trail_attr = trail;
712
2021-11-05
op
} else if (!strcmp(name, "download")) {
713
2021-11-05
op
download_face.attr = prfx;
714
2021-06-25
op
} else if (!strcmp(name, "minibuffer")) {
715
2021-06-25
op
minibuffer_face.attr = prfx;
716
2021-06-25
op
} else if (!strcmp(name, "modeline")) {
717
2021-06-25
op
modeline_face.attr = prfx;
718
2021-06-22
op
} else {
719
2021-06-22
op
return 0;
720
2021-06-22
op
}
721
2021-06-22
op
722
2021-06-22
op
return 1;
723
2021-06-24
op
}
724
2021-06-24
op
725
2021-06-24
op
static inline void
726
2021-06-24
op
tl_init_pair(int colors, int pair, int f, int b)
727
2021-06-24
op
{
728
2021-06-24
op
if (f >= colors || !enable_colors)
729
2021-06-24
op
f = -1;
730
2021-06-24
op
if (b >= colors || !enable_colors)
731
2021-06-24
op
b = -1;
732
2021-06-24
op
init_pair(pair, f, b);
733
2021-06-22
op
}
734
2021-06-22
op
735
2021-06-21
op
void
736
2021-06-24
op
config_apply_style(void)
737
2021-06-21
op
{
738
2021-06-24
op
size_t i, colors, len;
739
2021-06-21
op
struct line_face *f;
740
2021-06-21
op
741
2021-06-24
op
colors = COLORS;
742
2021-06-24
op
743
2021-06-24
op
len = sizeof(line_faces)/sizeof(line_faces[0]);
744
2021-06-21
op
for (i = 0; i < len; ++i) {
745
2021-06-21
op
f = &line_faces[i];
746
2021-06-21
op
747
2021-06-24
op
tl_init_pair(colors, f->prfx_pair, f->prfx_fg, f->prfx_bg);
748
2021-06-24
op
f->prefix = COLOR_PAIR(f->prfx_pair) | f->prfx_attr;
749
2021-06-21
op
750
2021-06-24
op
tl_init_pair(colors, f->pair, f->fg, f->bg);
751
2021-06-24
op
f->text = COLOR_PAIR(f->pair) | f->attr;
752
2021-06-21
op
753
2021-06-24
op
tl_init_pair(colors, f->trail_pair, f->trail_fg, f->trail_bg);
754
2021-06-24
op
f->trail = COLOR_PAIR(f->trail_pair) | f->trail_attr;
755
2021-06-21
op
}
756
2021-06-21
op
757
2021-06-22
op
/* tab line */
758
2021-06-24
op
tl_init_pair(colors, PTL_BG, tab_face.bg_fg, tab_face.bg_bg);
759
2021-06-22
op
tab_face.background = COLOR_PAIR(PTL_BG) | tab_face.bg_attr;
760
2021-06-22
op
761
2021-06-24
op
tl_init_pair(colors, PTL_TAB, tab_face.t_fg, tab_face.t_bg);
762
2021-06-22
op
tab_face.tab = COLOR_PAIR(PTL_TAB) | tab_face.t_attr;
763
2021-06-22
op
764
2021-06-24
op
tl_init_pair(colors, PTL_CURR, tab_face.c_fg, tab_face.c_bg);
765
2021-06-22
op
tab_face.current = COLOR_PAIR(PTL_CURR) | tab_face.c_attr;
766
2021-06-22
op
767
2021-06-22
op
/* body */
768
2021-06-24
op
tl_init_pair(colors, PBODY, body_face.fg, body_face.bg);
769
2021-06-21
op
body_face.body = COLOR_PAIR(PBODY);
770
2021-06-21
op
771
2021-06-24
op
tl_init_pair(colors, PBLEFT, body_face.lfg, body_face.lbg);
772
2021-06-21
op
body_face.left = COLOR_PAIR(PBLEFT);
773
2021-06-21
op
774
2021-06-24
op
tl_init_pair(colors, PBRIGHT, body_face.rfg, body_face.rbg);
775
2021-06-21
op
body_face.right = COLOR_PAIR(PBRIGHT);
776
2021-06-25
op
777
2021-11-05
op
/* download */
778
2021-11-05
op
tl_init_pair(colors, PDOWNLOAD_WIN, download_face.fg, download_face.bg);
779
2021-11-05
op
download_face.background = COLOR_PAIR(PDOWNLOAD_WIN) | download_face.attr;
780
2021-11-05
op
781
2021-06-25
op
/* modeline */
782
2021-06-25
op
tl_init_pair(colors, PMODELINE, modeline_face.fg, modeline_face.bg);
783
2021-06-25
op
modeline_face.background = COLOR_PAIR(PMODELINE) | modeline_face.attr;
784
2021-06-25
op
785
2021-06-25
op
/* minibuffer */
786
2021-06-25
op
tl_init_pair(colors, PMINIBUF, minibuffer_face.fg, minibuffer_face.bg);
787
2021-06-25
op
minibuffer_face.background = COLOR_PAIR(PMINIBUF) | minibuffer_face.attr;
788
2021-06-25
op
789
2021-06-21
op
}
Omar Polo