So8res
So8res

Reputation: 10366

How do I make a command line text editor?

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?

Upvotes: 23

Views: 26670

Answers (10)

Renato Aquino
Renato Aquino

Reputation: 814

Another option without curses is Python Slang

Newt is a library written on top of Slang.

Upvotes: 0

linjunhalida
linjunhalida

Reputation: 4655

try python curses module , it is a command-line graphic operation library.

Upvotes: 26

Jim Blizard
Jim Blizard

Reputation: 4253

Take a look at Curses Programming in Python and this as well.

Upvotes: 10

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...).

Upvotes: 2

S.Lott
S.Lott

Reputation: 391952

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.

Upvotes: 7

sigjuice
sigjuice

Reputation: 29777

Not quite a reference to a Python library, but The Craft of Text Editing by Craig A. Finseth might be of interest you.

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798944

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

Upvotes: 8

vezult
vezult

Reputation: 5243

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.

Upvotes: 3

Adam Davis
Adam Davis

Reputation: 93605

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

Upvotes: 5

David Z
David Z

Reputation: 131640

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.

Upvotes: 2

Related Questions