Compare commits

..

5 Commits

3 changed files with 23 additions and 16 deletions

View File

@ -82,6 +82,11 @@ To change the default settings for users of the system, amend the following opti
Customise the command used to execute the default browser used by linkulator. Default is *lynx*
#### Default gemini browser
*String gemini*
Customise the command used to execute the default gemini browser used by linkulator. Default is *amfora*
### User settings
Users can select their preferred browser by changing the browser setting in their settings file (default is $HOME/.linkulator/linkulatorrc).

View File

@ -28,12 +28,23 @@ class DefaultUser:
settingsfile: Path = datadir / PATHS.settingsfile
lastlogin: str = "0.0"
browser: str = "lynx"
handler: dict = {
"http": "lynx",
"https": "lynx",
"gopher": "lynx",
"gemini": "amfora",
"ssh": "putty"
}
def save(self):
"""Saves config data to file"""
config = configparser.ConfigParser()
config["User Status"] = {"lastlogin": time()}
config["User Settings"] = {"browser": self.browser}
config["URL Handler"] = self.handler
with open(self.settingsfile, "w") as file:
config.write(file)
@ -44,6 +55,7 @@ class DefaultUser:
if len(ret) > 0:
self.lastlogin = config["User Status"]["lastlogin"]
self.browser = config["User Settings"]["browser"]
self.handler = config["URL Handler"]
USER = DefaultUser()

View File

@ -74,10 +74,7 @@ def print_category_details(view_cat):
for link in category_details:
link_count += 1
thread_index[link_count] = link["postid"]
if(desclen > 0):
desc = textwrap.shorten(link["description"], width=desclen, placeholder="...")
else:
desc = link["description"]
desc = textwrap.shorten(link["description"], width=desclen, placeholder="...")
newmarker = (
"*" if link["last_modified_timestamp"] >= config.USER.lastlogin else ""
)
@ -218,19 +215,11 @@ def search():
def view_link_in_browser(url):
"""Attempts to view the specified URL in the configured browser"""
if which(config.USER.browser) is None:
print(
"Sorry, "
+ config.USER.browser
+ " is not installed on your system. Ask your sysadmin to install it."
)
return
url_scheme = urlparse(url).scheme
if url_scheme in ["gopher", "https", "http"]:
subprocess.call([config.USER.browser, url])
if url_scheme in config.USER.handler and which(config.USER.handler[url_scheme]):
subprocess.call([config.USER.handler[url_scheme], url])
else:
print("Sorry, that url doesn't start with gopher://, http:// or https://")
print("Sorry, there is no handler assigned to '{}'".format(url_scheme))
try_anyway = input(
"Do you want to try it in {} anyway? Y/[N]".format(config.USER.browser)
).lower()
@ -421,7 +410,8 @@ def menu_view_thread_details(post_id):
option_text = "Type {} to reply, {} to view in {}, {} to search, {} to post a new link, {} to go back, or {} to quit: ".format(
style_text("r", True, "underline"),
style_text("b", True, "underline"),
config.USER.browser,
# config.USER.browser,
"browser",
style_text("s", True, "underline"),
style_text("p", True, "underline"),
style_text("m", True, "underline"),