Allow copying long strings to the clipboard in the diagnostics viewer (#6951)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env -S uv run --quiet --script
|
#!/usr/bin/env -S uv run --quiet --script
|
||||||
# /// script
|
# /// script
|
||||||
# dependencies = ["textual>=0.87.0"]
|
# dependencies = ["textual>=0.87.0", "pyperclip"]
|
||||||
# ///
|
# ///
|
||||||
"""
|
"""
|
||||||
WARNING: entirely vibe coded. use as a throwaway tool
|
WARNING: entirely vibe coded. use as a throwaway tool
|
||||||
@@ -17,6 +17,8 @@ import zipfile
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Any
|
from typing import Optional, Any
|
||||||
|
|
||||||
|
import pyperclip
|
||||||
|
|
||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
from textual.widgets import Header, Footer, Static, Tree, ListView, ListItem, Label, Input
|
from textual.widgets import Header, Footer, Static, Tree, ListView, ListItem, Label, Input
|
||||||
from textual.containers import Horizontal, Vertical, VerticalScroll, Container
|
from textual.containers import Horizontal, Vertical, VerticalScroll, Container
|
||||||
@@ -145,6 +147,7 @@ class TextViewerModal(ModalScreen):
|
|||||||
|
|
||||||
BINDINGS = [
|
BINDINGS = [
|
||||||
Binding("escape,q,enter", "dismiss", "Close", show=True),
|
Binding("escape,q,enter", "dismiss", "Close", show=True),
|
||||||
|
Binding("c", "copy", "Copy", show=True),
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, title: str, text: str):
|
def __init__(self, title: str, text: str):
|
||||||
@@ -158,12 +161,17 @@ class TextViewerModal(ModalScreen):
|
|||||||
yield Static(f"[bold]{self.title}[/bold]", id="modal-title")
|
yield Static(f"[bold]{self.title}[/bold]", id="modal-title")
|
||||||
with VerticalScroll(id="modal-scroll"):
|
with VerticalScroll(id="modal-scroll"):
|
||||||
yield Static(self.text, id="modal-text")
|
yield Static(self.text, id="modal-text")
|
||||||
yield Static("[dim]Press Escape, Q, or Enter to close[/dim]", id="modal-footer")
|
yield Static("[dim]Press C to copy, Escape/Q/Enter to close[/dim]", id="modal-footer")
|
||||||
|
|
||||||
def action_dismiss(self):
|
def action_dismiss(self):
|
||||||
"""Dismiss the modal."""
|
"""Dismiss the modal."""
|
||||||
self.app.pop_screen()
|
self.app.pop_screen()
|
||||||
|
|
||||||
|
def action_copy(self):
|
||||||
|
"""Copy the text to clipboard."""
|
||||||
|
pyperclip.copy(self.text)
|
||||||
|
self.notify("Copied to clipboard")
|
||||||
|
|
||||||
|
|
||||||
class SearchOverlay(Container):
|
class SearchOverlay(Container):
|
||||||
"""Search overlay widget."""
|
"""Search overlay widget."""
|
||||||
|
|||||||
Reference in New Issue
Block a user