make page titles consistent, add landing page func
This commit is contained in:
parent
f7615ff7f9
commit
55196c60fe
27
nex.py
27
nex.py
|
@ -1,9 +1,9 @@
|
|||
import sys
|
||||
import socket
|
||||
import pytermgui as ptg
|
||||
from typing import Tuple
|
||||
import re
|
||||
import logging
|
||||
import pytermgui as ptg
|
||||
from typing import Tuple
|
||||
|
||||
PORT = 1900
|
||||
|
||||
|
@ -58,22 +58,28 @@ class Page:
|
|||
|
||||
@property
|
||||
def title(self):
|
||||
return f'nex://{self.url}'
|
||||
prefix = 'nex://'
|
||||
if self.url.startswith(prefix):
|
||||
return self.url[len(prefix):]
|
||||
return self.url
|
||||
|
||||
def _parse_links(self):
|
||||
pattern = re.compile(r'=>\s*([\w/:\.~-]*)\s*')
|
||||
self.links = pattern.findall(self.raw_content)
|
||||
|
||||
|
||||
landing_page = Page('')
|
||||
landing_page.raw_content = 'Welcome to PyNex'
|
||||
landing_page.content = landing_page.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
|
||||
|
||||
|
||||
class Session:
|
||||
def __init__(self):
|
||||
self.pages = {'': landing_page}
|
||||
self.history = ['']
|
||||
home_page = create_landing_page()
|
||||
self.pages = {home_page.url: home_page}
|
||||
self.history = [home_page.url]
|
||||
self.curr_index = 0
|
||||
|
||||
@property
|
||||
|
@ -147,8 +153,9 @@ class Browser(ptg.WindowManager):
|
|||
self.add(self.footer)
|
||||
|
||||
def update(self):
|
||||
self.page_container.set_widgets([self.session.current_page.content])
|
||||
self.body.set_title(f'[bold tertiary]{self.session.current_page.title}', 1)
|
||||
page = self.session.current_page
|
||||
self.page_container.set_widgets([page.content])
|
||||
self.body.set_title(f'[bold tertiary]{page.title}', 1)
|
||||
|
||||
def back(self, *args):
|
||||
self.session.prev()
|
||||
|
|
Loading…
Reference in New Issue