Skip to content

Commit

Permalink
added sort by line length functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenZcience committed Feb 22, 2024
1 parent 71c444e commit 72e238c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cat_win/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,8 @@ def edit_content(content: list, show_bytecode: bool, file_index: int = 0,
elif arg == ARGS_REVERSE:
content.reverse()
elif arg == ARGS_SORT:
content.sort(key = lambda l: l[1].casefold())
sort_method = len if param.isupper() else str.casefold
content.sort(key = lambda l: sort_method(l[1]))
elif arg == ARGS_BLANK:
content = [c for c in content if c[1]]
elif arg == ARGS_EVAL:
Expand Down
2 changes: 1 addition & 1 deletion cat_win/const/argconstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, short_form: str, long_form: str, arg_help: str, arg_id: int,
ARGS_REVERSE, show_arg_on_shell=False, section=3),
ArgConstant('-u', '--unique', 'suppress repeated output lines',
ARGS_SQUEEZE, show_arg_on_shell=False, section=3),
ArgConstant('--sort', '--sort', 'sort all lines alphabetically',
ArgConstant('--sort', '--SORT', 'sort all lines alphabetically or by length',
ARGS_SORT, show_arg_on_shell=False, section=3),
ArgConstant('--sf', '--specific-format', 'automatically format specific file types',
ARGS_SPECIFIC_FORMATS, show_arg_on_shell=False, section=3),
Expand Down
2 changes: 1 addition & 1 deletion cat_win/util/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def check_unknown_args(self, shell_arg: bool = False) -> list:
# print(leven_short.__round__(3), leven_long.__round__(3),
# max(leven_short, leven_long).__round__(3), u_arg, arg.long_form, sep="\t") # DEBUG
if max(leven_short, leven_long) > self.SIMILARITY_LIMIT:
if leven_short > leven_long:
if leven_short >= leven_long:
possible_arg_replacement[1].append((arg.short_form, leven_short))
else:
possible_arg_replacement[1].append((arg.long_form, leven_long))
Expand Down

0 comments on commit 72e238c

Please sign in to comment.