]> git.the-white-hart.net Git - gemini/cbs-client.git/commitdiff
Add page load at startup and factor out page logic
authorrs <>
Sat, 19 Mar 2022 01:32:56 +0000 (20:32 -0500)
committerrs <>
Sat, 19 Mar 2022 01:32:56 +0000 (20:32 -0500)
cbs.py

diff --git a/cbs.py b/cbs.py
index 84c6997f58509883ce980b23795720b9626274e5..873f84ffeac086029c7c8d6e69896fdbfb5c36d7 100755 (executable)
--- a/cbs.py
+++ b/cbs.py
@@ -152,12 +152,37 @@ class History(object):
         self._hist.append(url)
 
 
+def page_load(window):
+    # Make a request and handle the response
+    status, meta, body = gemini_request(window['-URL-'].get())
+    if 10 <= status < 20:
+        # Input request
+        layout = [[sg.Text(meta)], [sg.InputText()], [sg.Submit(), sg.Cancel()]]
+        event, values = sg.Window('Input Requested', layout).read(close=True)
+        query = '?' + urllib.parse.quote(values[0])
+        window['-URL-'].update(urllib.parse.urljoin(window['-URL-'].get(), query))
+        status, meta, body = gemini_request(window['-URL-'].get())
+    if 20 <= status < 30:  # if instead of elif to allow processing of new request made with input
+        pass  # Success
+    elif 30 <= status < 40:
+        body = '# {} - Redirect\n## {}'.format(status, meta)
+    elif 40 <= status < 50:
+        body = '# {} - Temporary falure\n## {}'.format(status, meta)
+    elif 50 <= status < 60:
+        body = '# {} - Permanent falure\n## {}'.format(status, meta)
+    elif 60 <= status < 70:
+        body = '# {} - Certificate required\n## {}'.format(status, meta)
+    else:
+        body = '# {} - Unknown status code\n## {}'.format(status, meta)
+    return update_content(window, body)
+
+
 def main():
     window = sg.Window('Gemini Client', browser_window_layout(), resizable=True)
     hist = History()
     hist.add(window['-URL-'].get())
     window.finalize()
-    links, overv = update_content(window, '')
+    links, overv = page_load(window)
     while True:
         event, values = window.read()
         if event == sg.WIN_CLOSED:
@@ -179,31 +204,8 @@ def main():
             elif event == '-OVERV-':
                 item = window['-OVERV-'].get_indexes()[0]
                 window['-CONTENT-'].set_vscroll_position(overv[item])
-                continue
-
-            # Make a request and handle the response
-            status, meta, body = gemini_request(window['-URL-'].get())
-            if 10 <= status < 20:
-                # Input request
-                layout = [[sg.Text(meta)], [sg.InputText()], [sg.Submit(), sg.Cancel()]]
-                event, values = sg.Window('Input Requested', layout).read(close=True)
-                query = '?' + urllib.parse.quote(values[0])
-                window['-URL-'].update(urllib.parse.urljoin(window['-URL-'].get(), query))
-                status, meta, body = gemini_request(window['-URL-'].get())
-            if 20 <= status < 30:  # if instead of elif to allow processing of new request made with input
-                pass  # Success
-            elif 30 <= status < 40:
-                body = '# {} - Redirect\n## {}'.format(status, meta)
-            elif 40 <= status < 50:
-                body = '# {} - Temporary falure\n## {}'.format(status, meta)
-            elif 50 <= status < 60:
-                body = '# {} - Permanent falure\n## {}'.format(status, meta)
-            elif 60 <= status < 70:
-                body = '# {} - Certificate required\n## {}'.format(status, meta)
-            else:
-                body = '# {} - Unknown status code\n## {}'.format(status, meta)
-            links, overv = update_content(window, body)
-
+                continue  # No page load, only scroll existing content
+            links, overv = page_load(window)
 
 if __name__ == '__main__':
     main()