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.4.tar.gz (44.6 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.4-cp312-cp312-win_amd64.whl (59.9 kB view details)

Uploaded CPython 3.12Windows x86-64

pyrime-0.0.4-cp312-cp312-manylinux_2_17_x86_64.whl (30.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: pyrime-0.0.4.tar.gz
  • Upload date:
  • Size: 44.6 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.4.tar.gz
Algorithm Hash digest
SHA256 6562cba05dec479b8eaf42078fe4c04bb658730f5bb2c9fea8e54bdee6746fb0
MD5 634dba802886032dac1e8784d83bb8ff
BLAKE2b-256 64d0c6b375deb5feec81061c1c27f7e73f9bc5af9e06310b9ac7d5440ed978d8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyrime-0.0.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 59.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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8b0a82715e46442b0f12e553323cf8408fea0cf1f3377b72dfa4108d5dcb14b4
MD5 4ecfbc77beea9e2014c5660c5b76ed2c
BLAKE2b-256 0331378bde7ecc331162f4a12137c351f2130eb74bd23590758759d8137d9317

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrime-0.0.4-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 793b2ccd01b0ebefec518bad7d96077ae6b95adcc75c4f31210a9a2752bba03d
MD5 6378461261429560aa5c1f20f49a9c4b
BLAKE2b-256 535a377e005be4f8dda0931c79afc9135163de65f7574b139a6bf6d201ef362a

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