Lines Matching refs:self
85 def __init__(self, r=24, c=80, encoding='latin-1', encoding_errors='replace'): argument
88 self.rows = r
89 self.cols = c
90 self.encoding = encoding
91 self.encoding_errors = encoding_errors
93 self.decoder = codecs.getincrementaldecoder(encoding)(encoding_errors)
95 self.decoder = None
96 self.cur_r = 1
97 self.cur_c = 1
98 self.cur_saved_r = 1
99 self.cur_saved_c = 1
100 self.scroll_row_start = 1
101 self.scroll_row_end = self.rows
102 self.w = [ [SPACE] * self.cols for _ in range(self.rows)]
104 def _decode(self, s): argument
107 if self.decoder is not None:
108 return self.decoder.decode(s)
113 def _unicode(self): argument
118 return u'\n'.join ([ u''.join(c) for c in self.w ])
125 def __str__(self): argument
128 encoding = self.encoding or 'ascii'
129 return self._unicode().encode(encoding, 'replace')
131 def dump (self): argument
136 return u''.join ([ u''.join(c) for c in self.w ])
138 def pretty (self): argument
143 top_bot = u'+' + u'-'*self.cols + u'+\n'
144 …return top_bot + u'\n'.join([u'|'+line+u'|' for line in unicode(self).split(u'\n')]) + u'\n' + top…
146 def fill (self, ch=SPACE): argument
149 ch = self._decode(ch)
151 self.fill_region (1,1,self.rows,self.cols, ch)
153 def fill_region (self, rs,cs, re,ce, ch=SPACE): argument
156 ch = self._decode(ch)
158 rs = constrain (rs, 1, self.rows)
159 re = constrain (re, 1, self.rows)
160 cs = constrain (cs, 1, self.cols)
161 ce = constrain (ce, 1, self.cols)
168 self.put_abs (r,c,ch)
170 def cr (self): argument
174 self.cursor_home (self.cur_r, 1)
176 def lf (self): argument
180 old_r = self.cur_r
181 self.cursor_down()
182 if old_r == self.cur_r:
183 self.scroll_up ()
184 self.erase_line()
186 def crlf (self): argument
191 self.cr ()
192 self.lf ()
194 def newline (self): argument
198 self.crlf()
200 def put_abs (self, r, c, ch): argument
203 r = constrain (r, 1, self.rows)
204 c = constrain (c, 1, self.cols)
206 ch = self._decode(ch)[0]
209 self.w[r-1][c-1] = ch
211 def put (self, ch): argument
216 ch = self._decode(ch)
218 self.put_abs (self.cur_r, self.cur_c, ch)
220 def insert_abs (self, r, c, ch): argument
227 ch = self._decode(ch)
229 r = constrain (r, 1, self.rows)
230 c = constrain (c, 1, self.cols)
231 for ci in range (self.cols, c, -1):
232 self.put_abs (r,ci, self.get_abs(r,ci-1))
233 self.put_abs (r,c,ch)
235 def insert (self, ch): argument
238 ch = self._decode(ch)
240 self.insert_abs (self.cur_r, self.cur_c, ch)
242 def get_abs (self, r, c): argument
244 r = constrain (r, 1, self.rows)
245 c = constrain (c, 1, self.cols)
246 return self.w[r-1][c-1]
248 def get (self): argument
250 self.get_abs (self.cur_r, self.cur_c)
252 def get_region (self, rs,cs, re,ce): argument
256 rs = constrain (rs, 1, self.rows)
257 re = constrain (re, 1, self.rows)
258 cs = constrain (cs, 1, self.cols)
259 ce = constrain (ce, 1, self.cols)
268 ch = self.get_abs (r,c)
273 def cursor_constrain (self): argument
277 self.cur_r = constrain (self.cur_r, 1, self.rows)
278 self.cur_c = constrain (self.cur_c, 1, self.cols)
280 def cursor_home (self, r=1, c=1): # <ESC>[{ROW};{COLUMN}H argument
282 self.cur_r = r
283 self.cur_c = c
284 self.cursor_constrain ()
286 def cursor_back (self,count=1): # <ESC>[{COUNT}D (not confused with down) argument
288 self.cur_c = self.cur_c - count
289 self.cursor_constrain ()
291 def cursor_down (self,count=1): # <ESC>[{COUNT}B (not confused with back) argument
293 self.cur_r = self.cur_r + count
294 self.cursor_constrain ()
296 def cursor_forward (self,count=1): # <ESC>[{COUNT}C argument
298 self.cur_c = self.cur_c + count
299 self.cursor_constrain ()
301 def cursor_up (self,count=1): # <ESC>[{COUNT}A argument
303 self.cur_r = self.cur_r - count
304 self.cursor_constrain ()
306 def cursor_up_reverse (self): # <ESC> M (called RI -- Reverse Index) argument
308 old_r = self.cur_r
309 self.cursor_up()
310 if old_r == self.cur_r:
311 self.scroll_up()
313 def cursor_force_position (self, r, c): # <ESC>[{ROW};{COLUMN}f argument
316 self.cursor_home (r, c)
318 def cursor_save (self): # <ESC>[s argument
321 self.cursor_save_attrs()
323 def cursor_unsave (self): # <ESC>[u argument
326 self.cursor_restore_attrs()
328 def cursor_save_attrs (self): # <ESC>7 argument
331 self.cur_saved_r = self.cur_r
332 self.cur_saved_c = self.cur_c
334 def cursor_restore_attrs (self): # <ESC>8 argument
337 self.cursor_home (self.cur_saved_r, self.cur_saved_c)
339 def scroll_constrain (self): argument
342 if self.scroll_row_start <= 0:
343 self.scroll_row_start = 1
344 if self.scroll_row_end > self.rows:
345 self.scroll_row_end = self.rows
347 def scroll_screen (self): # <ESC>[r argument
350 self.scroll_row_start = 1
351 self.scroll_row_end = self.rows
353 def scroll_screen_rows (self, rs, re): # <ESC>[{start};{end}r argument
356 self.scroll_row_start = rs
357 self.scroll_row_end = re
358 self.scroll_constrain()
360 def scroll_down (self): # <ESC>D argument
364 s = self.scroll_row_start - 1
365 e = self.scroll_row_end - 1
366 self.w[s+1:e+1] = copy.deepcopy(self.w[s:e])
368 def scroll_up (self): # <ESC>M argument
372 s = self.scroll_row_start - 1
373 e = self.scroll_row_end - 1
374 self.w[s:e] = copy.deepcopy(self.w[s+1:e+1])
376 def erase_end_of_line (self): # <ESC>[0K -or- <ESC>[K argument
380 self.fill_region (self.cur_r, self.cur_c, self.cur_r, self.cols)
382 def erase_start_of_line (self): # <ESC>[1K argument
386 self.fill_region (self.cur_r, 1, self.cur_r, self.cur_c)
388 def erase_line (self): # <ESC>[2K argument
391 self.fill_region (self.cur_r, 1, self.cur_r, self.cols)
393 def erase_down (self): # <ESC>[0J -or- <ESC>[J argument
397 self.erase_end_of_line ()
398 self.fill_region (self.cur_r + 1, 1, self.rows, self.cols)
400 def erase_up (self): # <ESC>[1J argument
404 self.erase_start_of_line ()
405 self.fill_region (self.cur_r-1, 1, 1, self.cols)
407 def erase_screen (self): # <ESC>[2J argument
410 self.fill ()
412 def set_tab (self): # <ESC>H argument
417 def clear_tab (self): # <ESC>[g argument
422 def clear_all_tabs (self): # <ESC>[3g argument