Process a single editing command.
(self, ch)
| 93 | self.win.move(*backyx) |
| 94 | |
| 95 | def do_command(self, ch): |
| 96 | "Process a single editing command." |
| 97 | self._update_max_yx() |
| 98 | (y, x) = self.win.getyx() |
| 99 | self.lastcmd = ch |
| 100 | if curses.ascii.isprint(ch): |
| 101 | if y < self.maxy or x < self.maxx: |
| 102 | self._insert_printable_char(ch) |
| 103 | elif ch == curses.ascii.SOH: # ^a |
| 104 | self.win.move(y, 0) |
| 105 | elif ch in (curses.ascii.STX,curses.KEY_LEFT, |
| 106 | curses.ascii.BS, |
| 107 | curses.KEY_BACKSPACE, |
| 108 | curses.ascii.DEL): |
| 109 | if x > 0: |
| 110 | self.win.move(y, x-1) |
| 111 | elif y == 0: |
| 112 | pass |
| 113 | elif self.stripspaces: |
| 114 | self.win.move(y-1, self._end_of_line(y-1)) |
| 115 | else: |
| 116 | self.win.move(y-1, self.maxx) |
| 117 | if ch in (curses.ascii.BS, curses.KEY_BACKSPACE, curses.ascii.DEL): |
| 118 | self.win.delch() |
| 119 | elif ch == curses.ascii.EOT: # ^d |
| 120 | self.win.delch() |
| 121 | elif ch == curses.ascii.ENQ: # ^e |
| 122 | if self.stripspaces: |
| 123 | self.win.move(y, self._end_of_line(y)) |
| 124 | else: |
| 125 | self.win.move(y, self.maxx) |
| 126 | elif ch in (curses.ascii.ACK, curses.KEY_RIGHT): # ^f |
| 127 | if x < self.maxx: |
| 128 | self.win.move(y, x+1) |
| 129 | elif y == self.maxy: |
| 130 | pass |
| 131 | else: |
| 132 | self.win.move(y+1, 0) |
| 133 | elif ch == curses.ascii.BEL: # ^g |
| 134 | return 0 |
| 135 | elif ch == curses.ascii.NL: # ^j |
| 136 | if self.maxy == 0: |
| 137 | return 0 |
| 138 | elif y < self.maxy: |
| 139 | self.win.move(y+1, 0) |
| 140 | elif ch == curses.ascii.VT: # ^k |
| 141 | if x == 0 and self._end_of_line(y) == 0: |
| 142 | self.win.deleteln() |
| 143 | else: |
| 144 | # first undo the effect of self._end_of_line |
| 145 | self.win.move(y, x) |
| 146 | self.win.clrtoeol() |
| 147 | elif ch == curses.ascii.FF: # ^l |
| 148 | self.win.refresh() |
| 149 | elif ch in (curses.ascii.SO, curses.KEY_DOWN): # ^n |
| 150 | if y < self.maxy: |
| 151 | self.win.move(y+1, x) |
| 152 | if x > self._end_of_line(y+1): |