Textualize / toolong

A terminal application to view, tail, merge, and search log files (plus JSONL).

Home Page:https://www.textualize.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File names that start with a number cause a crash

tstack opened this issue · comments

Problem

File names that start with a number seem to cause a problem with the file name sorting done for the UI.

How to reproduce

Create a file that starts with a number, like 1.txt. Then, run tl with that file and another one:

tl 1.txt /var/log/system.log

I see a traceback that ends with this:

  File "/opt/homebrew/lib/python3.11/site-packages/toolong/ui.py", line 91, in __init__
    self.file_paths = self.sort_paths(file_paths)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/toolong/ui.py", line 88, in sort_paths
    return sorted(paths, key=key)
           ^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'int' and 'str'

Details

It looks like the following code is trying to do a natural sort, but doesn't handle all the cases well:

def key(path) -> list:
return [
int(token) if token.isdigit() else token.lower()
for token in path.split("/")[-1].split(".")
]

Thanks. Should be fixed in 1.1.1