Update Tab class

This commit is contained in:
Gino D
2023-01-06 15:46:48 +01:00
parent 9f4b0903be
commit cbcc6d2b8d

View File

@@ -35,7 +35,7 @@ import subprocess
from serial import Serial from serial import Serial
from dotenv import dotenv_values from dotenv import dotenv_values
from typing import List, Optional, Tuple, Union from typing import List, Optional, Tuple, Union, Iterable
BUFFER_SIZE: int = 256 BUFFER_SIZE: int = 256
@@ -45,7 +45,7 @@ class Tab():
colsize: List = [] colsize: List = []
text_to_right: List = [] text_to_right: List = []
def __init__(self, *colsizes: int, nb_columns: int = 0, bordered: bool = False): def __init__(self, *colsizes: int, align_to_right: Union[List, Tuple] = [], nb_columns: int = 0, bordered: bool = False):
self.colsize = list(colsizes) self.colsize = list(colsizes)
self.bordered = bordered self.bordered = bordered
auto_size = nb_columns - len(self.colsize) auto_size = nb_columns - len(self.colsize)
@@ -57,6 +57,9 @@ class Tab():
for i in range(len(self.colsize), nb_columns): for i in range(len(self.colsize), nb_columns):
self.colsize.append(column_size) self.colsize.append(column_size)
if isinstance(align_to_right, (list, tuple)):
self.align_to_right(*align_to_right)
def head(self, *texts: str): def head(self, *texts: str):
self.border('=') self.border('=')
self.line(*texts, bordered=False) self.line(*texts, bordered=False)
@@ -85,7 +88,7 @@ class Tab():
word = word.strip() word = word.strip()
next_sentence = ' '.join(lines[column_num][1][lineno] + [word]) next_sentence = ' '.join(lines[column_num][1][lineno] + [word])
if len(next_sentence) >= max_length: if len(next_sentence) > max_length:
lineno += 1 lineno += 1
lines[column_num][1].append([]) lines[column_num][1].append([])