Attachment 'er-vi.txt'

Download

   1 import types
   2 
   3 def debug(k):
   4 
   5     class debugged:
   6 
   7         lastmethod = "Λ"
   8         
   9         def __init__(self, *args, **kwargs):
  10             self.wrapped = k(*args, **kwargs)
  11             
  12         def __getattr__(self, attrname):
  13             
  14             if \
  15                not attrname.startswith("_") and \
  16                isinstance(getattr(self.wrapped, attrname), types.MethodType):
  17                 self.lastmethod = attrname
  18                             
  19             return getattr(self.wrapped, attrname)
  20 
  21         def __repr__(self):
  22             return self.lastmethod.rjust(3)+" "+ \
  23                    str(self.cursor).rjust(3)+" "+ \
  24                    ":- " + \
  25                    self.line
  26 
  27     return debugged
  28 
  29 @debug
  30 class editor:
  31     cursor = -1
  32     line = ""
  33 
  34     def i(self, c):
  35         self.line = self.line[:self.cursor+1] + c + self.line[self.cursor+1:]
  36         self.cursor+=1
  37 
  38     def iw(self, w):
  39         self.line = self.line[:self.cursor+1] + w+" " + self.line[self.cursor+1:]
  40         self.cursor+=len(w)+1
  41 
  42     def h(self, n=1):
  43         if len(self.line) > 0:
  44             cpos = self.cursor - n
  45             self.cursor = cpos if cpos >= 0 else 0
  46 
  47     def l(self, n=1):
  48         if len(self.line) > 0:
  49             cpos = self.cursor + n
  50             self.cursor = cpos if cpos <= len(self.line)-1 else len(self.line)-1
  51 
  52     def x(self):
  53         if len(self.line) > 0:
  54             self.line = self.line[:self.cursor]+self.line[self.cursor+1:]
  55             if self.cursor == len(self.line): self.cursor -= 1
  56 
  57     def dw(self):
  58         if len(self.line) > 0:
  59             
  60             # senza questa if, se il cursore è inizialmente su uno spazio non si elimina niente
  61             # (non entra nel while)
  62             if self.line[self.cursor] == " ": self.x()
  63 
  64             current = self.cursor
  65             
  66             while len(self.line) > 0 and self.line[self.cursor] != " " and self.cursor >= current:
  67                 self.x()
  68 
  69     def __repr__(self):
  70         return self.line
  71         #return self.line + "\n" + " "*self.cursor + "^"

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.

Unable to edit the page? See the FrontPage for instructions.