diff --git a/von/fzf.py b/von/fzf.py index e938d73..87f897b 100644 --- a/von/fzf.py +++ b/von/fzf.py @@ -2,35 +2,44 @@ import subprocess import sys +from . import view from .model import PickleMappingEntry, VonIndex, setCache from .puid import inferPUID def _fzf_line(entry: PickleMappingEntry, tags: bool) -> str: - puid = inferPUID(entry.source) - line = f"{puid}\t{entry.source:<13}\t" + puid = view.APPLY_COLOR("CYAN", inferPUID(entry.source)) + source = view.APPLY_COLOR(view.getSourceColor(entry), f"{entry.source:<13}") + line = f"{puid}\t{source}\t" if not tags: return line + entry.desc - hashtags = " ".join(f"#{tag}" for tag in entry.tags) + hashtags = view.APPLY_COLOR("RED", " ".join(f"#{tag}" for tag in entry.tags)) return line + f"{entry.desc:<50}\t{hashtags}" def fzf_choose(tags=True) -> str: + brave = view.OPTS.brave + color = view.OPTS.color with VonIndex() as index: - choices = "\n".join(_fzf_line(entry, tags) for entry in index.values()) + choices = "\n".join( + _fzf_line(entry, tags) + for entry in index.values() + if brave or not entry.secret + ) try: chosen = subprocess.check_output( args=[ "fzf", "-e", - # Force left-align results if searching tags. - *(["--no-hscroll"] if tags else []), + *(["--ansi"] if color else []), "--tabstop", "12", "-d", r"\t", "--preview", - f"{shlex.quote(sys.executable)} -m von show {{2}}", + f"{shlex.quote(sys.executable)} -m von show" + + (" --brave" if brave else "") + + " {2}", "--preview-window", "down", ], diff --git a/von/view.py b/von/view.py index ac9a0f3..d111378 100644 --- a/von/view.py +++ b/von/view.py @@ -119,6 +119,17 @@ def getProblemString(problem: Problem, i: int | None = None): return s +def getSourceColor(entry: PickleMappingEntry) -> str: + if "favorite" in entry.tags: + return "BOLD_YELLOW" + elif "nice" in entry.tags: + return "BOLD_CYAN" + elif "good" in entry.tags: + return "BOLD_MAGENTA" + else: + return "BOLD_BLUE" + + def getEntryString(entry: PickleMappingEntry, verbose=False, i: int | None = None): # SPECIAL hide brave if OPTS.verbose is True: @@ -166,14 +177,7 @@ def getEntryString(entry: PickleMappingEntry, verbose=False, i: int | None = Non else: source_string += word + " " source_string = source_string.strip() - if "favorite" in entry.tags: - s += APPLY_COLOR("BOLD_YELLOW", source_string) - elif "nice" in entry.tags: - s += APPLY_COLOR("BOLD_CYAN", source_string) - elif "good" in entry.tags: - s += APPLY_COLOR("BOLD_MAGENTA", source_string) - else: - s += APPLY_COLOR("BOLD_BLUE", source_string) + s += APPLY_COLOR(getSourceColor(entry), source_string) s += " " * max(1, 17 - len(source_string)) # hardness