This function processes a quote and returns a string that is ready to be used in the fancy banner.
(quote, author, max_len=78)
| 539 | |
| 540 | |
| 541 | def _prepare_quote(quote, author, max_len=78): |
| 542 | # type: (str, str, int) -> List[str] |
| 543 | """This function processes a quote and returns a string that is ready |
| 544 | to be used in the fancy banner. |
| 545 | |
| 546 | """ |
| 547 | _quote = quote.split(' ') |
| 548 | max_len -= 6 |
| 549 | lines = [] |
| 550 | cur_line = [] # type: List[str] |
| 551 | |
| 552 | def _len(line): |
| 553 | # type: (List[str]) -> int |
| 554 | return sum(len(elt) for elt in line) + len(line) - 1 |
| 555 | while _quote: |
| 556 | if not cur_line or (_len(cur_line) + len(_quote[0]) - 1 <= max_len): |
| 557 | cur_line.append(_quote.pop(0)) |
| 558 | continue |
| 559 | lines.append(' | %s' % ' '.join(cur_line)) |
| 560 | cur_line = [] |
| 561 | if cur_line: |
| 562 | lines.append(' | %s' % ' '.join(cur_line)) |
| 563 | cur_line = [] |
| 564 | lines.append(' | %s-- %s' % (" " * (max_len - len(author) - 5), author)) |
| 565 | return lines |
| 566 | |
| 567 | |
| 568 | def get_fancy_banner(mini: Optional[bool] = None) -> str: |
no test coverage detected
searching dependent graphs…