Lines Matching refs:self

43     def __init__(self, win, insert_mode=False):
44 self.win = win
45 self.insert_mode = insert_mode
46 self._update_max_yx()
47 self.stripspaces = 1
48 self.lastcmd = None
51 def _update_max_yx(self):
52 maxy, maxx = self.win.getmaxyx()
53 self.maxy = maxy - 1
54 self.maxx = maxx - 1
56 def _end_of_line(self, y):
59 self._update_max_yx()
60 last = self.maxx
62 if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
63 last = min(self.maxx, last+1)
70 def _insert_printable_char(self, ch):
71 self._update_max_yx()
72 (y, x) = self.win.getyx()
74 while y < self.maxy or x < self.maxx:
75 if self.insert_mode:
76 oldch = self.win.inch()
81 self.win.addch(ch)
84 if not self.insert_mode or not curses.ascii.isprint(oldch):
87 (y, x) = self.win.getyx()
93 self.win.move(*backyx)
95 def do_command(self, ch):
97 self._update_max_yx()
98 (y, x) = self.win.getyx()
99 self.lastcmd = ch
101 if y < self.maxy or x < self.maxx:
102 self._insert_printable_char(ch)
104 self.win.move(y, 0)
107 self.win.move(y, x-1)
110 elif self.stripspaces:
111 self.win.move(y-1, self._end_of_line(y-1))
113 self.win.move(y-1, self.maxx)
115 self.win.delch()
117 self.win.delch()
119 if self.stripspaces:
120 self.win.move(y, self._end_of_line(y))
122 self.win.move(y, self.maxx)
124 if x < self.maxx:
125 self.win.move(y, x+1)
126 elif y == self.maxy:
129 self.win.move(y+1, 0)
133 if self.maxy == 0:
135 elif y < self.maxy:
136 self.win.move(y+1, 0)
138 if x == 0 and self._end_of_line(y) == 0:
139 self.win.deleteln()
141 # first undo the effect of self._end_of_line
142 self.win.move(y, x)
143 self.win.clrtoeol()
145 self.win.refresh()
147 if y < self.maxy:
148 self.win.move(y+1, x)
149 if x > self._end_of_line(y+1):
150 self.win.move(y+1, self._end_of_line(y+1))
152 self.win.insertln()
155 self.win.move(y-1, x)
156 if x > self._end_of_line(y-1):
157 self.win.move(y-1, self._end_of_line(y-1))
160 def gather(self):
163 self._update_max_yx()
164 for y in range(self.maxy+1):
165 self.win.move(y, 0)
166 stop = self._end_of_line(y)
167 if stop == 0 and self.stripspaces:
169 for x in range(self.maxx+1):
170 if self.stripspaces and x > stop:
172 result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
173 if self.maxy > 0:
177 def edit(self, validate=None):
180 ch = self.win.getch()
185 if not self.do_command(ch):
187 self.win.refresh()
188 return self.gather()