Recently I stumpled upon this series of posts about someone who wrote a (barebones) command line text editor on C and published a step-by-step version of it
Recently I stumpled upon this series of posts about someone who wrote a (barebones) command line text editor on C and published a step-by-step version of it
You will need a TUI (terminal user interface) library. There are many choices available for python, each with their own pros and cons: termbox blessed urwid curses python prompt toolkit...
You will need a TUI (terminal user interface) library. There are many choices available for python, each with their own pros and cons:
curses (curses.textpad) and urwid (urwid.edit) both have built-in widgets for simple text editing. They are also both mature and established libraries, with some quirks and idiosyncrasies. I would recommend you start there and see if you can find any simple examples / tutorials on the web.
Thank you very much for answering! It is very hard choosing a Python TUI! Your other arguments are sound to me, but the some quirks and idiosyncrasies is certainly not attractive. I'd prefer a...
Thank you very much for answering!
It is very hard choosing a Python TUI! Your other arguments are sound to me, but the some quirks and idiosyncrasies is certainly not attractive. I'd prefer a library that just works and keeps me sane, you know? Maybe that just doesn't exist? IDK.
Urwid was actually built for Python. Curses is a thin wrapper around an older C library. You can compare a minimal text editor in Urwid vs one in curses.
I mean, why not start by reading the source code of an ed implementation? ed is the standard text editor, after all. The OpenBSD version might be a good start. EDIT: Did you intend do name this...
EDIT: Did you intend do name this topic “(…) Python
command-line text editor?”? Because I've read it as “(…) Python
(comma) line text editor?”, ed obviously being a line
text editor.
It really depends on what your goals are. All of the TUI libraries use the same API under the hood (terminfo). Once you understand at least one of them on a fairly deep level, it's easy to switch...
It really depends on what your goals are. All of the TUI libraries use the same API under the hood (terminfo). Once you understand at least one of them on a fairly deep level, it's easy to switch between them.
Curses is part of the python standard library and that alone gives it a huge advantage for certain types of programs. You can write your application as a single python script and distribute it without needing to install any other dependencies or build a package.
Blessed has an (IMO) more "modern" and easier to understand interface. It also handles some things like unicode and text colors better than curses. The trade-off is that the API abstraction is at a lower level. You will need to do things like write your own code to manage windows inside of the terminal screen. This is actually better for applications where you need that level of control, but it can be a hurdle otherwise.
Recently I stumpled upon this series of posts about someone who wrote a (barebones) command line text editor on C and published a step-by-step version of it
Thanks. I know that tutorial. I don’t know C. I wish to do the same in Python. Thanks anyway.
You will need a TUI (terminal user interface) library. There are many choices available for python, each with their own pros and cons:
curses (curses.textpad) and urwid (urwid.edit) both have built-in widgets for simple text editing. They are also both mature and established libraries, with some quirks and idiosyncrasies. I would recommend you start there and see if you can find any simple examples / tutorials on the web.
Thank you very much for answering!
It is very hard choosing a Python TUI! Your other arguments are sound to me, but the
some quirks and idiosyncrasies
is certainly not attractive. I'd prefer a library that just works and keeps me sane, you know? Maybe that just doesn't exist? IDK.Urwid was actually built for Python. Curses is a thin wrapper around an older C library. You can compare a minimal text editor in Urwid vs one in curses.
I mean, why not start by reading the source code of an
ed
implementation?ed
is the standard text editor, after all. The OpenBSD version might be a good start.EDIT: Did you intend do name this topic “(…) Python command-line text editor?”? Because I've read it as “(…) Python (comma) line text editor?”,
ed
obviously being a line text editor.Yes the intention was command line.
Fixed.
I can certainly read source code but in my skill level it would be mostly a waste of time.
Should I learn curses or just go straight to blessed?
It really depends on what your goals are. All of the TUI libraries use the same API under the hood (terminfo). Once you understand at least one of them on a fairly deep level, it's easy to switch between them.
Curses is part of the python standard library and that alone gives it a huge advantage for certain types of programs. You can write your application as a single python script and distribute it without needing to install any other dependencies or build a package.
Blessed has an (IMO) more "modern" and easier to understand interface. It also handles some things like unicode and text colors better than curses. The trade-off is that the API abstraction is at a lower level. You will need to do things like write your own code to manage windows inside of the terminal screen. This is actually better for applications where you need that level of control, but it can be a hurdle otherwise.