From 00541a435d42c96db9c143af55716f517b68cde7 Mon Sep 17 00:00:00 2001 From: Emily <102429049+emily-is-my-username@users.noreply.github.com> Date: Tue, 26 Apr 2022 03:01:08 +0200 Subject: [PATCH] add confirmation prompts for url schemes (#302) * add confirmation prompts for url schemes This commit adds a confirmation prompt before following urls with with certain schemes. Wether or not a scheme requires confirmation can be configured in the new `[url-promps]` section. * Use other instead of default * Use other instead of default Co-authored-by: makeworld --- config/config.go | 1 + config/default.go | 12 ++++++++++++ default-config.toml | 12 ++++++++++++ display/handlers.go | 9 +++++++++ 4 files changed, 34 insertions(+) diff --git a/config/config.go b/config/config.go index c52c387..6531fe6 100644 --- a/config/config.go +++ b/config/config.go @@ -257,6 +257,7 @@ func Init() error { viper.SetDefault("keybindings.shift_numbers", "") viper.SetDefault("keybindings.bind_url_handler_open", "Ctrl-U") viper.SetDefault("url-handlers.other", "default") + viper.SetDefault("url-prompts.other", false) viper.SetDefault("cache.max_size", 0) viper.SetDefault("cache.max_pages", 20) viper.SetDefault("cache.timeout", 1800) diff --git a/config/default.go b/config/default.go index ab560f4..a73593e 100644 --- a/config/default.go +++ b/config/default.go @@ -218,6 +218,18 @@ underline = true # application on your computer for opening this kind of URI. other = 'default' +[url-prompts] +# Specify whether a confirmation prompt should be shown before following URL schemes. +# The special key 'other' matches all schemes that don't match any other key. +# +# Example: prompt on every non-gemini URL +# other = true +# gemini = false +# +# Example: only prompt on HTTP(S) +# other = false +# http = true +# https = true # [[mediatype-handlers]] section # --------------------------------- diff --git a/default-config.toml b/default-config.toml index 64a7dce..c465dce 100644 --- a/default-config.toml +++ b/default-config.toml @@ -215,6 +215,18 @@ underline = true # application on your computer for opening this kind of URI. other = 'default' +[url-prompts] +# Specify whether a confirmation prompt should be shown before following URL schemes. +# The special key 'other' matches all schemes that don't match any other key. +# +# Example: prompt on every non-gemini URL +# other = true +# gemini = false +# +# Example: only prompt on HTTP(S) +# other = false +# http = true +# https = true # [[mediatype-handlers]] section # --------------------------------- diff --git a/display/handlers.go b/display/handlers.go index 10fe36f..3f72166 100644 --- a/display/handlers.go +++ b/display/handlers.go @@ -252,6 +252,15 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) { return ret("", false) } + // check if a prompt is needed to handle this url + prompt := viper.GetBool("url-prompts.other") + if viper.IsSet("url-prompts." + parsed.Scheme) { + prompt = viper.GetBool("url-prompts." + parsed.Scheme) + } + if prompt && !(YesNo("Follow URL?\n" + u)) { + return ret("", false) + } + proxy := strings.TrimSpace(viper.GetString("proxies." + parsed.Scheme)) usingProxy := false