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.6.tar.gz (42.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyrime-0.0.6-cp313-cp313-macosx_14_0_arm64.whl (54.9 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

pyrime-0.0.6-cp312-cp312-win_amd64.whl (101.9 kB view details)

Uploaded CPython 3.12Windows x86-64

pyrime-0.0.6-cp312-cp312-manylinux_2_17_x86_64.whl (73.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: pyrime-0.0.6.tar.gz
  • Upload date:
  • Size: 42.7 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.6.tar.gz
Algorithm Hash digest
SHA256 340ac45eefd7d6f518f2fa3bfb08ee4739ee11fcbc098fc721e6694705e01e95
MD5 ac92449b65a910760e0bd81a4a5be42f
BLAKE2b-256 4cd9430155d56c61283c24819fcb7542439fc6d4f5ceedbbd51b46114de763ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrime-0.0.6-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 070d0704d494bf356867ea1a0481559738a40e7eeaa2058b2814b3ae51ab625d
MD5 4537b39c4a2ca50df103a919616b6083
BLAKE2b-256 59a9182a71ab9fe70e4e2979b10141b7f0da5a87e9734af4845b67ecbc88bd9c

See more details on using hashes here.

File details

Details for the file pyrime-0.0.6-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pyrime-0.0.6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 101.9 kB
  • Tags: CPython 3.12, 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.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a376f0f4df842f455e3bbc4fd5a512eb80ca0ebc86b7f94df4c9d139af32d771
MD5 baa0910f2d742766aaf5923a7723a05b
BLAKE2b-256 49f8f93ba21f789f3a35512c693402da3bff856691bfcd8f5c260c4041eb4b97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrime-0.0.6-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 1d2d52cbed4e3afb7d33f2ec9d555d7b82525303a8bbfb03600f49fe3c10f6e1
MD5 69fe72c89801b97d50751156fe577b15
BLAKE2b-256 716a21053753d44b2889d85b12a7c90e3c5c198ef00fd0eef897a4a77a66d44e

See more details on using hashes here.

Supported by

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