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 Distribution

pyrime-0.0.3.tar.gz (44.5 kB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.13 macOS 14.0+ ARM64

pyrime-0.0.3-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.3-cp311-cp311-win_amd64.whl (61.8 kB view details)

Uploaded CPython 3.11 Windows x86-64

File details

Details for the file pyrime-0.0.3.tar.gz.

File metadata

  • Download URL: pyrime-0.0.3.tar.gz
  • Upload date:
  • Size: 44.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pyrime-0.0.3.tar.gz
Algorithm Hash digest
SHA256 7bc03b9573d8113fada8e13bb877eeb38296915b9da77a3e559615661a9a397c
MD5 873de79b1dccda96be03258b6a054969
BLAKE2b-256 9c3d3358f8ea3f29078bbc462c6790e5e5cd2a2693cb45a3d0a88460a448cb43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrime-0.0.3-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 42cc9d4f72d02d729afd6fd568df2cd55e42b01678d310fadc063ef96f09345c
MD5 8147cf8396ee09384c4ef4ca429496d3
BLAKE2b-256 9d17e8208820d0b5bc939347221d4b360ade1b906752a2ff74a0928bb4922464

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrime-0.0.3-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 c035679da2eeaaf9069d382ed03d31160b89ece8bb7b24b913647b0cf79936ac
MD5 531aadcc5f72e7ba1323d3f6431e84a3
BLAKE2b-256 7951ee5218dc3513ebbcf3d1c7a18543c1c887a25beb891becc691d538599f77

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyrime-0.0.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 61.8 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.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b0904c6ebb9fb710333d152d2adad06ddc9c8332b78217ed655fadff09ee573e
MD5 f24297f2c1ac5d43ed695b2e4647d968
BLAKE2b-256 d958e7811f754c61f9834cf93c46628de20f30da4a8ecfab7744798df49b3546

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