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

Added copy (yank) function #62

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

A terminal application to view, tail, merge, and search log files (plus JSONL).

<details>
<details>
<summary> 🎬 Viewing a single file </summary>

&nbsp;

<div align="center">
Expand All @@ -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?

Expand Down Expand Up @@ -72,30 +72,30 @@ It is snappy, straightforward to use, and does a lot of the *grunt work* for you

### Videos

<details>
<details>
<summary> 🎬 Merging multiple (compressed) files </summary>
&nbsp;

<div align="center">
<video src="https://github.com/Textualize/tailless/assets/554369/efbbde11-bebf-44ff-8d2b-72a84b542b75" />
</div>


</details>

<details>
<details>
<summary> 🎬 Viewing JSONL files </summary>
&nbsp;

<div align="center">
<video src="https://github.com/Textualize/tailless/assets/554369/38936600-34ee-4fe1-9fd3-b1581fc3fa37" />
</div>



</details>

<details>
<details>
<summary> 🎬 Live Tailing a file </summary>
&nbsp;

Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/toolong/find_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
Expand Down Expand Up @@ -55,7 +55,7 @@ class FindDialog(Widget, can_focus_children=True):
display: none;
}
}
}
}
"""
BINDINGS = [
Binding("escape", "dismiss_find", "Dismiss", key_display="esc", show=False),
Expand Down
21 changes: 12 additions & 9 deletions src/toolong/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -62,7 +63,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
Expand All @@ -72,9 +73,11 @@
### 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 `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.
Expand All @@ -98,9 +101,9 @@
"""

TITLE = rf"""
_______ _
_______ _
|__ __| | | Built with Textual
| | ___ ___ | | ___ _ __ __ _
| | ___ ___ | | ___ _ __ __ _
| |/ _ \ / _ \| | / _ \| '_ \ / _` |
| | (_) | (_) | |___| (_) | | | | (_| |
|_|\___/ \___/|______\___/|_| |_|\__, |
Expand Down Expand Up @@ -138,21 +141,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 = [
Expand Down
14 changes: 7 additions & 7 deletions src/toolong/line_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
"""

Expand Down Expand Up @@ -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;
Expand Down
16 changes: 11 additions & 5 deletions src/toolong/log_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')"),
Expand All @@ -151,7 +152,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;
Expand All @@ -164,19 +165,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 = {
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 11 additions & 11 deletions src/toolong/log_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -54,7 +54,7 @@ class InfoOverlay(Widget):
width: 1fr;
align: center bottom;
}

InfoOverlay Label {
visibility: visible;
width: auto;
Expand Down Expand Up @@ -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;
}
}
"""
Expand Down Expand Up @@ -148,9 +148,9 @@ class LogFooter(Widget):
dock: bottom;
Horizontal {
width: 1fr;
height: 1;
height: 1;
}

.key {
color: $warning;
}
Expand All @@ -161,7 +161,7 @@ class LogFooter(Widget):
color: $success;
padding: 0 1 0 0;
}

.tail {
padding: 0 1;
margin: 0 1;
Expand Down Expand Up @@ -264,11 +264,11 @@ class LogView(Horizontal):
}
}
LogLines {
width: 1fr;
}
width: 1fr;
}
LinePanel {
width: 50%;
display: none;
display: none;
}
}
"""
Expand Down
8 changes: 4 additions & 4 deletions src/toolong/scan_progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/toolong/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down