Skip to main content

rime for python, attached to prompt-toolkit keybindings for some prompt-toolkit applications such as ptpython

Project description

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

aur/votes aur/popularity aur/maintainer aur/last-modified aur/version

screenshot

rime for python, attached to prompt-toolkit keybindings for some prompt-toolkit applications such as ptpython.

Dependence

# 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 librime gcc

Configure

~/.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()

If you defined some key bindings which will disturb rime, try:

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

If you want to exit rime in ViNavigationMode(), try:

    @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()

It will remember rime status and enable it when reenter ViInsertMode() or EmacsInsertMode().

Some utility functions are defined in this project. Refer my ptpython config to know more.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

pyrime-0.0.0-cp313-cp313-macosx_14_0_arm64.whl (30.1 kB view details)

Uploaded CPython 3.13 macOS 14.0+ ARM64

pyrime-0.0.0-cp312-cp312-manylinux_2_17_x86_64.whl (32.2 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pyrime-0.0.0-cp311-cp311-win_amd64.whl (61.6 kB view details)

Uploaded CPython 3.11 Windows x86-64

File details

Details for the file pyrime-0.0.0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pyrime-0.0.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a7341666ce0b8fbf8546b7b534683e7f2ba6670421569e23aecc1df0f2864471
MD5 ebe254e966bccf14659e5fdb6e91d3a7
BLAKE2b-256 2f6823d9f59fa9c49baf9c65df513f289d9caf75193002eb367c84eecdc38931

See more details on using hashes here.

File details

Details for the file pyrime-0.0.0-cp312-cp312-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pyrime-0.0.0-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 89720516bde7c6cba28869654540d074638c3af938bab39f92d88a3cd7a060b8
MD5 b6f1fe6a6b89c00cb6cb0e26809e306e
BLAKE2b-256 8023a1322282dab1a1c6dcaf9020afaf7a177156e8d3fd259d56be45cb466d2d

See more details on using hashes here.

File details

Details for the file pyrime-0.0.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pyrime-0.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 61.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pyrime-0.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f826b453540573b7ea2808f349bd5d1d1eb7b735d27b502956c0e2cf25db9d16
MD5 c23121b5837a0114560846ea9f67e876
BLAKE2b-256 13c46f141e16e4202162eb68ec1fb8fa9bae943cf29ff0ffde694664fdb8721f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page