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 18e6242
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
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
6 changes: 6 additions & 0 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 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

0 comments on commit 18e6242

Please sign in to comment.