commit 2513365f084c0d27d326cdcf878ecfbf087ea76c from: Omar Polo date: Tue Jan 16 17:03:46 2024 UTC add boolean variables The 'if zero/nonzero then...' is a bit annoying. Add proper booleans to the grammar of the config and use them when appropriate. Makes the description and the review of configuration files easier. This means that the old set olivetti-mode = 1 can now be written as set olivetti-mode = true Compatibility with the previous integer values will be kept for a while. commit - 2f51c5bdf3c4439827e2c4ff210bcc440c95fda2 commit + 2513365f084c0d27d326cdcf878ecfbf087ea76c blob - eb35860fb37a032652b98ced703e735d9ac71088 blob + 0b4971fc44214945ecb1df3877f546576620a3b6 --- defaults.c +++ defaults.c @@ -542,30 +542,12 @@ config_setvari(const char *var, int val) { if (!strcmp(var, "autosave")) { autosave = val; - } else if (!strcmp(var, "dont-wrap-pre")) { - dont_wrap_pre = !!val; - } else if (!strcmp(var, "emojify-link")) { - emojify_link = !!val; - } else if (!strcmp(var, "enable-colors")) { - enable_colors = !!val; } else if (!strcmp(var, "fill-column")) { if ((fill_column = val) <= 0) fill_column = INT_MAX; - } else if (!strcmp(var, "fringe-ignore-offset")) { - fringe_ignore_offset = !!val; - } else if (!strcmp(var, "hide-pre-blocks")) { - hide_pre_blocks = !!val; - } else if (!strcmp(var, "hide-pre-closing-line")) { - hide_pre_closing_line = !!val; - } else if (!strcmp(var, "hide-pre-context")) { - hide_pre_context = !!val; - } else if (!strcmp(var, "load-url-use-heuristic")) { - load_url_use_heuristic = !!val; } else if (!strcmp(var, "max-killed-tabs")) { if (val >= 0) max_killed_tabs = MIN(val, 128); - } else if (!strcmp(var, "olivetti-mode")) { - olivetti_mode = !!val; } else if (!strcmp(var, "tab-bar-show")) { if (val < 0) tab_bar_show = -1; @@ -573,9 +555,6 @@ config_setvari(const char *var, int val) tab_bar_show = 0; else tab_bar_show = 1; - } else if (!strcmp(var, "update-title") || - !strcmp(var, "set-title")) { - set_title = !!val; } else { return 0; } @@ -614,6 +593,64 @@ config_setvars(const char *var, char *val) } int +config_setvarb(const char *var, int val) { + val = !!val; + + if (!strcmp(var, "dont-wrap-pre")) { + dont_wrap_pre = val; + return 1; + } + + if (!strcmp(var, "emojify-link")) { + emojify_link = val; + return 1; + } + + if (!strcmp(var, "enable-colors")) { + enable_colors = val; + return 1; + } + + if (!strcmp(var, "fringe-ignore-offset")) { + fringe_ignore_offset = val; + return 1; + } + + if (!strcmp(var, "hide-pre-blocks")) { + hide_pre_blocks = val; + return 1; + } + + if (!strcmp(var, "hide-pre-closing-line")) { + hide_pre_closing_line = val; + return 1; + } + + if (!strcmp(var, "hide-pre-context")) { + hide_pre_context = val; + return 1; + } + + if (!strcmp(var, "load-url-use-heuristic")) { + load_url_use_heuristic = val; + return 1; + } + + if (!strcmp(var, "olivetti-mode")) { + olivetti_mode = val; + return 1; + } + + if (!strcmp(var, "update-title") || + !strcmp(var, "set-title")) { + set_title = val; + return 1; + } + + return 0; +} + +int config_setcolor(int bg, const char *name, int prfx, int line, int trail) { struct mapping *m; blob - 06e2a4f7feb58888450b2e1f79524db54c66754a blob + b52d550568e8735f56e4da0206d63aeb4628fbf7 --- include/defaults.h +++ include/defaults.h @@ -93,6 +93,7 @@ void config_init(void); int config_setprfx(const char *, const char *, const char *); int config_setvari(const char *, int); int config_setvars(const char *, char *); +int config_setvarb(const char *, int); int config_setcolor(int, const char *, int, int, int); int config_setattr(const char *, int, int, int); void config_apply_style(void); blob - 853d41e7d8526b498cc7137a0ec966ddba07e91c blob + 6689475de65ee43c5d9f3483d5b726dd77bfafc9 --- parse.y +++ parse.y @@ -60,6 +60,7 @@ static int yylex(void); static void setprfx(const char *, const char *); static void setvari(char *, int); static void setvars(char *, char *); +static void setvarb(char *, int); static int colorname(const char *); static void setcolor(const char *, const char *, const char *); static int attrname(const char *); @@ -79,8 +80,12 @@ static void do_parseconfig(const char *, int); %token UNBIND %token VIA +/* Sigh... they conflict with ncurses TRUE and FALSE */ +%token TOK_TRUE TOK_FALSE + %token STRING %token NUMBER +%type bool %% @@ -88,6 +93,10 @@ grammar : /* empty */ | grammar '\n' | grammar rule '\n' | error '\n' + ; + +bool : TOK_TRUE { $$ = 1; } + | TOK_FALSE { $$ = 0; } ; rule : set @@ -102,6 +111,7 @@ rule : set set : SET STRING '=' STRING { setvars($2, $4); } | SET STRING '=' NUMBER { setvari($2, $4); } + | SET STRING '=' bool { setvarb($2, $4); } ; style : STYLE STRING { current_style = $2; } stylespec ; @@ -164,11 +174,13 @@ static struct keyword { { "bg", BG }, { "bind", BIND }, { "cont", CONT }, + { "false", TOK_FALSE }, { "fg", FG }, { "prefix", PRFX }, { "proxy", PROXY }, { "set", SET }, { "style", STYLE }, + { "true", TOK_TRUE }, { "unbind", UNBIND }, { "via", VIA }, }; @@ -327,7 +339,12 @@ setprfx(const char *prfx, const char *cont) static void setvari(char *var, int val) { - if (!config_setvari(var, val)) + /* + * For some time, fall back to a boolean as compat + * with telescope 0.8 and previous. + */ + if (!config_setvari(var, val) && + !config_setvarb(var, val)) yyerror("invalid variable or value: %s = %d", var, val); @@ -344,6 +361,16 @@ setvars(char *var, char *val) free(var); } +static void +setvarb(char *var, int val) +{ + if (!config_setvarb(var, val)) + yyerror("invalid variable or value: %s = %s", + var, val ? "true" : "false"); + + free(var); +} + static int colorname(const char *name) { blob - 2da8f955d1f940939a6b3950f27800f1c3ed324b blob + 3cf942cce57f8348c499c035e7b99fd429efa22a --- telescope.1 +++ telescope.1 @@ -255,72 +255,73 @@ seconds after some events happens .Pq new or closed tabs, visited a link ... Defaults to 20. .It Ic dont-wrap-pre -.Pq integer -If nonzero, don't wrap preformatted blocks. -Defaults to 0. +.Pq boolean +If true, don't wrap preformatted blocks. +Defaults to false. .It Ic download-path .Pq string The default download path. Defaults to .Pa /tmp . .It Ic emojify-link -.Pq integer -If nonzero, when the text of a link starts with an emoji followed by a -space, use that emoji as line prefix. -Defaults to 1. +.Pq boolean +If true, when the text of a link starts with an emoji followed by a +space, use that emoji as line prefix. +Defaults to true. .It Ic enable-colors -.Pq integer -If nonzero, enable colours. -Defaults to 0 if +.Pq boolean +If true, enable colours. +Defaults to false if .Ev NO_COLORS -is set, 1 otherwise. +is set, true otherwise. .It Ic fill-column .Pq integer If greater than zero, lines of text will be formatted in a way that don't exceed the given number of columns. Defaults to 80. .It Ic fringe-ignore-offset -.Pq integer -If nonzero, the fringe doesn't obey to +.Pq boolean +If true, the fringe doesn't obey to .Ic olivetti-mode . -Defaults to 1. +Defaults to false. .It Ic hide-pre-blocks -.Pq integer -If nonzero, hide by default the body of the preformatted blocks. -Defaults to zero. +.Pq boolean +If true, hide by default the body of the preformatted blocks. +Defaults to false. .Ic push-button can be used to toggle the visibility per-block. .It Ic hide-pre-closing-line -.Pq integer -If nonzero, hide the closing line of preformatted blocks. -Defaults to 0. +.Pq boolean +If true, hide the closing line of preformatted blocks. +Defaults to false. .It Ic hide-pre-context -.Pq integer -If nonzero, hide the start and end line of the preformatted blocks. +.Pq boolean +If true, hide the start and end line of the preformatted blocks. If both hide-pre-context and hide-pre-blocks are nonzero, preformatted blocks are irremediably hidden. -Defaults to zero. +Defaults to false. .It Ic new-tab-url .Pq string URL for the new tab page. Defaults to .Dq about:new . .It Ic load-url-use-heuristic -If zero, don't use euristics to resolve the URLs. +.Pq boolean +If false, don't use euristics to resolve the URLs. Non-absolute URLs given as command line argument will be resolved as file system paths, .Ic load-url will resolve as relative to the current URL. -Defaults to 1. +Defaults to true. .It Ic max-killed-tabs .Pq integer The maximum number of closed tabs to keep track of, defaults to 10. Must be a positive number; if zero, don't save closed tabs at all. .It Ic olivetti-mode -.Pq integer -If nonzero, enable +.Pq boolean +If true, enable .Ic olivetti-mode -Defaults to 1. +Defaults to true. .It Ic tab-bar-show .Pq integer If tab-bar-show is -1 hide the tab bar permanently, if 0 show it @@ -328,9 +329,9 @@ unconditionally. If it's 1, show the bar only when there is more than one tab. Defaults to 1. .It Ic update-title -.Pq integer -If nonzero, set the terminal title to the page title. -Defaults to 1. +.Pq boolean +If true, set the terminal title to the page title. +Defaults to true. .El .It Ic style Ar name Ar option Change the styling of the element identified by