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

question: send keypress to all windows/OS windows #1569

Closed
minusf opened this issue Apr 25, 2019 · 7 comments
Closed

question: send keypress to all windows/OS windows #1569

minusf opened this issue Apr 25, 2019 · 7 comments

Comments

@minusf
Copy link

minusf commented Apr 25, 2019

Is there a way to have synchronous typing in all kitty windows/OS windows
like tmux's :setw synchronize-panes?

@kovidgoyal
Copy link
Owner

Yes, the remote control feature can be used to do that
https://sw.kovidgoyal.net/kitty/remote-control.html

@rjcoelho
Copy link

@kovidgoyal can you provide an example on how to toggle window sync across all windows in a given tab using remote control ?

@kovidgoyal
Copy link
Owner

It would require writing some small terminal program that reads keypresses and then sends those keypresses to all kitty windows using kitty @ send-text. Simply run that program in one window, then anything you type there will be sent to all windows by the program. I'm afraid I dont have time to write the program for you, but it should be pretty simple to do. In python pseudo code:

set stdin to unbuffered using the tty module
while True:
    bytes = sys.stdin.buffer.read(1)
    subprocess.run(['kitty', '@', 'send-text', '--match-tab', 'the tab you want matched', '--stdin'], stdin=bytes)

And if you want to get more sophisticated you can write it as a kitten and avoid needing to use remote control at all.

@rjcoelho
Copy link

Thanks, I'll try to come up with a PR for docs, if that makes sense for you.

@kovidgoyal
Copy link
Owner

sure

@aorith
Copy link

aorith commented Nov 30, 2020

I'm using this simple kitten:

from sys import exit

def main(args):
    # this is the main entry point of the kitten, it will be executed in
    # the overlay window when the kitten is launched
    print("Send to all windows in this Tab.\n")
    try:
        answer = input("> ")
    except KeyboardInterrupt:
        print("Cancelled.")
        exit(0)
    # whatever this function returns will be available in the
    # handle_result() function
    return answer


def handle_result(args, answer, target_window_id, boss):
    tab = boss.active_tab
    windows_dict = tab.list_windows(target_window_id)
    for w_dict in windows_dict:
        w = boss.window_id_map.get(w_dict.get("id"))
        if w is not None:
            #w.paste_bytes(answer + "\x0d")
            w.paste(answer + "\r")

map f2 kitten kittens/broadcast_to_current_tab.py
Press F2, write a command and press ENTER. It will send the command to all the windows in current tab.

Still, it feels like a bad hack and you can only send one command at a time, it doesn't stream the chars as you type them like in tmux implementation. I tried to do it by using yield but failed...

@kovidgoyal kovidgoyal reopened this Dec 1, 2020
@kovidgoyal
Copy link
Owner

I had a little time, so I implemented the kitten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants