#!/usr/bin/env python """ emano.py - The Simple Powerful Term Editor Author: Sean B. Palmer, inamidst.com Source: http://inamidst.com/emano/ @@ WARNING: This is not yet stable code: * Don't edit any files that you consider valuable * Remember to back up all of your work first """ import sys, os, curses # @@ Version: major.months-since-2005-01.day? if hasattr(os, 'pathconf_names'): # A value of -1 is returned if any of _POSIX_CHOWN_RESTRICTED, _ # POSIX_NO_TRUNC and _POSIX_VDISABLE are turned off. Otherwise, # another value is returned. # --man pathconf(2) # # This option is only meaningful for files that are terminal # devices. If it is enabled, then handling for special control # characters can be disabled individually. # --GNU libc manual on _POSIX_VDISABLE _POSIX_VDISABLE = os.pathconf_names.get('PC_VDISABLE', -1) != -1 else: _POSIX_VDISABLE = False def start(*filenames): """Initialise ncurses and start an emano Editor instance.""" screen = curses.initscr() screen.border(' ', ' ', ' ', ' ', ' ', ' ', ord('#')) screen.keypad(0) curses.nonl() # Turn off input buffering curses.noecho() # Turn off input echoing if _POSIX_VDISABLE: # And, if this system supports this... curses.raw() # Turn off everything else curses.meta(1) # Allow 8-bit character input def restore(): """Reverse the ncurses setup stuff.""" curses.nl() curses.echo() if _POSIX_VDISABLE: curses.noraw() curses.endwin() # @@ Wrap this is a better try-etc. block import editor try: editor.run(screen, filenames) finally: restore() def main(argv=None): # Check that we're in Python 2.4 or later if (not hasattr(sys, 'version_info')) or sys.version_info < (2, 4): print >> sys.stderr, "Error: Requires Python 2.4 or later." sys.exit(1) from optparse import OptionParser parser = OptionParser(usage='%prog [options] *') options, args = parser.parse_args(argv) start(*args) if __name__=="__main__": main()