gpt4 book ai didi

iTerm2 Python API 拆分标签

转载 作者:行者123 更新时间:2023-12-05 01:36:41 26 4
gpt4 key购买 nike

使用 iTerm Python API添加在 3.3.0发布,是否可以水平拆分一个选项卡?与;

Right Click -> Split Pane Horizontally


import iterm2

async def main(connection):

# Get app
app = await iterm2.async_get_app(connection)

# current window
window = app.current_terminal_window
if window is not None:

# Create main & sub tab
main = await window.async_create_tab()
await main.async_set_title('~ MAIN ~')
sub = await window.async_create_tab()
await sub.async_set_title('~ SUB ~')

# Split sub
...


发送默认击键 ( command + d) doesn't seem possible .

最佳答案

iTerm Python API有一个 async_split_pane可以拆分 Pane 的方法:

tab = await window.async_create_tab()
session = tab.current_session
splited = await session.async_split_pane(vertical=False)

Session负责拆分一个tab。如果要拆分新创建的 Pane ,请执行以下操作:

await splited.async_activate()
await session2.async_split_pane(vertical=True)

你的例子:

#!/usr/bin/env python3.7

import iterm2


async def main(connection):

# Get app
print("Test::main")
app = await iterm2.async_get_app(connection)

# Ensure window
window = app.current_terminal_window
if app.current_terminal_window is None:
exit()

# Create main tab
main = await window.async_create_tab()
await main.async_activate()
await main.async_set_title('~ Title ~')
sess = main.current_session

# Split main
sub = await sess.async_split_pane(vertical=True)
await sub.async_send_text('whoami\n')

iterm2.run_until_complete(main)

关于iTerm2 Python API 拆分标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61740502/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com