I have gotten to know my way around a few programming languages, and I'd like to try my hand at making a command-line text editor -- something that runs in the terminal, like vim/emacs/nano, but is pure text (no guis, please). Preferably, I'd like to do this in python. Where do I start? Are there any (python) libraries to do command-line applications?
-
if you find ongoing projects, please do let us know. I'd love to see a vim-like editor written in python and using python as scripting language... – Ciro Santilli OurBigBook.com Apr 08 '13 at 11:02
-
Have a look at [Suplemon](https://github.com/richrd/suplemon) – kangaroo Jun 15 '18 at 21:35
-
1@CiroSantilli新疆再教育营六四事件法轮功郝海东 [pyvim](https://github.com/prompt-toolkit/pyvim) – Giorgos Xou Oct 23 '21 at 11:38
-
@GiorgosXou I think that editor might not support python scripting currently – Ciro Santilli OurBigBook.com Oct 23 '21 at 12:08
10 Answers
try python curses module , it is a command-line graphic operation library.

- 346
- 3
- 14

- 4,538
- 6
- 44
- 64
-
8Kids today! When I was learning to code, we didn't have curses, we had teletypes! – S.Lott Mar 27 '09 at 11:26
-
9Back in my young day we had to hand-make circuit boards before we even started ;P – Christian Witts Mar 27 '09 at 11:40
-
17Back in my day, we used cogs and steam to reveal and conceal 1-foot square pixels on vast, bonfire-backed displays that stretched miles, and the whole thing was pointless unless you had a trained team of at least 100 gnomes. – Mr. B Mar 07 '15 at 20:37
Take a look at Curses Programming in Python and this as well.

- 346
- 3
- 14

- 4,255
- 28
- 37
Another option if you want to write a TUI (Text User Interface) without having to descend to curses is Snack, which comes with Newt.

- 776,304
- 153
- 1,341
- 1,358
Kids today! Sheesh! When I was starting out, curses was not in widespread use!
My first text editors worked on actual mechanical Teletype devices with actual paper (not a philosophical "TTY" device with a scrolling screen!)
This still works nicely as a way to edit.
Use the cmd
module to implement a bunch of commands. Use the 'ex' man page for hints as to what you need. Do not read about the vi commands; avoid reading about vim.
Look at older man pages for just the "EX COMMANDS" section. For example, here: http://www.manpagez.com/man/1/ex/.
Implement the append, add, change, delete, global, insert, join, list, move, print, quit, substitute and write commands and you'll be happy.
-
My first interaction with a "computer" was over an acoustically coupled remote TTY. Alas, it was a mainframe at Dad's office, and I was not allowed to do anything interesting with it. – dmckee --- ex-moderator kitten Mar 30 '09 at 18:57
-
My first TTY's were hard-wired. Probably 110 BAUD. I remember when 300 BAUD was a big deal. – S.Lott Mar 30 '09 at 19:28
Curses type libraries and resources will get you into the textual user interfaces, and provide very nice, relatively easy to use windows, menus, editors, etc.
Then you'll want to look into code highlighting modules for python.
It's a fun process dealing with the limitations of textual interfaces, and you can learn a lot by going down this road. Good luck!
-Adam

- 91,931
- 60
- 264
- 330
-
Thanks -- do you have any good recommendations for said code highlighting modules? I was poking around the pygments documentation, but that didn't look like it was built for real-time syntax highlighting. Can pygments do real-time syntax highlighting, or are there other modules I should check out? – So8res Mar 27 '09 at 02:53
-
I would recommend the excellent urwid toolkit (http://excess.org/article/2009/03/urwid-0984-released) - it's much easier to use than straight curses.

- 5,185
- 25
- 41
Well, what do you mean by a GUI? If you just want to create something that can be used on a console, look into the curses
module in the Python standard library, which allows you to simulate a primitive GUI of sorts on a console.

- 128,184
- 27
- 255
- 279
A not very serious suggestions: a line editor can be implemented without curses.
These things are pretty primitive, of course, and not a lot of fun to work in. But they can be implemented with very little code, and would give you a chance to fool around with various schemes for maintaining the file state in memory pretty quickly.
And they would put you in touch with the programmers of the early seventies (when they had teletypes and the first glass teletypes, but after punched cards were a bit passe...).

- 98,632
- 24
- 142
- 234
Not quite a reference to a Python library, but The Craft of Text Editing by Craig A. Finseth might be of interest you.

- 28,661
- 12
- 68
- 93
Another option without curses is Python Slang
Newt is a library written on top of Slang.

- 247
- 2
- 9

- 784
- 1
- 5
- 15