generated from felixm/defaultpy
Make fzf prompt more legible
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
CLAUDE.md
|
||||
# ---> Python
|
||||
uv.lock
|
||||
# Byte-compiled / optimized / DLL files
|
||||
|
||||
@@ -5,8 +5,10 @@ import sys
|
||||
EXECUTABLE_NAME = "fzf.exe" if sys.platform == "win32" else "fzf"
|
||||
|
||||
|
||||
def iterfzf(iterable, prompt="> "):
|
||||
cmd = [EXECUTABLE_NAME, "--prompt=" + prompt]
|
||||
def iterfzf(iterable, prompt="> ", header=None, height="50%"):
|
||||
cmd = [EXECUTABLE_NAME, "--prompt=" + prompt, "--height=" + height, "--reverse"]
|
||||
if header:
|
||||
cmd.append("--header=" + header)
|
||||
encoding = sys.getdefaultencoding()
|
||||
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=None)
|
||||
if proc.stdin is None:
|
||||
|
||||
@@ -397,8 +397,9 @@ def add_account2_interactive(transaction: Transaction, categories: List[str]):
|
||||
"""Interactively add account2 to a transaction."""
|
||||
t = transaction
|
||||
account2 = None
|
||||
prompt = f"{t.account1} {t.date} {t.description} {t.debit} > "
|
||||
header = f"{t.account1} | {t.date} | {t.description} | {t.debit}"
|
||||
logging.warning(f"No mapping for '{t}'.")
|
||||
while account2 is None:
|
||||
account2 = iterfzf(categories, prompt=prompt)
|
||||
account2 = iterfzf(categories, header=header)
|
||||
transaction.account2 = account2
|
||||
print(f"Assigned category '{account2}'.")
|
||||
|
||||
@@ -68,6 +68,7 @@ def get_transactions(csv_file: str, config: CsvConfig) -> list[Transaction]:
|
||||
|
||||
def apply_mappings(transactions: list[Transaction], mappings: dict[str, Mapping]):
|
||||
"""Apply mappings to transactions."""
|
||||
unmapped_count = 0
|
||||
for t in transactions:
|
||||
if t.key() in mappings:
|
||||
mapping = mappings[t.key()]
|
||||
@@ -76,7 +77,9 @@ def apply_mappings(transactions: list[Transaction], mappings: dict[str, Mapping]
|
||||
mapping.count -= 1
|
||||
t.mapping = mapping
|
||||
else:
|
||||
logging.warning(f"No mapping for '{t}'.")
|
||||
unmapped_count += 1
|
||||
if unmapped_count > 0:
|
||||
logging.info(f"{unmapped_count} transactions without mappings.")
|
||||
|
||||
for mapping in mappings.values():
|
||||
assert mapping.count == 0, f"{mapping} was not used as often as expected!"
|
||||
|
||||
Reference in New Issue
Block a user