-
from textual import on, work
from textual.app import App, ComposeResult, events
from textual.widgets import *
from textual.binding import Binding
class ScriptApp(App):
BINDINGS = [
Binding("ctrl+insert", "copy_to_clipboard"),
Binding("ctrl+p", "print"),
]
def compose(self) -> ComposeResult:
yield Output()
@work(exclusive=True, thread=True)
def action_copy_to_clipboard(self) -> None:
self.query_one(Output).begin_capture_print()
print("Copy to clipboard...")
@work(exclusive=True, thread=True)
def action_print(self) -> None:
self.query_one(Output).begin_capture_print()
print("Ctrl + p...")
class Output(RichLog):
def __init__(self) -> None:
super().__init__(highlight=True, markup=True)
@on(events.Print)
def on_print(self, event: events.Print) -> None:
if event.text.strip():
self.write(event.text)
app = ScriptApp()
if __name__ == "__main__":
app.run() Run this app, the ctrl + insert binding doesn't work but ctrl + p works. |
Beta Was this translation helpful? Give feedback.
Answered by
davep
Jan 20, 2024
Replies: 1 comment 10 replies
-
Please see this FAQ. |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In my experience the insert key, and modified forms of it, are not fully-supported across the multitude of terminal emulators that are available. For example, here is insert, shift+insert and ctrl+insert as recorded under rio:
This isn't because of anything Textual is doing; this is because of what rio sends.
The advice given in the FAQ is there for the reason it states: not all key combinations will work under all terminal emulators, because of how those terminal emulators work (and sometimes because the keys are special to the host operating system).