def test__cli__helpers__wrap_field_c(): """Test simple wrapping.""" dct = wrap_field("how now brn cow", "How Now Brown Cow", width=25) assert dct["label_list"] == ["how now", "brn cow"] assert dct["label_width"] == 7 assert dct["val_list"] == ["How Now Brown", "Cow"] assert dct["lines"] == 2
def test__cli__helpers__wrap_field_c(): """ Simple wrap test """ dct = wrap_field('how now brn cow', 'How Now Brown Cow', width=25) assert dct['label_list'] == ['how now', 'brn cow'] assert dct['label_width'] == 7 assert dct['val_list'] == ['How Now Brown', 'Cow'] assert dct['lines'] == 2
def test__cli__helpers__wrap_field_a(): """Test simple wrapping.""" dct = wrap_field("abc", "How Now Brown Cow", width=40) assert dct["label_list"] == ["abc"] assert dct["val_list"] == ["How Now Brown Cow"] assert "sep_char" in dct assert dct["lines"] == 1 assert dct["label_width"] == 3
def test__cli__helpers__wrap_field_a(): """ Simple wrap test """ dct = wrap_field('abc', 'How Now Brown Cow', width=40) assert dct['label_list'] == ['abc'] assert dct['val_list'] == ['How Now Brown Cow'] assert 'sep_char' in dct assert dct['lines'] == 1 assert dct['label_width'] == 3
def cli_table_row( self, fields: List[Tuple[str, str]], col_width, max_label_width=10, sep_char=": ", divider_char=" ", label_color=Color.lightgrey, val_align="right", ) -> str: """Make a row of a CLI table, using wrapped values.""" # Do some intel first cols = len(fields) last_col_idx = cols - 1 wrapped_fields = [ wrap_field( field[0], field[1], width=col_width, max_label_width=max_label_width, sep_char=sep_char, ) for field in fields ] max_lines = max(fld["lines"] for fld in wrapped_fields) last_line_idx = max_lines - 1 # Make some text buff = StringIO() for line_idx in range(max_lines): for col_idx in range(cols): # Assume we pad labels left and values right fld = wrapped_fields[col_idx] ll = fld["label_list"] vl = fld["val_list"] buff.write( self.colorize( pad_line( ll[line_idx] if line_idx < len(ll) else "", width=fld["label_width"], ), color=label_color, )) if line_idx == 0: buff.write(sep_char) else: buff.write(" " * len(sep_char)) buff.write( pad_line( vl[line_idx] if line_idx < len(vl) else "", width=fld["val_width"], align=val_align, )) if col_idx != last_col_idx: buff.write(divider_char) elif line_idx != last_line_idx: buff.write("\n") return buff.getvalue()
def test__cli__helpers__wrap_field_b(): """Test simple wrapping with overlap avoidance.""" dct = wrap_field("abc", "How Now Brown Cow", width=23) assert dct["label_list"] == ["abc"] assert dct["val_list"] == ["How Now Brown Cow"] assert dct["label_width"] == 3
def test__cli__helpers__wrap_field_b(): """ Simple wrap test, but testing overlap allowance """ dct = wrap_field('abc', 'How Now Brown Cow', width=23) assert dct['label_list'] == ['abc'] assert dct['val_list'] == ['How Now Brown Cow'] assert dct['label_width'] == 3
def test__cli__helpers__wrap_field_b(): """Test simple wrapping with overlap avoidance.""" dct = wrap_field('abc', 'How Now Brown Cow', width=23) assert dct['label_list'] == ['abc'] assert dct['val_list'] == ['How Now Brown Cow'] assert dct['label_width'] == 3