spacepaste

  1.  
  2. # Error: urwid.widget.WidgetError: Widget <ANSIColorCanvas selectable box widget> rendered (166 x 26) canvas when passed size (238, 65)!
  3. class ANSIColorCanvas(urwid.BoxWidget):
  4. def __init__(self):
  5. self.__super.__init__()
  6. self.term = None
  7. self.term_size = None
  8. self.term_modes = urwid.TermModes() # Compatibility with TermCanvas
  9. self.text = []
  10. def render(self, size, focus=False):
  11. if not self.term:
  12. width, height = size
  13. self.term = TermCanvas(width, height, self)
  14. self.term_size = size
  15. if len(self.text) > 0:
  16. self.term.addstr(self.text)
  17. self.text = []
  18. if self.term_size != size:
  19. self.term.resize(*size)
  20. return self.term
  21. def addtext(self, text):
  22. if not self.term or not self.term.autoscroll:
  23. self.text += text
  24. else:
  25. if len(self.text) > 0:
  26. self.term.addstr(self.text)
  27. self.text = []
  28. self.term.addstr(text)
  29. self._invalidate()
  30.