X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=text_utils.py;h=d9bb652689f8b317af606b4334a9e09604518975;hb=76bc42a750b1c4d0ce81179337e47dc08db7b386;hp=0d07905be78daeb273995a0b5e131722e6e344d5;hpb=971d4ba141459f78d10d5770b9459d1ead7d49a0;p=python_utils.git diff --git a/text_utils.py b/text_utils.py index 0d07905..d9bb652 100644 --- a/text_utils.py +++ b/text_utils.py @@ -2,15 +2,14 @@ """Utilities for dealing with "text".""" -from collections import defaultdict import logging import math import sys +from collections import defaultdict from typing import Dict, Generator, List, NamedTuple, Optional from ansi import fg, reset - logger = logging.getLogger(__file__) @@ -127,9 +126,7 @@ def distribute_strings( subwidth = math.floor(width / len(strings)) retval = "" for string in strings: - string = justify_string( - string, width=subwidth, alignment=alignment, padding=padding - ) + string = justify_string(string, width=subwidth, alignment=alignment, padding=padding) retval += string while len(retval) > width: retval = retval.replace(' ', ' ', 1) @@ -151,13 +148,7 @@ def justify_string_by_chunk(string: str, width: int = 80, padding: str = " ") -> padding = padding[0] first, *rest, last = string.split() w = width - (len(first) + 1 + len(last) + 1) - ret = ( - first - + padding - + distribute_strings(rest, width=w, padding=padding) - + padding - + last - ) + ret = first + padding + distribute_strings(rest, width=w, padding=padding) + padding + last return ret