+ self.resultObj.AppendMessage(self._indent + s)
+ self._line += 1
+
+ def _doColor(self):
+ if self.color is True:
+ return True;
+ return self.color is None and self.isatty
+
+ def _needsHeader(self):
+ if self._header is None:
+ return False
+ if self._lastHeader is None:
+ return True
+ if not self.isatty:
+ return False
+ return self._line - self._lastHeader > 40
+
+ def indent(self):
+ return IndentScope(self)
+
+ def table(self, header, indent = False):
+ return HeaderScope(self, header, indent)
+
+ def format(self, s, *args, **kwargs):
+ if self._doColor():
+ kwargs['VT'] = VT
+ else:
+ kwargs['VT'] = NOVT()
+
+ return s.format(*args, **kwargs)
+
+ def error(self, s, *args, **kwargs):
+ print self.format("{cmd.cmd_name}: {VT.Red}"+s+"{VT.Default}", cmd=self, *args, **kwargs)
+
+ def write(self, s):
+ """ Handler for all commands output. By default just print to stdout """
+
+ s = self._buffer + s
+
+ while s.find('\n') != -1:
+ l, s = s.split("\n", 1)
+ if self.FILTER:
+ if not self.reg.search(l):
+ continue
+ if self._doColor():
+ l = self.reg.sub(VT.Underline + r"\g<0>" + VT.EndUnderline, l);
+
+ if len(l) and self._needsHeader():
+ for hdr in self._header.split("\n"):
+ self._write(self.format("{VT.Bold}{:s}{VT.EndBold}", hdr))
+ self._lastHeader = self._line
+
+ self._write(l)
+
+ self._buffer = s