From 059786ab66069f3ca54e248bf287496f197f4426 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 13 Nov 2019 10:38:58 +0530 Subject: [PATCH] Implement piping for launch --- kitty/boss.py | 4 ++-- kitty/launch.py | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index 6e2454dd5..026b9aa0f 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -58,9 +58,9 @@ def data_for_at(w, arg, add_wrap_markers=False): if arg == '@selection': return w.text_for_selection() - if arg == '@ansi': + if arg == '@ansi' or '@ansi_screen_scrollback': return as_text(as_ansi=True, add_history=True) - if arg == '@text': + if arg == '@text' or arg == '@screen_scrollback': return as_text(add_history=True) if arg == '@screen': return as_text() diff --git a/kitty/launch.py b/kitty/launch.py index a49622973..c47566b66 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -76,6 +76,33 @@ control kitty. It can, however, be useful to block programs running on other computers (for example, over ssh) or as other users. +--stdin-source +type=choices +default=none +choices=none,@selection,@screen,@screen_scrollback,@alternate,@alternate_scrollback +Pass the screen contents as :code:`STDIN` to the child process. @selection is +the currently selected text. @screen is the contents of the currently active +window. @screen_scrollback is the same as @screen, but includes the scrollback +buffer as well. @alternate is the secondary screen of the current active +window. For example if you run a full screen terminal application, the +secondary screen will be the screen you return to when quitting the +application. + + +--stdin-add-formatting +type=bool-set +When using :code:`--stdin-source` add formatting escape codes, without this +only plain text will be sent. + + +--stdin-add-line-wrap-markers +type=bool-set +When using :code:`--stdin-source` add a carriage return at every line wrap +location (where long lines are wrapped at screen edges). This is useful if you +want to pipe to program that wants to duplicate the screen layout of the +screen. + + ''' options_spec.ans = OPTIONS return options_spec.ans @@ -117,8 +144,8 @@ def launch(boss, opts, args): tab = boss.active_tab active = boss.active_window_for_cwd active_child = getattr(active, 'child', None) + env = get_env(opts, active_child) kw = { - 'env': get_env(opts, active_child) or None, 'allow_remote_control': opts.allow_remote_control } if opts.cwd: @@ -140,5 +167,14 @@ def launch(boss, opts, args): kw['cmd'] = cmd if opts.type == 'overlay' and active and not active.overlay_window_id: kw['overlay_for'] = active.id + if opts.stdin_source: + q = opts.stdin_source + if opts.stdin_add_line_wrap_markers: + q += '_wrap' + penv, stdin = boss.process_stdin_source(window=active, stdin=q) + if stdin: + kw['stdin'] = stdin + if penv: + env.update(penv) - return tab.new_window(**kw) + return tab.new_window(env=env or None, **kw)