跳转到主要内容

rime for python,连接到某些prompt-toolkit应用程序(如ptpython)的prompt-toolkit快捷键

项目描述

pyrime

readthedocs pre-commit.ci status github/workflow codecov

github/downloads github/downloads/latest github/issues github/issues-closed github/issues-pr github/issues-pr-closed github/discussions github/milestones github/forks github/stars github/watchers github/contributors github/commit-activity github/last-commit github/release-date

github/license github/languages github/languages/top github/directory-file-count github/code-size github/repo-size github/v

pypi/status pypi/v pypi/downloads pypi/format pypi/implementation pypi/pyversions

screenshot

rime for python,连接到某些prompt-toolkit应用程序(如ptpython)的prompt-toolkit快捷键。

依赖关系

# Ubuntu
sudo apt-get -y install librime-dev librime1 pkg-config
sudo apt-mark auto librime-dev pkg-config
# ArchLinux
sudo pacman -S --noconfirm librime pkg-config
# Android Termux
apt-get -y install librime pkg-config
# Nix
# use nix-shell to create a virtual environment then build
# homebrew
brew tap tonyfettes/homebrew-rime
brew install librime pkg-config
# Windows msys2
pacboy -S --noconfirm pkg-config:x librime:x gcc:x

配置

~/.config/ptpython/config.py:

from ptpython.repl import PythonRepl
from prompt_toolkit.filters import EmacsInsertMode, ViInsertMode
from prompt_toolkit.key_binding.key_processor import KeyPressEvent
from pyrime.prompt_toolkit import Rime


def configure(repl: PythonRepl) -> None:
    rime = Rime(repl)

    @repl.add_key_binding("c-^", filter=ViInsertMode())
    @repl.add_key_binding("c-^", filter=EmacsInsertMode())
    @repl.add_key_binding("c-^", filter=rime.mode())
    def _(event: KeyPressEvent) -> None:
        rime.toggle()

如果您定义了一些会干扰rime的快捷键,请尝试

    @repl.add_key_binding("c-h", filter=rime.filter(EmacsInsertMode()))
    def _(event: KeyPressEvent) -> None:
        rime.toggle()

如果您想在ViNavigationMode()中退出rime,请尝试

    @repl.add_key_binding("escape", filter=EmacsInsertMode())
    def _(event: KeyPressEvent) -> None:
        """.

        :param event:
        :type event: KeyPressEvent
        :rtype: None
        """
        event.app.editing_mode = EditingMode.VI
        event.app.vi_state.input_mode = InputMode.NAVIGATION
        rime.conditional_disable()

    # and a, I, A, ...
    @repl.add_key_binding("i", filter=ViNavigationMode())
    def _(event: KeyPressEvent) -> None:
        """.

        :param event:
        :type event: KeyPressEvent
        :rtype: None
        """
        event.app.editing_mode = EditingMode.EMACS
        event.app.vi_state.input_mode = InputMode.INSERT
        rime.conditional_enable()

它将记住rime的状态,并在重新进入ViInsertMode()EmacsInsertMode()时启用它。

此项目定义了一些实用函数。有关更多信息,请参考我的ptpython配置

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装软件包的信息。

源代码分发

pyrime-0.0.2.tar.gz (43.1 kB 查看哈希值)

上传时间: 源代码

构建的分发包

pyrime-0.0.2-cp312-cp312-manylinux_2_17_x86_64.whl (32.0 kB 查看哈希值)

上传时间: CPython 3.12 manylinux: glibc 2.17+ x86-64

pyrime-0.0.2-cp312-cp312-macosx_14_0_arm64.whl (30.0 kB 查看哈希值)

上传时间: CPython 3.12 macOS 14.0+ ARM64

pyrime-0.0.2-cp311-cp311-win_amd64.whl (61.7 kB 查看哈希值)

上传时间: CPython 3.11 Windows x86-64

由以下组织支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面