pyrime


Namepyrime JSON
Version 0.0.7 PyPI version JSON
download
home_pageNone
Summaryrime for python, attached to prompt-toolkit keybindings for some prompt-toolkit applications such as ptpython
upload_time2024-12-03 07:37:05
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseGPL v3
keywords rime ptpython prompt-toolkit
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyrime

[![readthedocs](https://shields.io/readthedocs/pyrime)](https://pyrime.readthedocs.io)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/Freed-Wu/pyrime/main.svg)](https://results.pre-commit.ci/latest/github/Freed-Wu/pyrime/main)
[![github/workflow](https://github.com/Freed-Wu/pyrime/actions/workflows/main.yml/badge.svg)](https://github.com/Freed-Wu/pyrime/actions)
[![codecov](https://codecov.io/gh/Freed-Wu/pyrime/branch/main/graph/badge.svg)](https://codecov.io/gh/Freed-Wu/pyrime)

[![github/downloads](https://shields.io/github/downloads/Freed-Wu/pyrime/total)](https://github.com/Freed-Wu/pyrime/releases)
[![github/downloads/latest](https://shields.io/github/downloads/Freed-Wu/pyrime/latest/total)](https://github.com/Freed-Wu/pyrime/releases/latest)
[![github/issues](https://shields.io/github/issues/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/issues)
[![github/issues-closed](https://shields.io/github/issues-closed/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/issues?q=is%3Aissue+is%3Aclosed)
[![github/issues-pr](https://shields.io/github/issues-pr/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/pulls)
[![github/issues-pr-closed](https://shields.io/github/issues-pr-closed/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/pulls?q=is%3Apr+is%3Aclosed)
[![github/discussions](https://shields.io/github/discussions/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/discussions)
[![github/milestones](https://shields.io/github/milestones/all/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/milestones)
[![github/forks](https://shields.io/github/forks/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/network/members)
[![github/stars](https://shields.io/github/stars/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/stargazers)
[![github/watchers](https://shields.io/github/watchers/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/watchers)
[![github/contributors](https://shields.io/github/contributors/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/graphs/contributors)
[![github/commit-activity](https://shields.io/github/commit-activity/w/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/graphs/commit-activity)
[![github/last-commit](https://shields.io/github/last-commit/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/commits)
[![github/release-date](https://shields.io/github/release-date/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/releases/latest)

[![github/license](https://shields.io/github/license/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/blob/main/LICENSE)
[![github/languages](https://shields.io/github/languages/count/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime)
[![github/languages/top](https://shields.io/github/languages/top/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime)
[![github/directory-file-count](https://shields.io/github/directory-file-count/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime)
[![github/code-size](https://shields.io/github/languages/code-size/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime)
[![github/repo-size](https://shields.io/github/repo-size/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime)
[![github/v](https://shields.io/github/v/release/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime)

[![pypi/status](https://shields.io/pypi/status/pyrime)](https://pypi.org/project/pyrime/#description)
[![pypi/v](https://shields.io/pypi/v/pyrime)](https://pypi.org/project/pyrime/#history)
[![pypi/downloads](https://shields.io/pypi/dd/pyrime)](https://pypi.org/project/pyrime/#files)
[![pypi/format](https://shields.io/pypi/format/pyrime)](https://pypi.org/project/pyrime/#files)
[![pypi/implementation](https://shields.io/pypi/implementation/pyrime)](https://pypi.org/project/pyrime/#files)
[![pypi/pyversions](https://shields.io/pypi/pyversions/pyrime)](https://pypi.org/project/pyrime/#files)

[![aur/votes](https://img.shields.io/aur/votes/python-pyrime)](https://aur.archlinux.org/packages/python-pyrime)
[![aur/popularity](https://img.shields.io/aur/popularity/python-pyrime)](https://aur.archlinux.org/packages/python-pyrime)
[![aur/maintainer](https://img.shields.io/aur/maintainer/python-pyrime)](https://aur.archlinux.org/packages/python-pyrime)
[![aur/last-modified](https://img.shields.io/aur/last-modified/python-pyrime)](https://aur.archlinux.org/packages/python-pyrime)
[![aur/version](https://img.shields.io/aur/version/python-pyrime)](https://aur.archlinux.org/packages/python-pyrime)

![screenshot](https://github.com/user-attachments/assets/5c79575c-79c5-4e4f-b6ab-b9cdaad352b2)

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

## Dependence

- [librime](https://github.com/rime/librime)

```sh
# 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`:

```python
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:

```python
    @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:

```python
    @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](https://github.com/Freed-Wu/Freed-Wu/blob/main/.config/ptpython/config.py)
to know more.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyrime",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "rime, ptpython, prompt-toolkit",
    "author": null,
    "author_email": "\"Wu, Zhenyu\" <wuzhenyu@ustc.edu>",
    "download_url": "https://files.pythonhosted.org/packages/21/8b/1314fe5c93ca3864a1ab230387ea4236aa67ec5f7f50c3bb2fbf8647c8b3/pyrime-0.0.7.tar.gz",
    "platform": null,
    "description": "# pyrime\n\n[![readthedocs](https://shields.io/readthedocs/pyrime)](https://pyrime.readthedocs.io)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/Freed-Wu/pyrime/main.svg)](https://results.pre-commit.ci/latest/github/Freed-Wu/pyrime/main)\n[![github/workflow](https://github.com/Freed-Wu/pyrime/actions/workflows/main.yml/badge.svg)](https://github.com/Freed-Wu/pyrime/actions)\n[![codecov](https://codecov.io/gh/Freed-Wu/pyrime/branch/main/graph/badge.svg)](https://codecov.io/gh/Freed-Wu/pyrime)\n\n[![github/downloads](https://shields.io/github/downloads/Freed-Wu/pyrime/total)](https://github.com/Freed-Wu/pyrime/releases)\n[![github/downloads/latest](https://shields.io/github/downloads/Freed-Wu/pyrime/latest/total)](https://github.com/Freed-Wu/pyrime/releases/latest)\n[![github/issues](https://shields.io/github/issues/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/issues)\n[![github/issues-closed](https://shields.io/github/issues-closed/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/issues?q=is%3Aissue+is%3Aclosed)\n[![github/issues-pr](https://shields.io/github/issues-pr/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/pulls)\n[![github/issues-pr-closed](https://shields.io/github/issues-pr-closed/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/pulls?q=is%3Apr+is%3Aclosed)\n[![github/discussions](https://shields.io/github/discussions/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/discussions)\n[![github/milestones](https://shields.io/github/milestones/all/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/milestones)\n[![github/forks](https://shields.io/github/forks/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/network/members)\n[![github/stars](https://shields.io/github/stars/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/stargazers)\n[![github/watchers](https://shields.io/github/watchers/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/watchers)\n[![github/contributors](https://shields.io/github/contributors/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/graphs/contributors)\n[![github/commit-activity](https://shields.io/github/commit-activity/w/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/graphs/commit-activity)\n[![github/last-commit](https://shields.io/github/last-commit/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/commits)\n[![github/release-date](https://shields.io/github/release-date/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/releases/latest)\n\n[![github/license](https://shields.io/github/license/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime/blob/main/LICENSE)\n[![github/languages](https://shields.io/github/languages/count/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime)\n[![github/languages/top](https://shields.io/github/languages/top/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime)\n[![github/directory-file-count](https://shields.io/github/directory-file-count/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime)\n[![github/code-size](https://shields.io/github/languages/code-size/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime)\n[![github/repo-size](https://shields.io/github/repo-size/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime)\n[![github/v](https://shields.io/github/v/release/Freed-Wu/pyrime)](https://github.com/Freed-Wu/pyrime)\n\n[![pypi/status](https://shields.io/pypi/status/pyrime)](https://pypi.org/project/pyrime/#description)\n[![pypi/v](https://shields.io/pypi/v/pyrime)](https://pypi.org/project/pyrime/#history)\n[![pypi/downloads](https://shields.io/pypi/dd/pyrime)](https://pypi.org/project/pyrime/#files)\n[![pypi/format](https://shields.io/pypi/format/pyrime)](https://pypi.org/project/pyrime/#files)\n[![pypi/implementation](https://shields.io/pypi/implementation/pyrime)](https://pypi.org/project/pyrime/#files)\n[![pypi/pyversions](https://shields.io/pypi/pyversions/pyrime)](https://pypi.org/project/pyrime/#files)\n\n[![aur/votes](https://img.shields.io/aur/votes/python-pyrime)](https://aur.archlinux.org/packages/python-pyrime)\n[![aur/popularity](https://img.shields.io/aur/popularity/python-pyrime)](https://aur.archlinux.org/packages/python-pyrime)\n[![aur/maintainer](https://img.shields.io/aur/maintainer/python-pyrime)](https://aur.archlinux.org/packages/python-pyrime)\n[![aur/last-modified](https://img.shields.io/aur/last-modified/python-pyrime)](https://aur.archlinux.org/packages/python-pyrime)\n[![aur/version](https://img.shields.io/aur/version/python-pyrime)](https://aur.archlinux.org/packages/python-pyrime)\n\n![screenshot](https://github.com/user-attachments/assets/5c79575c-79c5-4e4f-b6ab-b9cdaad352b2)\n\nrime for python, attached to prompt-toolkit keybindings for some prompt-toolkit\napplications such as ptpython.\n\n## Dependence\n\n- [librime](https://github.com/rime/librime)\n\n```sh\n# Ubuntu\nsudo apt-get -y install librime-dev librime1 pkg-config\nsudo apt-mark auto librime-dev pkg-config\n# ArchLinux\nsudo pacman -S --noconfirm librime pkg-config\n# Android Termux\napt-get -y install librime pkg-config\n# Nix\n# use nix-shell to create a virtual environment then build\n# homebrew\nbrew tap tonyfettes/homebrew-rime\nbrew install librime pkg-config\n# Windows msys2\npacboy -S --noconfirm pkg-config librime gcc\n```\n\n## Configure\n\n`~/.config/ptpython/config.py`:\n\n```python\nfrom ptpython.repl import PythonRepl\nfrom prompt_toolkit.filters import EmacsInsertMode, ViInsertMode\nfrom prompt_toolkit.key_binding.key_processor import KeyPressEvent\nfrom pyrime.prompt_toolkit import Rime\n\n\ndef configure(repl: PythonRepl) -> None:\n    rime = Rime(repl)\n\n    @repl.add_key_binding(\"c-^\", filter=ViInsertMode())\n    @repl.add_key_binding(\"c-^\", filter=EmacsInsertMode())\n    @repl.add_key_binding(\"c-^\", filter=rime.mode())\n    def _(event: KeyPressEvent) -> None:\n        rime.toggle()\n```\n\nIf you defined some key bindings which will disturb rime, try:\n\n```python\n    @repl.add_key_binding(\"c-h\", filter=rime.filter(EmacsInsertMode()))\n    def _(event: KeyPressEvent) -> None:\n        rime.toggle()\n```\n\nIf you want to exit rime in `ViNavigationMode()`, try:\n\n```python\n    @repl.add_key_binding(\"escape\", filter=EmacsInsertMode())\n    def _(event: KeyPressEvent) -> None:\n        \"\"\".\n\n        :param event:\n        :type event: KeyPressEvent\n        :rtype: None\n        \"\"\"\n        event.app.editing_mode = EditingMode.VI\n        event.app.vi_state.input_mode = InputMode.NAVIGATION\n        rime.conditional_disable()\n\n    # and a, I, A, ...\n    @repl.add_key_binding(\"i\", filter=ViNavigationMode())\n    def _(event: KeyPressEvent) -> None:\n        \"\"\".\n\n        :param event:\n        :type event: KeyPressEvent\n        :rtype: None\n        \"\"\"\n        event.app.editing_mode = EditingMode.EMACS\n        event.app.vi_state.input_mode = InputMode.INSERT\n        rime.conditional_enable()\n```\n\nIt will remember rime status and enable it when reenter `ViInsertMode()` or\n`EmacsInsertMode()`.\n\nSome utility functions are defined in this project. Refer\n[my ptpython config](https://github.com/Freed-Wu/Freed-Wu/blob/main/.config/ptpython/config.py)\nto know more.\n",
    "bugtrack_url": null,
    "license": "GPL v3",
    "summary": "rime for python, attached to prompt-toolkit keybindings for some prompt-toolkit applications such as ptpython",
    "version": "0.0.7",
    "project_urls": {
        "Bug Report": "https://github.com/Freed-Wu/pyrime/issues",
        "Download": "https://github.com/Freed-Wu/pyrime/releases",
        "Homepage": "https://pyrime.readthedocs.io",
        "Source": "https://github.com/Freed-Wu/pyrime"
    },
    "split_keywords": [
        "rime",
        " ptpython",
        " prompt-toolkit"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6f0104e19e52ec5c8e8bc9aa1f77c8871069863b287f100eb045e852b25b1f24",
                "md5": "32e5fd3ff1f2a0385b9867eb5d51946f",
                "sha256": "9f4ff41cc15945f9ffcc0a7c26cd320963538bad75c4c2136b5a6efd8e4620c5"
            },
            "downloads": -1,
            "filename": "pyrime-0.0.7-cp312-cp312-manylinux_2_17_x86_64.whl",
            "has_sig": false,
            "md5_digest": "32e5fd3ff1f2a0385b9867eb5d51946f",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.10",
            "size": 73249,
            "upload_time": "2024-12-03T07:37:02",
            "upload_time_iso_8601": "2024-12-03T07:37:02.304837Z",
            "url": "https://files.pythonhosted.org/packages/6f/01/04e19e52ec5c8e8bc9aa1f77c8871069863b287f100eb045e852b25b1f24/pyrime-0.0.7-cp312-cp312-manylinux_2_17_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3062dd2ae5c35e422ea377854a2087e608626538b301423304871f4bbda7609e",
                "md5": "7d1ce6531b1c41b41f722b67dfe2212d",
                "sha256": "78e13d33ec57490dd94d07395c0518c938f3c7d86dd69b36400951095dd4ff92"
            },
            "downloads": -1,
            "filename": "pyrime-0.0.7-cp312-cp312-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "7d1ce6531b1c41b41f722b67dfe2212d",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.10",
            "size": 101925,
            "upload_time": "2024-12-03T07:37:03",
            "upload_time_iso_8601": "2024-12-03T07:37:03.477784Z",
            "url": "https://files.pythonhosted.org/packages/30/62/dd2ae5c35e422ea377854a2087e608626538b301423304871f4bbda7609e/pyrime-0.0.7-cp312-cp312-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9accc8a9a4610b0a66e4f2acd5c3b25427e04f42a369273dc16e262c984c9b33",
                "md5": "4bcb48e991e3f13272fa17522fcd799c",
                "sha256": "734517ebbb064da3666c9b65017eb61f2fa142fe5ea651699bff496c324ef5bc"
            },
            "downloads": -1,
            "filename": "pyrime-0.0.7-cp313-cp313-macosx_14_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "4bcb48e991e3f13272fa17522fcd799c",
            "packagetype": "bdist_wheel",
            "python_version": "cp313",
            "requires_python": ">=3.10",
            "size": 54895,
            "upload_time": "2024-12-03T07:37:04",
            "upload_time_iso_8601": "2024-12-03T07:37:04.578559Z",
            "url": "https://files.pythonhosted.org/packages/9a/cc/c8a9a4610b0a66e4f2acd5c3b25427e04f42a369273dc16e262c984c9b33/pyrime-0.0.7-cp313-cp313-macosx_14_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "218b1314fe5c93ca3864a1ab230387ea4236aa67ec5f7f50c3bb2fbf8647c8b3",
                "md5": "0a85e655ff59ea01adc6612df44c8376",
                "sha256": "e0a9ecc4f405eebf3d998c6c7c9464da730e1b46a509cd3d64b3556f6cb797e3"
            },
            "downloads": -1,
            "filename": "pyrime-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "0a85e655ff59ea01adc6612df44c8376",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 42660,
            "upload_time": "2024-12-03T07:37:05",
            "upload_time_iso_8601": "2024-12-03T07:37:05.570125Z",
            "url": "https://files.pythonhosted.org/packages/21/8b/1314fe5c93ca3864a1ab230387ea4236aa67ec5f7f50c3bb2fbf8647c8b3/pyrime-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-03 07:37:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Freed-Wu",
    "github_project": "pyrime",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyrime"
}
        
Elapsed time: 4.60980s