def render(self, width, height, terminal): n = 0 inputLines = self.text.splitlines() outputLines = [] while inputLines: if self.longLines == self.WRAP: wrappedLines = tptext.greedyWrap(inputLines.pop(0), width) outputLines.extend(wrappedLines or ['']) else: outputLines.append(inputLines.pop(0)[:width]) if len(outputLines) >= height: break for n, L in enumerate(outputLines[:height]): terminal.cursorPosition(0, n) terminal.write(L)
def failWhale(error, columns=80): if isinstance(error, WebError): emsg = "{0.status} {0.message}".format(error) else: emsg = str(error) width = columns - _whalePaddingLen lines = [] for line in emsg.splitlines(): lines.extend(greedyWrap(line, width)) lineLength = max(map(len, lines)) msg = "{0}|\n|{0}".format((_whalePaddingLen/2)*" ").join( map(lambda l: "{0:{1}}".format(l, lineLength), lines)) return _whaleFmt.format( space = " "*lineLength, lines = "_"*lineLength, length = lineLength, body = msg)
def render(self, width, height, terminal): n = 0 inputLines = self.text.splitlines() outputLines = [] while inputLines: if self.longLines == self.WRAP: line = inputLines.pop(0) if not isinstance(line, str): line = line.decode("utf-8") wrappedLines = [] for wrappedLine in tptext.greedyWrap(line, width): if not isinstance(wrappedLine, bytes): wrappedLine = wrappedLine.encode("utf-8") wrappedLines.append(wrappedLine) outputLines.extend(wrappedLines or [b'']) else: outputLines.append(inputLines.pop(0)[:width]) if len(outputLines) >= height: break for n, L in enumerate(outputLines[:height]): terminal.cursorPosition(0, n) terminal.write(L)
def _printMessage(self, msg, screenNameWidth=14): if self.config["long"]: fmt = "--- {0.user.screen_name:{2}} {0.created_at} [{0.id}]\n" \ " {1}" paddingLen = 4 else: fmt = "{0.user.screen_name:{2}} {1}" paddingLen = screenNameWidth + 2 width = self.config.parent["COLUMNS"] - paddingLen log.trace("Formatting {0} at {1} characters.".format( "long message" if self.config["long"] else "message", width)) joiner = "\n" + (" " * paddingLen) text = joiner.join(greedyWrap(msg.text, width)) try: print fmt.format(msg, text, screenNameWidth) except UnicodeEncodeError, uee: # Ignore messages with Unicode errors. Sahri Charlie. log.warn("Unicode error printing message {0.id}".format(msg))
def _wrapText(self, text, paddingLen): width = self.config.parent["COLUMNS"] - paddingLen joiner = "\n" + str(" " * paddingLen) return joiner.join(greedyWrap(text, width))
def handle_TAB1(self): head_line, tail_line = self.currentLineBuffer() search_line = head_line completer = Completer(self.namespace) def find_term(line): chrs = [] attr = False for c in reversed(line): if c == '.': attr = True if not c.isalnum() and c not in ('_', '.'): break chrs.insert(0, c) return ''.join(chrs), attr search_term, attrQ = find_term(search_line) if not search_term: return manhole.Manhole.handle_TAB(self) if attrQ: matches = completer.attr_matches(search_term) matches = list(set(matches)) matches.sort() else: matches = completer.global_matches(search_term) def same(*args): if len(set(args)) == 1: return args[0] return False def progress(rem): letters = [] while True: letter = same(*[elm.pop(0) for elm in rem if elm]) if letter: letters.append(letter) else: return letters if matches is not None: rem = [list(s.partition(search_term)[2]) for s in matches] more_letters = progress(rem) # print 'LEN MATCHES', len(matches), more_letters # if len(matches) == 1: # length = len(search_line) # self.lineBuffer = self.lineBuffer[:-length] # self.lineBuffer.extend([matches[0]]+more_letters) # self.lineBufferIndex = len(self.lineBuffer) if len(matches) > 1: match_str = "%s \t\t" * len(matches) % tuple(matches) match_rows = text.greedyWrap(match_str) # line = self.lineBuffer self.terminal.nextLine() self.terminal.saveCursor() for row in match_rows: self.addOutput(row, True) if tail_line: self.terminal.cursorBackward(len(tail_line)) self.lineBufferIndex -= len(tail_line) # self.addOutput("".join(more_letters), True) self._deliverBuffer(more_letters)