Compare commits
No commits in common. "2c130bf515f71b3de811a9024ae8b5f06a6e9d11" and "f7615ff7f9a813aefe2aa00f4695cb9ef35190a8" have entirely different histories.
2c130bf515
...
f7615ff7f9
43
nex.py
43
nex.py
|
@ -1,9 +1,9 @@
|
|||
import sys
|
||||
import socket
|
||||
import re
|
||||
import logging
|
||||
import pytermgui as ptg
|
||||
from typing import Tuple
|
||||
import re
|
||||
import logging
|
||||
|
||||
PORT = 1900
|
||||
|
||||
|
@ -58,28 +58,22 @@ class Page:
|
|||
|
||||
@property
|
||||
def title(self):
|
||||
prefix = 'nex://'
|
||||
if self.url.startswith(prefix):
|
||||
return self.url[len(prefix):]
|
||||
return self.url
|
||||
return f'nex://{self.url}'
|
||||
|
||||
def _parse_links(self):
|
||||
pattern = re.compile(r'=>\s*([\w/:\.~-]*)\s*')
|
||||
self.links = pattern.findall(self.raw_content)
|
||||
|
||||
|
||||
def create_landing_page() -> Page:
|
||||
landing_page = Page('about:home')
|
||||
landing_page.raw_content = 'Welcome to PyNex'
|
||||
landing_page.content = landing_page.raw_content
|
||||
return landing_page
|
||||
landing_page = Page('')
|
||||
landing_page.raw_content = 'Welcome to PyNex'
|
||||
landing_page.content = landing_page.raw_content
|
||||
|
||||
|
||||
class Session:
|
||||
def __init__(self):
|
||||
home_page = create_landing_page()
|
||||
self.pages = {home_page.url: home_page}
|
||||
self.history = [home_page.url]
|
||||
self.pages = {'': landing_page}
|
||||
self.history = ['']
|
||||
self.curr_index = 0
|
||||
|
||||
@property
|
||||
|
@ -120,10 +114,10 @@ class Browser(ptg.WindowManager):
|
|||
vertical_align=ptg.VerticalAlignment.TOP)
|
||||
self.footer = ptg.Window(
|
||||
ptg.Splitter(
|
||||
["(B)ack", self.back],
|
||||
["(F)orward", self.forward],
|
||||
["(R)eload", self.reload],
|
||||
["(Q)uit", lambda *_: self.stop()]
|
||||
ptg.KeyboardButton("Back", self.back, bound='b'),
|
||||
ptg.KeyboardButton("Forward", self.forward, bound='f'),
|
||||
ptg.KeyboardButton("Reload", self.reload, bound='r'),
|
||||
ptg.KeyboardButton("Quit", self.stop, bound='q')
|
||||
),
|
||||
box="EMPTY",
|
||||
is_persistant=True
|
||||
|
@ -134,13 +128,10 @@ class Browser(ptg.WindowManager):
|
|||
self.update()
|
||||
|
||||
def _create_key_bindings(self):
|
||||
self.bind(ptg.keys.DOWN, lambda *_: self.body.scroll(5))
|
||||
self.bind(ptg.keys.UP, lambda *_: self.body.scroll(-5))
|
||||
self.bind('j', lambda *_: self.body.scroll(5))
|
||||
self.bind(ptg.keys.DOWN, lambda *_: self.body.scroll(5))
|
||||
self.bind('k', lambda *_: self.body.scroll(-5))
|
||||
self.bind('b', self.back)
|
||||
self.bind('f', self.forward)
|
||||
self.bind('r', self.reload)
|
||||
self.bind(ptg.keys.UP, lambda *_: self.body.scroll(-5))
|
||||
self.bind('q', lambda *_: self.stop())
|
||||
|
||||
for i in range(10):
|
||||
|
@ -151,13 +142,13 @@ class Browser(ptg.WindowManager):
|
|||
self.layout.add_break()
|
||||
self.layout.add_slot("Footer", height=1)
|
||||
|
||||
# self.add(self.header)
|
||||
self.add(self.body)
|
||||
self.add(self.footer)
|
||||
|
||||
def update(self):
|
||||
page = self.session.current_page
|
||||
self.page_container.set_widgets([page.content])
|
||||
self.body.set_title(f'[bold tertiary]{page.title}', 1)
|
||||
self.page_container.set_widgets([self.session.current_page.content])
|
||||
self.body.set_title(f'[bold tertiary]{self.session.current_page.title}', 1)
|
||||
|
||||
def back(self, *args):
|
||||
self.session.prev()
|
||||
|
|
Loading…
Reference in New Issue