using Spectre.Console; namespace LazyBear.MCP.TUI; internal static class UiMetrics { public static int ConsoleWidth => Math.Max(ReadConsoleSize(ReadConsoleWidth, () => AnsiConsole.Profile.Width, 80), 1); public static int ConsoleHeight => Math.Max(ReadConsoleSize(ReadConsoleHeight, () => AnsiConsole.Profile.Height, 24), 1); private static int ReadConsoleSize(Func consoleReader, Func profileReader, int fallback) { try { var consoleValue = consoleReader(); if (consoleValue > 0) { return consoleValue; } } catch { // Игнорируем и пробуем fallback через профиль Spectre. } try { var profileValue = profileReader(); if (profileValue > 0) { return profileValue; } } catch { // Игнорируем и используем значение по умолчанию. } return fallback; } private static int ReadConsoleWidth() => Console.WindowWidth; private static int ReadConsoleHeight() => Console.WindowHeight; }