add: save last cursor pos
This commit is contained in:
parent
3dd457c9dd
commit
a8279c146c
@ -45,11 +45,19 @@ class Database():
|
|||||||
last_path = cookies.get("last_path")
|
last_path = cookies.get("last_path")
|
||||||
return (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):
|
def set_last_site(self, value):
|
||||||
self.cookies_table.update(set("last_site", value), self.query.id == "0")
|
self.cookies_table.update(set("last_site", value), self.query.id == "0")
|
||||||
|
|
||||||
def set_last_path(self, value):
|
def set_last_path(self, value):
|
||||||
self.cookies_table.update(set("last_path", value), self.query.id == "0")
|
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):
|
def add_site(self, site):
|
||||||
self.sites_table.insert(site)
|
self.sites_table.insert(site)
|
||||||
|
6
main.py
6
main.py
@ -11,10 +11,12 @@ def files_navigator(site: dict):
|
|||||||
path = database.get_last_path()
|
path = database.get_last_path()
|
||||||
else:
|
else:
|
||||||
path = '/'
|
path = '/'
|
||||||
|
database.set_last_site(site.get("id"))
|
||||||
while True:
|
while True:
|
||||||
|
pos = database.get_last_cursor_pos()
|
||||||
path = get_uri(get_url(site) + path)
|
path = get_uri(get_url(site) + path)
|
||||||
database.set_last_path(path)
|
database.set_last_path(path)
|
||||||
file = menu.files(site, path)
|
file = menu.files(site, path, database, pos)
|
||||||
if (file == None):
|
if (file == None):
|
||||||
return
|
return
|
||||||
elif (file == "../" and path == "/"):
|
elif (file == "../" and path == "/"):
|
||||||
@ -104,5 +106,5 @@ def sites_navigator(database: Database):
|
|||||||
database = Database()
|
database = Database()
|
||||||
|
|
||||||
if (database.get_cookies_table_len() == 0):
|
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);
|
sites_navigator(database);
|
||||||
|
11
menu.py
11
menu.py
@ -9,8 +9,8 @@ uri = ""
|
|||||||
preview_site = {}
|
preview_site = {}
|
||||||
preview_database = ""
|
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):
|
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
|
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());
|
return (menu.show());
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ def files_preview(filename: str) -> str:
|
|||||||
files = get_files(preview_site, uri + filename)
|
files = get_files(preview_site, uri + filename)
|
||||||
return ("\n".join(files))
|
return ("\n".join(files))
|
||||||
|
|
||||||
def files(site, path):
|
def files(site:dict, path:str, database:Database, pos:int):
|
||||||
global uri
|
global uri
|
||||||
global preview_site
|
global preview_site
|
||||||
|
|
||||||
@ -44,9 +44,12 @@ def files(site, path):
|
|||||||
preview_command=files_preview,
|
preview_command=files_preview,
|
||||||
preview_size=0.3,
|
preview_size=0.3,
|
||||||
show_search_hint=True,
|
show_search_hint=True,
|
||||||
title=f"Index of {path}")
|
title=f"Index of {path}",
|
||||||
|
cursor_pos = pos)
|
||||||
if (choose == None):
|
if (choose == None):
|
||||||
|
database.set_last_cursor_pos(0)
|
||||||
return (None)
|
return (None)
|
||||||
|
database.set_last_cursor_pos(choose)
|
||||||
return (files[choose])
|
return (files[choose])
|
||||||
|
|
||||||
def config_preview(site_name:str):
|
def config_preview(site_name:str):
|
||||||
|
Loading…
Reference in New Issue
Block a user