TUI: переработать shell и адаптацию layout
This commit is contained in:
43
LazyBear.MCP/TUI/UiMetrics.cs
Normal file
43
LazyBear.MCP/TUI/UiMetrics.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
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<int> consoleReader, Func<int> 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;
|
||||
}
|
||||
Reference in New Issue
Block a user