- Добавить GlobalKeyboardService — выделенный поток с блокирующим Console.ReadKey, единственный источник клавишных событий для TUI - Убрать FocusManager из App.razor: перехватывал Tab до компонентов - Удалить @onkeydown с <Select>: RazorConsole не пробрасывает Tab/стрелки через этот механизм - Использовать FocusedValue вместо Value в Select для корректной подсветки - Обновить CLAUDE.md и AGENTS.md: архитектура TUI, RazorConsole gotchas - Добавить docs/tui_log.md: разбор проблемы и справочник по RazorConsole Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
132 lines
4.6 KiB
Plaintext
132 lines
4.6 KiB
Plaintext
@using LazyBear.MCP.Services.Logging
|
|
|
|
<Rows>
|
|
<Markup Content="Runtime Logs" Foreground="@UiPalette.Text" Decoration="@Spectre.Console.Decoration.Bold" />
|
|
<Markup Content="Left/Right change level. Up/Down move. PageUp/PageDown/Home/End scroll." Foreground="@UiPalette.TextMuted" />
|
|
<Markup Content=" " />
|
|
|
|
<Columns>
|
|
@foreach (var filter in Filters)
|
|
{
|
|
var isActive = string.Equals(filter, SelectedFilter, StringComparison.Ordinal);
|
|
<Markup Content="@($" {filter} ")"
|
|
Foreground="@(isActive ? UiPalette.SelectionForeground : UiPalette.Text)"
|
|
Background="@(isActive ? UiPalette.AccentSoft : UiPalette.SurfaceMuted)"
|
|
Decoration="@(isActive ? Spectre.Console.Decoration.Bold : Spectre.Console.Decoration.None)" />
|
|
<Markup Content=" " />
|
|
}
|
|
</Columns>
|
|
|
|
<Markup Content=" " />
|
|
|
|
@if (Entries.Count == 0)
|
|
{
|
|
<Border BorderColor="@UiPalette.Frame" BoxBorder="@Spectre.Console.BoxBorder.Rounded" Padding="@(new Spectre.Console.Padding(0, 0, 0, 0))">
|
|
<Markup Content="No log entries yet." Foreground="@UiPalette.TextDim" />
|
|
</Border>
|
|
}
|
|
else
|
|
{
|
|
<Select TItem="int"
|
|
Options="@GetOptions()"
|
|
Value="@GetNormalizedIndex()"
|
|
FocusedValue="@GetNormalizedIndex()"
|
|
Formatter="@FormatEntry"
|
|
Expand="true"
|
|
BorderStyle="@Spectre.Console.BoxBorder.Rounded"
|
|
SelectedIndicator="@('>')" />
|
|
}
|
|
|
|
<Markup Content=" " />
|
|
<Markup Content="@GetDetailsHeader()" Foreground="@UiPalette.TextMuted" />
|
|
<Markup Content="@GetDetailsText()" Foreground="@UiPalette.Text" />
|
|
</Rows>
|
|
|
|
@code {
|
|
private static readonly string[] Filters = ["All", "Info", "Warn", "Error"];
|
|
|
|
[Parameter, EditorRequired] public IReadOnlyList<LogEntry> Entries { get; set; } = Array.Empty<LogEntry>();
|
|
[Parameter] public int SelectedIndex { get; set; }
|
|
[Parameter] public EventCallback<int> SelectedIndexChanged { get; set; }
|
|
[Parameter] public string SelectedFilter { get; set; } = "All";
|
|
[Parameter] public int ViewportRows { get; set; } = 5;
|
|
[Parameter] public bool IsStickyToBottom { get; set; }
|
|
|
|
private int[] GetOptions() => Enumerable.Range(0, Entries.Count).ToArray();
|
|
|
|
private int GetNormalizedIndex() => Entries.Count == 0 ? 0 : Math.Clamp(SelectedIndex, 0, Entries.Count - 1);
|
|
|
|
private string GetDetailsHeader()
|
|
{
|
|
if (Entries.Count == 0)
|
|
{
|
|
return $"Filter: {SelectedFilter}";
|
|
}
|
|
|
|
var selected = Entries[Math.Clamp(SelectedIndex, 0, Entries.Count - 1)];
|
|
var position = Math.Clamp(SelectedIndex, 0, Entries.Count - 1) + 1;
|
|
var sticky = IsStickyToBottom ? "sticky" : "manual";
|
|
return $"{position}/{Entries.Count} | {selected.Timestamp:HH:mm:ss} | {selected.Level} | {selected.ShortCategory} | {sticky}";
|
|
}
|
|
|
|
private string GetDetailsText()
|
|
{
|
|
if (Entries.Count == 0)
|
|
{
|
|
return "Incoming log entries will appear here.";
|
|
}
|
|
|
|
var selected = Entries[Math.Clamp(SelectedIndex, 0, Entries.Count - 1)];
|
|
var details = string.IsNullOrWhiteSpace(selected.Exception)
|
|
? selected.Message
|
|
: $"{selected.Message} | {selected.Exception}";
|
|
|
|
return Fit(details, Math.Max(Console.WindowWidth - 12, 32));
|
|
}
|
|
|
|
private static Spectre.Console.Color GetLevelColor(LogEntry entry) => entry.Level switch
|
|
{
|
|
LogLevel.Error or LogLevel.Critical => UiPalette.Danger,
|
|
LogLevel.Warning => UiPalette.Warning,
|
|
LogLevel.Information => UiPalette.Text,
|
|
_ => UiPalette.TextMuted
|
|
};
|
|
|
|
private string FormatEntry(int index)
|
|
{
|
|
var entry = Entries[index];
|
|
var level = entry.Level switch
|
|
{
|
|
LogLevel.Error => "ERR",
|
|
LogLevel.Critical => "CRT",
|
|
LogLevel.Warning => "WRN",
|
|
LogLevel.Information => "INF",
|
|
LogLevel.Debug => "DBG",
|
|
_ => "TRC"
|
|
};
|
|
|
|
var text = $"{entry.Timestamp:HH:mm:ss} {level,-3} {entry.ShortCategory,-18} {entry.Message}";
|
|
return Fit(text, Math.Max(Console.WindowWidth - 12, 32));
|
|
}
|
|
|
|
private static string Fit(string text, int width)
|
|
{
|
|
if (width <= 0)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
if (text.Length <= width)
|
|
{
|
|
return text.PadRight(width);
|
|
}
|
|
|
|
if (width <= 3)
|
|
{
|
|
return text[..width];
|
|
}
|
|
|
|
return text[..(width - 3)] + "...";
|
|
}
|
|
}
|