using System.Collections.Generic;
public static void Main() {
Logger.linesPerColumn = mB;
bool availableCellsExhaused = true;
for (a = 0, i = 0; a < mA; a++) {
for (b = 0; b < mB; b++, i++) {
if (b == 0) { a--; b = mB - 1; }
if (a < mA - 1 || b < mB) {
availableCellsExhaused = false;
for (int _i = i; _i < mA * mB; _i++) {
if (_i % mB == 0) Logger.NextColumn();
public static class Logger {
public static int columnWidth = 2;
public static int linesPerColumn = 5;
public readonly int width;
public readonly int height;
public List<char[]> logs;
public int x { get; private set; }
public int y { get; private set; }
public bool complete { get; private set; }
public Column(int width, int height) {
logs.Add(emptyLine.ToCharArray());
logs.Add(emptyLine.ToCharArray());
logs.Add(emptyLine.ToCharArray());
public bool Write(string text, out string remaining) {
if (complete) return complete;
while (y >= logs.Count - 1) {
logs.Add(emptyLine.ToCharArray());
if (x + 1 >= columnWidth) {
List<string> chunks = new();
for (int i = 0; i < text.Length; i++) {
if (!wasSpace || chunk.Length > 1) chunks.Add(chunk);
for (int p = 0; p < chunks.Count; p++) {
string stem = p == chunks.Count - 1 ? "" : " ";
WriteWord(chunks[p] + stem, remaining, out remaining);
if (complete) return complete;
private bool WriteWord(string text, string all, out string remaining) {
if (x + text.Length > columnWidth) {
for (int i = 0; i < text.Length; i++) {
for (int t = 0; t < 4; t++) {
remaining = remaining.Prim();
static List<List<char>> final;
public static void Init() {
string dottedLine = "- --- -";
for (int i = 0, l = 0; i < columnWidth; i++, l = (l + 1) % dottedLine.Length) {
headingLine += dottedLine[l];
writer = new(columnWidth, linesPerColumn);
final = new List<List<char>>();
static string headingLine;
public static void Header(string header) {
int headerLength = header.Length;
int half = (int)MathF.Round((float)columnWidth * 0.5f - (float)headerLength * 0.5f - 2);
for (int i = 0; i < half; i++) centered += " ";
WriteLine($"{centered}");
public static void WriteColumn(string text = "") {
if (writer.x == 0 && writer.y <= 1)
public static void WriteLine(string text = "") {
public static void Write(string text) {
if (writer.Write(text, out string remaining)) {
writer.Write(remaining, out string _);
public static void NextColumn() {
for (int i = 0; i <= writer.y; i++) {
var newLine = new List<char>();
for (int ci = 0; ci < cols; ci++) {
newLine.AddRange(emptyLine.ToCharArray());
final[i].AddRange(writer.logs[i]);
public static void NextLine() {
public static void Read() {
char[] topLine = new char[0];
char[] bottomLine = new char[0];
int size = final[0].Count;
topLine = new char[size];
bottomLine = new char[size];
for (int i = 0; i < size; i++) {
Console.WriteLine(new string(topLine));
for (int i = 0; i < final.Count; i++) {
Console.WriteLine(new string(final[i].ToArray()) + " ");
Console.WriteLine(new string(bottomLine));
public static string Prim(this string str)
=> str.Length > 2 ? str.Substring(1, str.Length - 1) : "";