Skip to content

Commit

Permalink
cursed-hr: Add option to toggle line prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fkglr committed Jun 6, 2023
1 parent 558c254 commit f710b1e
Showing 1 changed file with 15 additions and 8 deletions.
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

0 comments on commit f710b1e

Please sign in to comment.