Lines Matching refs:self
55 def __init__(self, maxlen=None):
56 self.maxlen = maxlen
57 self.lines = co.deque(maxlen=maxlen)
58 self.tail = io.StringIO()
62 self.resize(0)
64 def write(self, s):
68 if len(lines) > 1 and self.tail.getvalue():
69 self.tail.write(lines[0])
70 lines[0] = self.tail.getvalue()
71 self.tail = io.StringIO()
73 self.lines.extend(lines[:-1])
76 self.tail.write(lines[-1])
78 def resize(self, maxlen):
79 self.maxlen = maxlen
82 if maxlen != self.lines.maxlen:
83 self.lines = co.deque(self.lines, maxlen=maxlen)
86 def draw(self):
88 if self.maxlen == 0:
89 self.resize(0)
92 while LinesIO.canvas_lines < len(self.lines):
97 shrink = LinesIO.canvas_lines - len(self.lines)
107 LinesIO.canvas_lines = len(self.lines)
109 for i, line in enumerate(self.lines):
112 if len(self.lines)-1-i > 0:
113 sys.stdout.write('\x1b[%dA' % (len(self.lines)-1-i))
118 if len(self.lines)-1-i > 0:
119 sys.stdout.write('\x1b[%dB' % (len(self.lines)-1-i))
221 def wear(self):
222 return self >> 3
225 def readed(self):
226 return (self & 1) != 0
229 def proged(self):
230 return (self & 2) != 0
233 def erased(self):
234 return (self & 4) != 0
236 def read(self):
237 return Block(int(self) | 1)
239 def prog(self):
240 return Block(int(self) | 2)
242 def erase(self):
243 return Block((int(self) | 4) + 8)
245 def clear(self):
246 return Block(int(self) & ~7)
248 def __or__(self, other):
250 (int(self) | int(other)) & 7,
251 wear=max(self.wear, other.wear))
253 def worn(self, max_wear, *,
261 return self.wear / block_cycles
263 return self.wear / max(max_wear, len(wear_chars))
265 def draw(self, max_wear, char=None, *,
309 self.worn(
318 if erase and self.erased:
321 elif prog and self.proged:
324 elif read and self.readed:
342 def __init__(self, *,
352 self.blocks = [Block() for _ in range(width*height)]
354 self.blocks = blocks
355 self.size = size
356 self.count = count
357 self.width = width
358 self.height = height
360 def _op(self, f, block=None, off=None, size=None):
362 range_ = range(len(self.blocks))
365 off, size = 0, self.size
370 self.resize(
371 size=max(self.size, off+size),
372 count=max(self.count, block+1))
375 start = (block*self.size + off) / (self.size*self.count)
376 stop = (block*self.size + off+size) / (self.size*self.count)
379 m.floor(start*len(self.blocks)),
380 m.ceil(stop*len(self.blocks)))
384 self.blocks[i] = f(self.blocks[i])
386 def read(self, block=None, off=None, size=None):
387 self._op(Block.read, block, off, size)
389 def prog(self, block=None, off=None, size=None):
390 self._op(Block.prog, block, off, size)
392 def erase(self, block=None, off=None, size=None):
393 self._op(Block.erase, block, off, size)
395 def clear(self, block=None, off=None, size=None):
396 self._op(Block.clear, block, off, size)
398 def copy(self):
400 blocks=self.blocks.copy(),
401 size=self.size,
402 count=self.count,
403 width=self.width,
404 height=self.height)
406 def resize(self, *,
411 size = size if size is not None else self.size
412 count = count if count is not None else self.count
413 width = width if width is not None else self.width
414 height = height if height is not None else self.height
416 if (size == self.size
417 and count == self.count
418 and width == self.width
419 and height == self.height):
433 start = start_block*self.size + start_off
434 stop = stop_block*self.size + stop_off
435 start = m.floor(start * len(self.blocks)/(self.size*self.count))
436 stop = m.ceil(stop * len(self.blocks)/(self.size*self.count))
441 self.blocks[start:stop],
444 self.size = size
445 self.count = count
446 self.width = width
447 self.height = height
448 self.blocks = blocks
450 def draw(self, row, *,
463 max_wear = max(b.wear for b in self.blocks)
467 grid = [None]*(self.width*self.height)
469 hilbert_curve(self.width, self.height),
470 self.blocks):
471 grid[x + y*self.width] = b
473 grid = [None]*(self.width*self.height)
475 lebesgue_curve(self.width, self.height),
476 self.blocks):
477 grid[x + y*self.width] = b
479 grid = self.blocks
484 if (braille and self.height < 4) or (dots and self.height < 2):
487 self.history = getattr(self, 'history', [])
488 self.history.append(grid)
490 if len(self.history)*self.height < needed_height:
497 self.width*self.height)
498 for h in self.history))
499 self.history = []
504 for x in range(0, self.width, 2):
508 b = grid[x+(2-1-(i%2)) + ((row*4)+(4-1-(i//2)))*self.width]
528 for x in range(self.width):
532 b = grid[x + ((row*2)+(2-1-i))*self.width]
551 for x in range(self.width):
552 line.append(grid[x + row*self.width].draw(