add: save last cursor pos

This commit is contained in:
starnakin 2023-05-29 19:23:39 +02:00
parent 3dd457c9dd
commit a8279c146c
3 changed files with 19 additions and 6 deletions

View File

@ -45,11 +45,19 @@ class Database():
last_path = cookies.get("last_path")
return (last_path)
def get_last_cursor_pos(self):
cookies = self.get_cookies()
last_path = cookies.get("last_cursor_pos")
return (last_path)
def set_last_site(self, value):
self.cookies_table.update(set("last_site", value), self.query.id == "0")
def set_last_path(self, value):
self.cookies_table.update(set("last_path", value), self.query.id == "0")
def set_last_cursor_pos(self, value):
self.cookies_table.update(set("last_cursor_pos", value), self.query.id == "0")
def add_site(self, site):
self.sites_table.insert(site)

View File

@ -11,10 +11,12 @@ def files_navigator(site: dict):
path = database.get_last_path()
else:
path = '/'
database.set_last_site(site.get("id"))
while True:
pos = database.get_last_cursor_pos()
path = get_uri(get_url(site) + path)
database.set_last_path(path)
file = menu.files(site, path)
file = menu.files(site, path, database, pos)
if (file == None):
return
elif (file == "../" and path == "/"):
@ -104,5 +106,5 @@ def sites_navigator(database: Database):
database = Database()
if (database.get_cookies_table_len() == 0):
database.add_cookies({"last_path": "", "last_site": "", "id": "0"})
database.add_cookies({"last_path": "", "last_site": "", "last_cursor_pos": 0, "id": "0"})
sites_navigator(database);

11
menu.py
View File

@ -9,8 +9,8 @@ uri = ""
preview_site = {}
preview_database = ""
def get_user_choice_by_menu(options: list, title = None, preview_command=None, preview_size: float = 0.3, show_search_hint: bool = False, skip_empty_entries = False):
menu = Menu(options, title, preview_body_function=preview_command, preview_ratio=preview_size, skip_empty_option=skip_empty_entries
def get_user_choice_by_menu(options: list, title = None, preview_command=None, preview_size: float = 0.3, show_search_hint: bool = False, skip_empty_entries = False, cursor_pos: int = 0):
menu = Menu(options, title, preview_body_function=preview_command, preview_ratio=preview_size, skip_empty_option=skip_empty_entries, cursor_pos=cursor_pos
)
return (menu.show());
@ -33,7 +33,7 @@ def files_preview(filename: str) -> str:
files = get_files(preview_site, uri + filename)
return ("\n".join(files))
def files(site, path):
def files(site:dict, path:str, database:Database, pos:int):
global uri
global preview_site
@ -44,9 +44,12 @@ def files(site, path):
preview_command=files_preview,
preview_size=0.3,
show_search_hint=True,
title=f"Index of {path}")
title=f"Index of {path}",
cursor_pos = pos)
if (choose == None):
database.set_last_cursor_pos(0)
return (None)
database.set_last_cursor_pos(choose)
return (files[choose])
def config_preview(site_name:str):