@@ -160,4 +160,49 @@ def text(self, x:int, y:int, text:str="TEXT", background_color:str="", text_colo
160160 return
161161
162162 for i in range (len (text )):
163- self .buffer [y ][x + i ] = Symbol (background_color = background_color , text_color = text_color , char = text [i ])
163+ self .point (x + i , y , Symbol (background_color = background_color , text_color = text_color , char = text [i ]))
164+
165+ def table (self , x , y , data , header ):
166+ if not data :
167+ print ("[ERROR][WINDOW][TABLE] Data empty" )
168+ return
169+
170+ data = data .copy ()
171+ header = header .copy ()
172+
173+ for i , row in enumerate (data ):
174+ for j , cell in enumerate (row ):
175+ data [i ][j ] = str (cell )
176+
177+ max_widths = []
178+ for title in header :
179+ max_widths .append (len (title ))
180+
181+ for i , row in enumerate (data ):
182+ for j , cell in enumerate (row ):
183+ max_widths [j ] = max (max_widths [j ], len (cell ))
184+
185+ width = sum (max_widths ) + len (max_widths ) + 1
186+
187+ # Нормализация длины заголовка
188+ for i , title in enumerate (header ):
189+ header [i ] += " " * (max_widths [i ] - len (title ))
190+
191+ # Нормализация длины информации
192+ for i , row in enumerate (data ):
193+ for j , cell in enumerate (row ):
194+ data [i ][j ] += " " * (max_widths [j ] - len (data [i ][j ]))
195+
196+ out_strings = []
197+
198+ out_strings .append ("-" * width )
199+ out_strings .append ("|" + "|" .join (header ) + "|" )
200+ out_strings .append ("-" * width )
201+
202+ for row in data :
203+ out_strings .append ("|" + "|" .join (row ) + "|" )
204+
205+ out_strings .append ("-" * width )
206+
207+ for i , string in enumerate (out_strings ):
208+ self .text (x , y + i , string )
0 commit comments