From 0db7d4bdaa14a56ac437d72c8fc447c443c62b67 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 6 Sep 2026 13:37:35 +0200 Subject: [PATCH] Added image loading config. Added auto-load check based on RTT and EDR. --- nomadnet/NomadNetworkApp.py | 23 +++++++++++++++++++++++ nomadnet/ui/TextUI.py | 5 +++++ nomadnet/ui/textui/Browser.py | 28 +++++++++++++++++++++++++++- nomadnet/ui/textui/Config.py | 8 ++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/nomadnet/NomadNetworkApp.py b/nomadnet/NomadNetworkApp.py index 1319e5f..edc6833 100644 --- a/nomadnet/NomadNetworkApp.py +++ b/nomadnet/NomadNetworkApp.py @@ -994,6 +994,20 @@ class NomadNetworkApp: else: raise ValueError("The selected Text UI color mode is invalid") + if not "image_loading" in self.config["textui"]: + self.config["textui"]["image_loading"] = nomadnet.ui.TextUI.IMGLOAD_AUTO + else: + if self.config["textui"]["image_loading"].lower() == "never": + self.config["textui"]["image_loading"] = nomadnet.ui.TextUI.IMGLOAD_NEVER + elif self.config["textui"]["image_loading"].lower() == "manual": + self.config["textui"]["image_loading"] = nomadnet.ui.TextUI.IMGLOAD_MANUAL + elif self.config["textui"]["image_loading"].lower() == "auto": + self.config["textui"]["image_loading"] = nomadnet.ui.TextUI.IMGLOAD_AUTO + elif self.config["textui"]["image_loading"].lower() == "always": + self.config["textui"]["image_loading"] = nomadnet.ui.TextUI.IMGLOAD_ALWAYS + else: + raise ValueError("The selected image loading mode is invalid") + if not "theme" in self.config["textui"]: self.config["textui"]["theme"] = nomadnet.ui.TextUI.THEME_DARK else: @@ -1400,6 +1414,15 @@ colormode = 24bit # glyphs = unicode glyphs = nerdfont +# If your terminal supports image output, +# the page browser can display images and +# graphics on pages. You can specify how, +# or if at all, images are loaded. Valid +# options are "auto", "manual", "never" +# and "always". + +image_loading = auto + # You can specify whether mouse events # should be considered as input to the # application. On by default. diff --git a/nomadnet/ui/TextUI.py b/nomadnet/ui/TextUI.py index bdc13bb..413972d 100644 --- a/nomadnet/ui/TextUI.py +++ b/nomadnet/ui/TextUI.py @@ -16,6 +16,11 @@ COLORMODE_88 = 88 COLORMODE_256 = 256 COLORMODE_TRUE = 2**24 +IMGLOAD_NEVER = 0x00 +IMGLOAD_MANUAL = 0x01 +IMGLOAD_AUTO = 0x02 +IMGLOAD_ALWAYS = 0x03 + THEMES = { THEME_DARK: { "urwid_theme": [ diff --git a/nomadnet/ui/textui/Browser.py b/nomadnet/ui/textui/Browser.py index 1b57133..7487d48 100644 --- a/nomadnet/ui/textui/Browser.py +++ b/nomadnet/ui/textui/Browser.py @@ -19,6 +19,11 @@ from nomadnet.ui.textui.images import _termlib from .Helpers import ClickableIcon, osc52_copy from .ReadlineEdit import ReadlineMixin, ReadlineEdit +IMGLOAD_NEVER = 0x00 +IMGLOAD_MANUAL = 0x01 +IMGLOAD_AUTO = 0x02 +IMGLOAD_ALWAYS = 0x03 + class BrowserFrame(urwid.Frame): def keypress(self, size, key): if key == "ctrl w": @@ -133,7 +138,8 @@ class Browser: self.image_updater_running = False self.partial_updater_lock = Lock() self.image_updater_lock = Lock() - self.image_rendering_supported = _termlib.is_kitty_supported() + self.image_mode = self.app.config["textui"]["image_loading"] + self.image_rendering_supported = _termlib.is_kitty_supported() and self.image_mode != IMGLOAD_NEVER self.build_display() self.history = [] @@ -671,10 +677,26 @@ class Browser: except Exception: pass def should_load_images(self): + if self.image_mode == IMGLOAD_NEVER: return False + elif self.image_mode == IMGLOAD_MANUAL: return False + elif self.image_mode == IMGLOAD_ALWAYS: return True + elif self.image_mode == IMGLOAD_AUTO: + if self.destination_hash == self.loopback: return True + rtt_limit = 1.5; edr_limit = 10000 + if self.link: + rtt = self.link.rtt + edr = self.link.get_expected_rate() or self.last_response_speed() + rtt_ok = rtt and rtt < rtt_limit + edr_ok = edr and edr > edr_limit + RNS.log(f"Checking image load conditions, RTT is {RNS.prettyshorttime(rtt) if rtt else 'unknown'}, EDR is {RNS.prettyspeed(edr) if edr else 'unknown'}", RNS.LOG_DEBUG) + if rtt_ok and edr_ok: return True + else: return False + return False def load_images(self): if not self.image_rendering_supported: return + elif self.image_mode == IMGLOAD_NEVER: return else: self.detect_images() def detect_images(self): @@ -2107,6 +2129,10 @@ class Browser: self.update_display() + def last_response_speed(self): + if self.response_transfer_size and self.response_time: + return (self.response_transfer_size/max(self.response_time, 0.0001))*8 + else: return None def status_text(self): if self.status == Browser.DONE and self.response_transfer_size != None: diff --git a/nomadnet/ui/textui/Config.py b/nomadnet/ui/textui/Config.py index 7a0f771..8c54f08 100644 --- a/nomadnet/ui/textui/Config.py +++ b/nomadnet/ui/textui/Config.py @@ -239,6 +239,14 @@ CONFIG_SECTIONS = [ "default": "24bit", "help": "Colour capability of your terminal", }, + { + "config_key": "image_loading", + "label": "Image Loading: ", + "type": "dropdown", + "options": ["never", "manual", "auto", "always"], + "default": "auto", + "help": "How, or if at all, to load page images", + }, { "config_key": "glyphs", "label": "Glyphs: ",