Skip to content

Commit

Permalink
#18 split --bare flag into 3 flags
Browse files Browse the repository at this point in the history
  • Loading branch information
epogrebnyak committed Mar 4, 2024
1 parent 38fc86f commit 1b35eca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ justpath
Same as above, but no line numbers, no comments, no color, just bare text.

```console
justpath --bare --no-color
justpath --bare
```

Show directories from PATH in alphabetic order[^1]:
Expand Down Expand Up @@ -102,7 +102,7 @@ What is the `PATH` without invalid paths and duplicates?
justpath --purge-invalid --purge-duplicates
```

More concise:
Same as above, but more concise:

```console
justpath --correct
Expand Down
28 changes: 10 additions & 18 deletions justpath/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def max_digits(self) -> int:
"""Number of digits in a line number, usually 1 or 2."""
return len(str(max(self.keys()))) if self.keys() else 0

def offset(self, i: int):
return str(i).rjust(self.max_digits)

def to_rows(self, follow_symlinks: bool) -> list["Row"]:
getter = resolve if follow_symlinks else as_is
counter = Counter([getter(path) for path in self.values()])
Expand Down Expand Up @@ -168,7 +171,13 @@ def show(
print(dumps(paths, indent=2))
else:
for row in rows:
print_row2(row, color, comments, numbers, path_var.max_digits)
items = [
get_color(row) if color else "",
path_var.offset(row.i) if numbers else "",
str(row.path),
get_comment(row) if comments else "",
]
print("".join(item for item in items if item))
if color:
print(Style.RESET_ALL, end="")

Expand Down Expand Up @@ -228,23 +237,6 @@ def get_comment(row: Row) -> str:
return ""


def print_row2(row: Row, color: bool, comments: bool, numbers: bool, max_digits: int):
color_modifier = get_color(row) if color else ""
comment_text = (" " + get_comment(row)) if comments else ""
line_number_text = (str(row.i).rjust(max_digits) + " ") if numbers else ""
print("".join([color_modifier,
line_number_text,
str(row.path),
comment_text]))



def print_row(row: Row, color: bool, n: int):
modifier = get_color(row) if color else ""
comment = get_comment(row)
print(modifier + str(row.i).rjust(n), str(row.path), comment)


def remove_duplicates(rows, follow_symlinks):
seen = set()
result = []
Expand Down
1 change: 1 addition & 0 deletions tests/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
["--shell-equivalents"],
["--raw"],
["--count"],
"--no-numbers --no-comments --no-color".split(),
["--bare"],
["--sort", "--includes", "mingw", "--excludes", "tools"],
["--invalid"],
Expand Down

0 comments on commit 1b35eca

Please sign in to comment.