'Process a single editing command.'

def do_command(self, ch):

    (y, x) = self.win.getyx()
    self.lastcmd = ch
    if curses.ascii.isprint(ch):
        if ((y < self.maxy) or (x < self.maxx)):
            self._insert_printable_char(ch)
    elif (ch == curses.ascii.SOH):
        self.win.move(y, 0)
    elif (ch in (curses.ascii.STX, curses.KEY_LEFT, curses.ascii.BS, curses.KEY_BACKSPACE)):
        if (x > 0):
            self.win.move(y, (x - 1))
        elif (y == 0):
            pass
        elif self.stripspaces:
            self.win.move((y - 1), self._end_of_line((y - 1)))
        else:
            self.win.move((y - 1), self.maxx)
        if (ch in (curses.ascii.BS, curses.KEY_BACKSPACE)):
            self.win.delch()
    elif (ch == curses.ascii.EOT):
        self.win.delch()
    elif (ch == curses.ascii.ENQ):
        if self.stripspaces:
            self.win.move(y, self._end_of_line(y))
        else:
            self.win.move(y, self.maxx)
    else:
        if (ch in (curses.ascii.ACK, curses.KEY_RIGHT)):
            if (x < self.maxx):
                self.win.move(y, (x + 1))
            elif (y == self.maxy):
                pass
            else:
                self.win.move((y + 1), 0)
        elif (ch == curses.ascii.BEL):
            return 0
        if (ch == curses.ascii.NL):
            if (self.maxy == 0):
                return 0
            if (y < self.maxy):
                self.win.move((y + 1), 0)
        elif (ch == curses.ascii.VT):
            if ((x == 0) and (self._end_of_line(y) == 0)):
                self.win.deleteln()
            else:
                self.win.move(y, x)
                self.win.clrtoeol()
        elif (ch == curses.ascii.FF):
            self.win.refresh()
        elif (ch in (curses.ascii.SO, curses.KEY_DOWN)):
            if (y < self.maxy):
                self.win.move((y + 1), x)
                if (x > self._end_of_line((y + 1))):
                    self.win.move((y + 1), self._end_of_line((y + 1)))
        elif (ch == curses.ascii.SI):
            self.win.insertln()
        elif (ch in (curses.ascii.DLE, curses.KEY_UP)):
            if (y > 0):
                self.win.move((y - 1), x)
                if (x > self._end_of_line((y - 1))):
                    self.win.move((y - 1), self._end_of_line((y - 1)))
    return 1
