protected string BuildLine(string message, ConsoleTextPosition position) { // TODO: Handle when command is longer than the available width var msg = message; var width = _console.WindowWidth; var buffer = new string(' ', width); if (msg.Length >= width) { msg = message.Substring(0, width - 3) + "..."; } var line = ""; switch (position) { case ConsoleTextPosition.Left: line = msg + buffer; break; case ConsoleTextPosition.Right: line = buffer.Substring(msg.Length) + msg; break; default: var padding = (width - msg.Length) / 2; var pad = new string(' ', (int)padding); line = $"{pad}{msg}{pad}"; break; } if (line.Length > width) { line = line.Substring(0, width); } if (line.Length < width) { var padding = new string(' ', width - line.Length); line += padding; } return(line); }
public void WriteHeader(string msg, ConsoleColor?foregroundColor = null, ConsoleColor?backgroundColor = null, ConsoleTextPosition position = ConsoleTextPosition.Left) { var color = new ColorPair(_console, foregroundColor, backgroundColor); _console.CursorLeft = 0; //pos; _console.CursorTop = _originalState.WindowTop; var line = BuildLine(msg, position); this.Write(line, color); _originalState.ResetCursor(); }