| 203 | return state |
| 204 | |
| 205 | class ColumnPrinter: |
| 206 | def __init__(self): |
| 207 | self.columns = [] |
| 208 | |
| 209 | def append(self, data): |
| 210 | self.columns.append(data) |
| 211 | |
| 212 | def __str__(self): |
| 213 | row_count = 1 |
| 214 | for data in self.columns: |
| 215 | row_count = max(row_count, len(data.splitlines()) + 1) |
| 216 | |
| 217 | rows = [""] * row_count |
| 218 | for j in range(row_count): |
| 219 | for i, data in enumerate(self.columns): |
| 220 | line = data.splitlines()[max(0, j - 1)] |
| 221 | if j == 0: |
| 222 | padding = " " * (len(line) // 2) |
| 223 | rows[j] += padding + str(i) + padding |
| 224 | else: |
| 225 | rows[j] += line |
| 226 | |
| 227 | if (i + 1) < len(self.columns): |
| 228 | rows[j] += " | " |
| 229 | |
| 230 | return "\n".join(rows) |
| 231 | |
| 232 | |
| 233 | grid = Grid(5, 9) |