内容简介:iTerm2 的文档页面显示,其最新测试版增加了 Python API。具体来说就是,iTerm2 提供了一个 Python 包,通过它我们可以轻松编写控制 iTerm2 并扩展其行为的 Python 脚本。 当然,该功能目前尚处于 Beta 阶段,API...
iTerm2 的文档页面显示,其最新测试版增加了 Python API。具体来说就是,iTerm2 提供了一个 Python 包,通过它我们可以轻松编写控制 iTerm2 并扩展其行为的 Python 脚本。
当然,该功能目前尚处于 Beta 阶段,API 可能偶尔会发生变化。
#!/usr/bin/env python3
import asyncio
import iterm2
async def main(connection):
app = await iterm2.async_get_app(connection)
keycodes = [ iterm2.Keycode.F1,
iterm2.Keycode.F2,
iterm2.Keycode.F3,
iterm2.Keycode.F4,
iterm2.Keycode.F5,
iterm2.Keycode.F6,
iterm2.Keycode.F7,
iterm2.Keycode.F8,
iterm2.Keycode.F9,
iterm2.Keycode.F10,
iterm2.Keycode.F11,
iterm2.Keycode.F12 ]
async def keystroke_handler(connection, keystroke):
if keystroke.modifiers == [ iterm2.Modifier.FUNCTION ]:
try:
fkey = keycodes.index(keystroke.keycode)
if fkey >= 0 and fkey < len(app.current_terminal_window.tabs):
await app.current_terminal_window.tabs[fkey].async_select()
except:
pass
pattern = iterm2.KeystrokePattern()
pattern.forbidden_modifiers.extend([iterm2.Modifier.CONTROL,
iterm2.Modifier.OPTION,
iterm2.Modifier.COMMAND,
iterm2.Modifier.SHIFT,
iterm2.Modifier.NUMPAD])
pattern.required_modifiers.extend([iterm2.Modifier.FUNCTION])
pattern.keycodes.extend(keycodes)
async def monitor():
async with iterm2.KeystrokeMonitor(connection) as mon:
while True:
keystroke = await mon.async_get()
await keystroke_handler(connection, keystroke)
# Run the monitor in the background
asyncio.create_task(monitor())
# Block regular handling of function keys
filter = iterm2.KeystrokeFilter(connection, [pattern])
async with filter as mon:
await iterm2.async_wait_forever()
iterm2.run_forever(main)
使用该脚本,我们可以通过按下功能键来选择选项卡。F1 表示选择第一个选项卡,F2 表示选择第二个选项卡等。>>> 脚本下载
官方还提供了关于该功能的教程,包含了编写脚本的详细指南,并描述了 iTerm2 脚本系统的架构。
iTerm2 是 iTerm 的后继者,也是 Terminal 的替代者。这是一款用于 macOS 的终端模拟器,支持窗口分割、热键、搜索、自动补齐、无鼠标复制、历史粘贴、即时重播等功能特性,适用于 macOS 10.10 及以上版本。
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 终端复用神器Tmux
- iTerm2 3.3.0 发布,Mac 终端神器
- 终端依赖者福利:终端也能实现翻译功能了
- 程序员必备之终端模拟器,让你的终端世界多一抹“颜色”
- 程序员必备之终端模拟器,让你的终端世界多一抹 “颜色”
- 漫淡终端技术未来
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Numerical Methods and Methods of Approximation in Science and En
Karan Surana / CRC Press / 2018-10-31
ABOUT THIS BOOK Numerical Methods and Methods of Approximation in Science and Engineering prepares students and other readers for advanced studies involving applied numerical and computational anal......一起来看看 《Numerical Methods and Methods of Approximation in Science and En》 这本书的介绍吧!