7 votes

Where should I start to make a minimalist Python command-line text editor?

Every tutorial I find is geared to graphical interfaces

11 comments

  1. [2]
    aymm
    Link
    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

    4 votes
    1. mrbig
      Link Parent
      Thanks. I know that tutorial. I don’t know C. I wish to do the same in Python. Thanks anyway.

      Thanks. I know that tutorial. I don’t know C. I wish to do the same in Python. Thanks anyway.

      1 vote
  2. [3]
    mozz
    Link
    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.

    3 votes
    1. [2]
      mrbig
      Link Parent
      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.

      1 vote
      1. imperialismus
        Link Parent
        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.

        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.

        4 votes
  3. [4]
    unknown user
    (edited )
    Link
    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...

    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.

    2 votes
    1. [2]
      mrbig
      Link Parent
      Yes the intention was command line.

      Yes the intention was command line.

      2 votes
    2. mrbig
      Link Parent
      I can certainly read source code but in my skill level it would be mostly a waste of time.

      I can certainly read source code but in my skill level it would be mostly a waste of time.

  4. [2]
    mrbig
    Link
    Should I learn curses or just go straight to blessed?

    Should I learn curses or just go straight to blessed?

    1. mozz
      Link Parent
      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.

      1 vote