https://github.com/albertz/py-tui-editor
Simple Python terminal (TUI) multi-line editor
https://github.com/albertz/py-tui-editor
python tty tui-editor
Last synced: 2 months ago
JSON representation
Simple Python terminal (TUI) multi-line editor
- Host: GitHub
- URL: https://github.com/albertz/py-tui-editor
- Owner: albertz
- License: mit
- Created: 2022-08-20T19:58:20.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-12T22:34:21.000Z (10 months ago)
- Last Synced: 2025-03-18T20:54:02.944Z (3 months ago)
- Topics: python, tty, tui-editor
- Language: Python
- Homepage:
- Size: 1.31 MB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Simple Python terminal (TUI) multi-line editor
##############################################Features:
- simple multi-line editor
- not whole screen but only next N lines
- status bar (supporting multiple lines):
show interactive feedback. e.g. mark edits, show number of edits, show diff in separate plane or soThis is just a simple multi-line editor for the terminal
(VT100).
It is a bit like
``input`` (`doc `__)
but supporting multiple lines
and behaving more like a simple editor.
It is different to other editors
and other TUI frameworks in that it will not go full-screen
but only use the last N lines of the terminal.
It is intended to be simple and flexible and hackable,
i.e. the behavior can be changed, typing events can be handled,
etc.
It takes extra care to handle terminal resizing.
It also supports to show a status bar (potential multi-line).Homepage: https://github.com/albertz/py-tui-editor
Installation
************The project is on PyPI:
https://pypi.org/project/tui-editor/Thus you can just do:
.. code-block:: bash
pip install tui-editor
Usage
*****Simple empty editor:
.. code-block:: python
>>> from tui_editor import TuiEditor
>>> editor = TuiEditor()
>>> editor.edit()
>>> editor.get_text()
'Hello World!'Predefined editable text:
.. code-block:: python
>>> from tui_editor import TuiEditor
>>> editor = TuiEditor()
>>> editor.set_text('Hello World!')
>>> editor.edit()
>>> editor.get_text()
'Hello World!'See `demo-prompt.py `__
and `demo-editor.py `__.Screenshot
**********.. image:: https://raw.githubusercontent.com/albertz/py-tui-editor/master/screenshots/2022-09-02.png?sanitize=true
Screencast
**********.. image:: https://img.youtube.com/vi/zIFMyBkYwqg/maxresdefault.jpg
:target: https://youtu.be/zIFMyBkYwqgThis shows the ``demo-prompt.py`` and ``demo-editor.py``.
.. image:: https://img.youtube.com/vi/4ERr0o9k72Y/maxresdefault.jpg
:target: https://youtu.be/4ERr0o9k72YThis uses a `very custom small app `__,
which I use to take over annotated PDF edits into my Latex file,
where I get the editor, and it shows me the live-diff in the status bar of the editor.Licence
*******MIT License
History
*******2015 Paul Sokolovsky:
`picotui project `__
`seditor.py example `__.
2022 Albert Zeyer: extend and redesign and package just the text editor as this library.Related projects
****************Python terminal user interface (TUI) and related.
The features stated in the beginning were the main motivation.
The related work here did not really satisfy me in getting those features,
or did not really make it simpler to accomplish them.
(At least from a first glance to those other projects
- maybe I'm missing sth! Please share a short demo,
similar to the demos here, if you know how to easily implement it.)https://docs.python.org/3/library/curses.html
- too complex but at the same time too limited?https://github.com/bczsalba/pytermgui (1.2k stars)
- limited, no real text editorhttps://urwid.org/examples/index.html (2.5k stars)
- edit example: https://github.com/urwid/urwid/blob/master/examples/edit.pyhttps://github.com/prompt-toolkit/python-prompt-toolkit (7.9k stars)
- too complex...? similar as curses...https://github.com/pfalcon/picotui (0.7k stars)
- good enough? editor: https://github.com/pfalcon/picotui/blob/master/picotui/editor.py
- another editor: https://github.com/pfalcon/picotui/blob/master/seditor.pyhttps://github.com/Textualize/textual (13k stars)
- async framework, I don't want that...(Or coding some line edit by hand, should not be too difficult...?)
https://github.com/pfalcon/picotui/blob/master/seditor.py
References
**********https://en.wikipedia.org/wiki/ANSI_escape_code
https://invisible-island.net/xterm/ctlseqs/ctlseqs.html