prompt-toolkit / pyvim

Pure Python Vim clone.
BSD 3-Clause "New" or "Revised" License
2.52k stars 160 forks source link

Use as a library? #150

Open mentalisttraceur opened 1 year ago

mentalisttraceur commented 1 year ago

I was recently thinking about adding vi-style editing to some software written in Python.

Naturally I start searching for "vi"/"vim"/etc on PyPI, and I find this - looks promising, I'm super excited, etc.

At a glance, it looks like the focus of this project is the full interactive TUI of vi. Does it have a core that can be reused as a library? So that for example a GUI written in Python could easily add vi-style editing to a command line that it has? If not, is there interest in a PR to refactor things to make it that happen?

[click to expand some design thoughts] I'm hoping for a library that's more like a state machine of sorts: off the top of my head, I imagine/design 1. a class representing a thing being edited, 2. we construct/initialize it with one argument - a `string`, `bytes`, or `bytearray` object, or something similarly sensible, 3. it has a method which takes inputs (a string representing key strokes, probably) and returns something to indicate if further inputs are needed (for example, the user hit "d" and the second "d" or motion hasn't come in yet) and what vi mode this instance of the object is in, and 4. another method that returns the current string/bytearray/whatever after all the edits/input up to this point (perhaps this could/should also return the current vi mode, for convenience). (A full vi replacement use-case would probably need to layer in optimizations with this - which could be done by for example creating an object that fulfills a relevant editable interface - but this seems like a sufficient minimal interface for basic use-cases.)