@newfunc me.editor(self,buf,entry,state)
x
%# Rename property name so we can use original editor to read source
@renprop me.editor to neweditor
@edit me.neweditor
"""Builder METHOD: editor( self, buf, entry, state ):"""
# This method implements a subset *nix editor ed(1)
if not state:
# start new editing session and put in COMMAND
self.tell("[New Editor -- enter h for help]")
self._prompt = '*'
return 'OK'
elif state == 'INPUT':
# INPUT mode
if entry == '.':
self.tell('Exiting INPUT mode.')
self._prompt = '*'
return 'OK'
buf.insert(self._editAddr, entry)
# echoing input line interefered with standard telnet client and
# direct mode
##self.tell('%4s %s' % (self._editAddr + 1, entry))
self._editAddr += 1
return 'INPUT'
# split address(es) and command
# one letter commands come after address
cmd = entry[-1]
# split address numbers and convert symbols into line number
if len(entry) > 1:
addr = entry[:-1].split(',')
for i in range(len(addr)):
if addr[i] == '.': addr[i] = self._editAddr
elif addr[i] == '$': addr[i] = len(buf)
elif addr[i] == '%':
addr = [1, len(buf)]
break
elif addr[i] == ';':
addr = [self._editAddr, len(buf)]
break
elif addr[i][0] == '-':
addr[i] = eval('%s%s' % (self._editAddr, addr[i]))
elif addr[i][0] == '+':
addr[i] = eval('%s%s' % (self._editAddr, addr[i]))
else: addr[i] = int(addr[i])
else:
addr = []
if len(addr) > 2: return 'OK'
if cmd == 'h': # h - help
self.tell('New Editor Help (subset of *nix ed)')
self.tell('LINE ADDRESSING')
self.tell(' . The current line')
self.tell(' $ The last line')
self.tell(' n The nth line')
self.tell(' -n The nth previous line')
self.tell(' +n The nth next line')
self.tell(' % The first through last lines')
self.tell(' ; The current through last lines')
self.tell('COMMANDS')
self.tell(' (.)a Appends text after addressed line')
self.tell(' (.,.)c Changes the addressed lines')
self.tell(' (.,.)d Deletes the addressed lines')
self.tell(' (.)i Inserts text before addressed line')
self.tell(' (.,.+1)j Joins the addressed lines')
self.tell(' (.,.)l Prints the addressed lines')
self.tell(' (.,.)n Prints the addressed lines w/ line numbers')
self.tell(' q Quit (Abort)')
self.tell(' w Save and quit')
self.tell('Input mode is terminated by entering a single period.')