From db9a707dda1faa841b7c8757f71786ca778bb4d3 Mon Sep 17 00:00:00 2001 From: Anders Norman Date: Fri, 25 Oct 2024 18:14:39 +0200 Subject: [PATCH 1/2] Cleanup (trailing whitespace) --- README.md | 22 +++++++++++----------- src/toolong/find_dialog.py | 6 +++--- src/toolong/help.py | 18 +++++++++--------- src/toolong/line_panel.py | 14 +++++++------- src/toolong/log_lines.py | 10 +++++----- src/toolong/log_view.py | 22 +++++++++++----------- src/toolong/scan_progress_bar.py | 8 ++++---- src/toolong/ui.py | 4 ++-- 8 files changed, 52 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 9221e29..7b68ad2 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ A terminal application to view, tail, merge, and search log files (plus JSONL). -
+
🎬 Viewing a single file - +  
@@ -36,7 +36,7 @@ See [Toolong on Calmcode.io](https://calmcode.io/shorts/toolong.py) for a calmin - Support for JSONL files: lines are pretty printed. - Opens .bz and .bz2 files automatically. - Merges log files by auto detecting timestamps. - + ## Why? @@ -72,30 +72,30 @@ It is snappy, straightforward to use, and does a lot of the *grunt work* for you ### Videos -
+
🎬 Merging multiple (compressed) files  
- +
-
+
🎬 Viewing JSONL files  
- - + +
-
+
🎬 Live Tailing a file   @@ -120,7 +120,7 @@ You could also install Toolong with Pip: pip install toolong ``` -> [!NOTE] +> [!NOTE] > If you use pip, you should ideally create a virtual environment to avoid potential dependancy conflicts. However you install Toolong, the `tl` command will be added to your path: @@ -167,7 +167,7 @@ tree / | tl This [guy](https://github.com/willmcgugan). An ex web developer who somehow makes a living writing terminal apps. - + --- ## History diff --git a/src/toolong/find_dialog.py b/src/toolong/find_dialog.py index 2189363..107dded 100644 --- a/src/toolong/find_dialog.py +++ b/src/toolong/find_dialog.py @@ -26,8 +26,8 @@ class FindDialog(Widget, can_focus_children=True): DEFAULT_CSS = """ FindDialog { layout: horizontal; - dock: top; - padding-top: 1; + dock: top; + padding-top: 1; width: 1fr; height: auto; max-height: 70%; @@ -55,7 +55,7 @@ class FindDialog(Widget, can_focus_children=True): display: none; } } - } + } """ BINDINGS = [ Binding("escape", "dismiss_find", "Dismiss", key_display="esc", show=False), diff --git a/src/toolong/help.py b/src/toolong/help.py index 068959d..95c59d4 100644 --- a/src/toolong/help.py +++ b/src/toolong/help.py @@ -62,7 +62,7 @@ #### Merging files -Multiple files will open in tabs. +Multiple files will open in tabs. If you add the `--merge` switch, TooLong will merge all the log files based on their timestamps: ```bash @@ -72,7 +72,7 @@ ### Pointer mode Pointer mode lets you navigate by line. -To enter pointer mode, press `enter` or click a line. +To enter pointer mode, press `enter` or click a line. When in pointer mode, the navigation keys will move this pointer rather than scroll the log file. Press `enter` again or click the line a second time to expand the line in to a new panel. @@ -98,9 +98,9 @@ """ TITLE = rf""" - _______ _ + _______ _ |__ __| | | Built with Textual - | | ___ ___ | | ___ _ __ __ _ + | | ___ ___ | | ___ _ __ __ _ | |/ _ \ / _ \| | / _ \| '_ \ / _` | | | (_) | (_) | |___| (_) | | | | (_| | |_|\___/ \___/|______\___/|_| |_|\__, | @@ -138,21 +138,21 @@ class HelpScreen(ModalScreen): CSS = """ HelpScreen VerticalScroll { background: $surface; - margin: 4 8; - border: heavy $accent; - height: 1fr; + margin: 4 8; + border: heavy $accent; + height: 1fr; .title { width: auto; } scrollbar-gutter: stable; Markdown { margin:0 2; - } + } Markdown .code_inline { background: $primary-darken-1; text-style: bold; } - } + } """ BINDINGS = [ diff --git a/src/toolong/line_panel.py b/src/toolong/line_panel.py index 1eb2fae..f8f012b 100644 --- a/src/toolong/line_panel.py +++ b/src/toolong/line_panel.py @@ -14,20 +14,20 @@ class LineDisplay(Widget): DEFAULT_CSS = """ - LineDisplay { + LineDisplay { padding: 0 1; margin: 1 0; width: auto; - height: auto; + height: auto; Label { width: 1fr; - } + } .json { - width: auto; + width: auto; } .nl { width: auto; - } + } } """ @@ -57,10 +57,10 @@ def compose(self) -> ComposeResult: class LinePanel(ScrollableContainer): DEFAULT_CSS = """ LinePanel { - background: $panel; + background: $panel; overflow-y: auto; overflow-x: auto; - border: blank transparent; + border: blank transparent; scrollbar-gutter: stable; &:focus { border: heavy $accent; diff --git a/src/toolong/log_lines.py b/src/toolong/log_lines.py index 7354ddc..22f8906 100644 --- a/src/toolong/log_lines.py +++ b/src/toolong/log_lines.py @@ -151,7 +151,7 @@ class LogLines(ScrollView, inherit_bindings=False): LogLines { scrollbar-gutter: stable; overflow: scroll; - border: heavy transparent; + border: heavy transparent; .loglines--filter-highlight { background: $secondary; color: auto; @@ -164,19 +164,19 @@ class LogLines(ScrollView, inherit_bindings=False): } border-subtitle-color: $success; - border-subtitle-align: center; + border-subtitle-align: center; align: center middle; &.-scanning { tint: $background 30%; } .loglines--line-numbers { - color: $warning 70%; + color: $warning 70%; } .loglines--line-numbers-active { - color: $warning; + color: $warning; text-style: bold; - } + } } """ COMPONENT_CLASSES = { diff --git a/src/toolong/log_view.py b/src/toolong/log_view.py index e8ec302..c30547d 100644 --- a/src/toolong/log_view.py +++ b/src/toolong/log_view.py @@ -42,10 +42,10 @@ class InfoOverlay(Widget): DEFAULT_CSS = """ InfoOverlay { display: none; - dock: bottom; + dock: bottom; layer: overlay; width: 1fr; - visibility: hidden; + visibility: hidden; offset-y: -1; text-style: bold; } @@ -54,7 +54,7 @@ class InfoOverlay(Widget): width: 1fr; align: center bottom; } - + InfoOverlay Label { visibility: visible; width: auto; @@ -101,9 +101,9 @@ class FooterKey(Label): &:light { color: $primary; } - padding: 0 1 0 0; + padding: 0 1 0 0; &:hover { - text-style: bold underline; + text-style: bold underline; } } """ @@ -148,9 +148,9 @@ class LogFooter(Widget): dock: bottom; Horizontal { width: 1fr; - height: 1; + height: 1; } - + .key { color: $warning; } @@ -161,7 +161,7 @@ class LogFooter(Widget): color: $success; padding: 0 1 0 0; } - + .tail { padding: 0 1; margin: 0 1; @@ -264,11 +264,11 @@ class LogView(Horizontal): } } LogLines { - width: 1fr; - } + width: 1fr; + } LinePanel { width: 50%; - display: none; + display: none; } } """ diff --git a/src/toolong/scan_progress_bar.py b/src/toolong/scan_progress_bar.py index 2fb8773..768ea3a 100644 --- a/src/toolong/scan_progress_bar.py +++ b/src/toolong/scan_progress_bar.py @@ -11,16 +11,16 @@ class ScanProgressBar(Vertical): width: 100%; height: auto; margin: 2 4; - dock: top; + dock: top; padding: 1 2; - background: $primary; + background: $primary; display: block; text-align: center; display: none; - align: center top; + align: center top; ProgressBar { margin: 1 0; - } + } } LogLines:focus ScanProgressBar.-has-content { diff --git a/src/toolong/ui.py b/src/toolong/ui.py index c14c33e..f1b24cd 100644 --- a/src/toolong/ui.py +++ b/src/toolong/ui.py @@ -28,12 +28,12 @@ class LogScreen(Screen): CSS = """ LogScreen { layers: overlay; - & TabPane { + & TabPane { padding: 0; } & Tabs:focus Underline > .underline--bar { color: $accent; - } + } Underline > .underline--bar { color: $panel; } From 18e6242a908ae47dea5261e72d68df0ad2481eb2 Mon Sep 17 00:00:00 2001 From: Anders Norman Date: Fri, 25 Oct 2024 19:20:20 +0200 Subject: [PATCH 2/2] Added copy (yank) function on keypress 'y' --- src/toolong/help.py | 3 +++ src/toolong/log_lines.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/toolong/help.py b/src/toolong/help.py index 95c59d4..ef1241b 100644 --- a/src/toolong/help.py +++ b/src/toolong/help.py @@ -41,6 +41,7 @@ - `ctrl+l` Toggle line numbers. - `ctrl+t` Tail current file. - `ctrl+c` Exit the app. +- `y` Copy (yank) current line in pointer mode ### Opening Files @@ -75,6 +76,8 @@ To enter pointer mode, press `enter` or click a line. When in pointer mode, the navigation keys will move this pointer rather than scroll the log file. +Press `y` to copy (yank) the current line to the system clipboard. + Press `enter` again or click the line a second time to expand the line in to a new panel. Press `escape` to hide the line panel if it is visible, or to leave pointer mode if the line panel is not visible. diff --git a/src/toolong/log_lines.py b/src/toolong/log_lines.py index 22f8906..91e2bb9 100644 --- a/src/toolong/log_lines.py +++ b/src/toolong/log_lines.py @@ -139,6 +139,7 @@ class LogLines(ScrollView, inherit_bindings=False): Binding("pagedown,space", "page_down", "Page Down", show=False), Binding("enter", "select", "Select line", show=False), Binding("escape", "dismiss", "Dismiss", show=False, priority=True), + Binding("y", "copy", "Copy (yank) current selection", show=False, priority=True), Binding("m", "navigate(+1, 'm')"), Binding("M", "navigate(-1, 'm')"), Binding("o", "navigate(+1, 'h')"), @@ -906,6 +907,11 @@ def action_navigate(self, steps: int, unit: Literal["m", "h", "d"]) -> None: self.pointer_line = line_no self.scroll_pointer_to_center(animate=abs(initial_line_no - line_no) < 100) + def action_copy(self, **argv): + if self.pointer_line: + line = self.get_line_from_index(self.pointer_line) + self.app.copy_to_clipboard(line) + def watch_tail(self, tail: bool) -> None: self.set_class(tail, "-tail") if tail: