Skip to content

Commit

Permalink
fix: improved chat picker (now uses full-width of terminal)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Oct 30, 2024
1 parent ffaa109 commit 32db19d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions gptme/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,14 @@ def pick_log(limit=20) -> Path: # pragma: no cover
# return "-test-" in name or name.startswith("test-")
# prev_conv_files = [f for f in prev_conv_files if not is_test(f.parent.name)]

prev_convs = [
f"{conv.name:30s} \t{epoch_to_age(conv.modified)} \t{conv.messages:5d} msgs"
for conv in convs
]
terminal_width = os.get_terminal_size().columns

prev_convs: list[str] = []
for conv in convs:
name = conv.name
metadata = f"{epoch_to_age(conv.modified)} {conv.messages:4d} msgs"
spacing = terminal_width - len(name) - len(metadata) - 6
prev_convs.append(" ".join([name, spacing * " ", metadata]))

options = (
[
Expand Down
8 changes: 6 additions & 2 deletions gptme/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def is_generated_name(name: str) -> bool:
return name.count("-") == 2 and all(word in all_words for word in name.split("-"))


def epoch_to_age(epoch):
def epoch_to_age(epoch, incl_date=False):
# takes epoch and returns "x minutes ago", "3 hours ago", "yesterday", etc.
age = datetime.now() - datetime.fromtimestamp(epoch)
if age < timedelta(minutes=1):
Expand All @@ -125,7 +125,11 @@ def epoch_to_age(epoch):
elif age < timedelta(days=2):
return "yesterday"
else:
return f"{age.days} days ago ({datetime.fromtimestamp(epoch).strftime('%Y-%m-%d')})"
return f"{age.days} days ago" + (
" ({datetime.fromtimestamp(epoch).strftime('%Y-%m-%d')})"
if incl_date
else ""
)


def print_preview(code: str, lang: str): # pragma: no cover
Expand Down

0 comments on commit 32db19d

Please sign in to comment.