Skip to content

Commit

Permalink
Added copy (yank) function on keypress 'y'
Browse files Browse the repository at this point in the history
  • Loading branch information
anorm committed Oct 25, 2024
1 parent db9a707 commit 1d7b0cb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
16 changes: 13 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ python = "^3.8"
click = "^8.1.7"
textual = "^0.58.0"
typing-extensions = "^4.9.0"
pyperclip = "^1.9.0"

[tool.poetry.group.dev.dependencies]
textual-dev = "^1.4.0"
Expand Down
3 changes: 3 additions & 0 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 Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/toolong/log_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from queue import Empty, Queue
from operator import itemgetter
import platform
import pyperclip
from threading import Event, RLock, Thread

from textual.message import Message
Expand Down Expand Up @@ -139,6 +140,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 Down Expand Up @@ -906,6 +908,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)
pyperclip.copy(line)

def watch_tail(self, tail: bool) -> None:
self.set_class(tail, "-tail")
if tail:
Expand Down

0 comments on commit 1d7b0cb

Please sign in to comment.