Beispiel #1
0
 def _format(self, prefix, message, color):
     """
     Rewrap the message; but preserve newlines, and don't touch any
     lines that begin with spaces.
     """
     lines = message.split('\n')
     startindex = indent = len(prefix)
     for i in range(len(lines)):
         if lines[i].startswith(' '):
             lines[i] = ' '*(indent-startindex) + lines[i] + '\n'
         else:
             width = self.term.COLS - 5 - 4*len(self._message_blocks)
             lines[i] = wordwrap(lines[i], indent, width, startindex, '\\/')
         startindex = 0
     return color+prefix+self.term.NORMAL+''.join(lines)
Beispiel #2
0
 def _format(self, prefix, message, color):
     """
     Rewrap the message; but preserve newlines, and don't touch any
     lines that begin with spaces.
     """
     lines = message.split('\n')
     startindex = indent = len(prefix)
     for i in range(len(lines)):
         if lines[i].startswith(' '):
             lines[i] = ' ' * (indent - startindex) + lines[i] + '\n'
         else:
             width = self.term.COLS - 5 - 4 * len(self._message_blocks)
             lines[i] = wordwrap(lines[i], indent, width, startindex, '\\/')
         startindex = 0
     return color + prefix + self.term.NORMAL + ''.join(lines)
Beispiel #3
0
 def end_block(self):
     header, messages = self._message_blocks.pop()
     if messages:
         width = self.term.COLS - 5 - 2*len(self._message_blocks)
         prefix = self.term.CYAN+self.term.BOLD+'| '+self.term.NORMAL
         divider = (self.term.CYAN+self.term.BOLD+'+'+'-'*(width-1)+
                    self.term.NORMAL)
         # Mark up the header:
         header = wordwrap(header, right=width-2, splitchars='\\/').rstrip()
         header = '\n'.join([prefix+self.term.CYAN+l+self.term.NORMAL
                             for l in header.split('\n')])
         # Construct the body:
         body = ''
         for message in messages:
             if message.endswith('\n'): body += message
             else: body += message+'\n'
         # Indent the body:
         body = '\n'.join([prefix+'  '+l for l in body.split('\n')])
         # Put it all together:
         message = divider + '\n' + header + '\n' + body + '\n'
         self._report(message)
Beispiel #4
0
 def end_block(self):
     header, messages = self._message_blocks.pop()
     if messages:
         width = self.term.COLS - 5 - 2 * len(self._message_blocks)
         prefix = self.term.CYAN + self.term.BOLD + '| ' + self.term.NORMAL
         divider = (self.term.CYAN + self.term.BOLD + '+' + '-' *
                    (width - 1) + self.term.NORMAL)
         # Mark up the header:
         header = wordwrap(header, right=width - 2,
                           splitchars='\\/').rstrip()
         header = '\n'.join([
             prefix + self.term.CYAN + l + self.term.NORMAL
             for l in header.split('\n')
         ])
         # Construct the body:
         body = ''
         for message in messages:
             if message.endswith('\n'): body += message
             else: body += message + '\n'
         # Indent the body:
         body = '\n'.join([prefix + '  ' + l for l in body.split('\n')])
         # Put it all together:
         message = divider + '\n' + header + '\n' + body + '\n'
         self._report(message)
Beispiel #5
0
 def log(self, level, message):
     message = wordwrap(str(message)).rstrip() + '\n'
     if self._message_blocks:
         self._message_blocks[-1][-1].append((level, message))
     else:
         self._messages.append((level, message))
Beispiel #6
0
 def log(self, level, message):
     message = wordwrap(str(message)).rstrip() + '\n'
     if self._message_blocks:
         self._message_blocks[-1][-1].append( (level, message) )
     else:
         self._messages.append( (level, message) )