Video Coming Soon...
Exercise 50: vi
I am going to prison for this exercise. You have a module that implements features used in both ed
and sed
. Obviously the next step is to implement the most hated and useful text editor in the history of the world: vi
. If you knew Lisp you could implement Emacs,
but nobody has time to create a whole new operating system pretending to be a text editor. Life is too short to hold down three keys and hit tab all day.
The goal of this exercise is not to do a dead accurate copy of vi
. That's a very large project, but if you feel like trying it then go for it. Your goal in this project is to do one more reuse of your ed
module and to play around with the Python curses module. The curses
module lets you do old-school text terminal window and graphic manipulation. Actually "graphics" should be in quotes because there are very little actual graphics in curses
.
You'll use curses to create a baby vi
implementation that lets you open files, run ed
and sed
commands using your module, and use curses
to display them to the terminal screen. You'll also find out that attempting to automatically test this is going to be very difficult. You'll get extra points if you can figure out how to do a fake curses testing framework, but that's going to require some magical wizard skills with a Unix pty system (I think).
The better way to make this testable is to put as much of your vi
into Python modules as possible so that you can test the code without having to run the curses
screen system. When I say "modules" I don't really mean a fully baked Python module that you install with pip
like you did with the ed
module. I mean modules right in the code for the vi
and then imported into your project.
The way to think of this project is to separate the code that controls the view (curses
) from the rest of the code so that you can plug in your own fake view for the testing. That then leaves a small amount of functionality that you can test manually by actually running your vi
.
Register for Learn More Python the Hard Way
Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.