Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions von/fzf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
20 changes: 12 additions & 8 deletions von/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Loading