feat(cli): make preview window for fzf optional

This commit is contained in:
Benex254
2024-08-05 09:47:02 +03:00
parent 52178cf38a
commit 5877525c15
3 changed files with 27 additions and 8 deletions

View File

@@ -85,6 +85,8 @@ signal.signal(signal.SIGINT, handle_exit)
@click.option("-d", "--downloads-dir", type=click.Path(), help="Downloads location")
@click.option("--fzf", is_flag=True, help="Use fzf for the ui")
@click.option("--default", is_flag=True, help="Use the default interface")
@click.option("--preview", is_flag=True, help="Show preview when using fzf")
@click.option("--no-preview", is_flag=True, help="Dont show preview when using fzf")
@click.pass_context
def run_cli(
ctx: click.Context,
@@ -98,6 +100,8 @@ def run_cli(
downloads_dir,
fzf,
default,
preview,
no_preview,
):
ctx.obj = Config()
if server:
@@ -123,3 +127,7 @@ def run_cli(
ctx.obj.use_fzf = True
if default:
ctx.obj.use_fzf = False
if preview:
ctx.obj.preview = True
if no_preview:
ctx.obj.preview = False

View File

@@ -27,6 +27,7 @@ class Config(object):
"translation_type": "sub",
"preferred_language": "english",
"use_fzf": "False",
"preview": "False",
}
)
self.configparser.add_section("stream")
@@ -40,6 +41,7 @@ class Config(object):
# --- set defaults ---
self.downloads_dir = self.get_downloads_dir()
self.use_fzf = self.get_use_fzf()
self.preview = self.get_preview()
self.translation_type = self.get_translation_type()
self.sort_by = self.get_sort_by()
self.continue_from_history = self.get_continue_from_history()
@@ -76,6 +78,9 @@ class Config(object):
def get_use_fzf(self):
return self.configparser.getboolean("general", "use_fzf")
def get_preview(self):
return self.configparser.getboolean("general", "preview")
def get_preferred_language(self):
return self.configparser.get("general", "preferred_language")

View File

@@ -578,16 +578,22 @@ def select_anime(config: Config, anilist_config: QueryDict):
for anime in search_results
}
preview = get_preview(search_results, config)
choices = [*anime_data.keys(), "Back"]
if config.use_fzf:
selected_anime_title = fzf.run(
choices,
prompt="Select Anime: ",
header="Search Results",
preview=preview,
)
if config.preview:
preview = get_preview(search_results, config)
selected_anime_title = fzf.run(
choices,
prompt="Select Anime: ",
header="Search Results",
preview=preview,
)
else:
selected_anime_title = fzf.run(
choices,
prompt="Select Anime: ",
header="Search Results",
)
else:
selected_anime_title = fuzzy_inquirer("Select Anime", choices)
# "bat %s/{}" % SEARCH_RESULTS_CACHE