Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cursed-hr: Add option to toggle line prefixes #402

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/cursed_hr/cursed_hr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import shutil
import tempfile
import warnings
from argparse import ArgumentParser
from argparse import ArgumentParser, BooleanOptionalAction
from array import array
from binascii import unhexlify
from copy import deepcopy
Expand Down Expand Up @@ -169,6 +169,7 @@ def __init__(
in_file: Path,
priority: PenlogPriority = PenlogPriority.DEBUG,
filters: list[str] | None = None,
use_prefix: bool = True,
):
self.in_file = in_file
self.level_pointers: list[array[int]] = [array("L") for _ in range(9)]
Expand All @@ -181,6 +182,7 @@ def __init__(
)
]
self.configuration_index = 0
self.use_prefix = use_prefix

try:
self.window = self.init_curses()
Expand Down Expand Up @@ -482,12 +484,14 @@ def formatted_entry(self, entry_id: int) -> list[DisplayEntry]:
_, max_width = self.window.getmaxyx()

prefix = ""
prefix += entry.datetime.strftime("%b %d %H:%M:%S.%f")[:-3]
prefix += " "
prefix += entry.module
if entry.tags is not None:
prefix += f" [{', '.join(entry.tags)}]"
prefix += ": "

if self.use_prefix:
prefix += entry.datetime.strftime("%b %d %H:%M:%S.%f")[:-3]
prefix += " "
prefix += entry.module
if entry.tags is not None:
prefix += f" [{', '.join(entry.tags)}]"
prefix += ": "

residual_width = max_width - len(prefix) - 1

Expand Down Expand Up @@ -1214,6 +1218,8 @@ def line_up() -> None:
self.window.move(
max_lines, min(filter_cursor, len(fh_tmp[fh_index]))
)
case "x":
self.use_prefix = not self.use_prefix

display_entries = self.calculate_display_entries(entry_start, line_start)

Expand Down Expand Up @@ -1331,8 +1337,9 @@ def main() -> None:
"--priority", "-p", type=PenlogPriority.from_str, default=PenlogPriority.DEBUG
)
parser.add_argument("--filter", "-f", type=parse_filter, default=None)
parser.add_argument("--prefix", action=BooleanOptionalAction, default=True)
args = parser.parse_args()
CursedHR(args.file, args.priority, args.filter)
CursedHR(args.file, args.priority, args.filter, args.prefix)


if __name__ == "__main__":
Expand Down