@if (Entries.Count == 0)
{
}
else
{
}
@code {
[Parameter, EditorRequired] public IReadOnlyList Entries { get; set; } = Array.Empty();
[Parameter] public int SelectedIndex { get; set; }
[Parameter] public EventCallback SelectedIndexChanged { get; set; }
[Parameter] public int ViewportRows { get; set; } = 5;
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 GetSelectedDescription()
{
if (Entries.Count == 0)
{
return "Runtime enable/disable settings are unavailable.";
}
var selected = Entries[Math.Clamp(SelectedIndex, 0, Entries.Count - 1)];
return selected.Description;
}
private string FormatEntry(int index)
{
var entry = Entries[index];
var indent = new string(' ', entry.Depth * 4);
var checkbox = entry.IsChecked ? "[x]" : "[ ]";
var disabledSuffix = entry.Kind == SettingsEntryKind.Tool && !entry.IsModuleEnabled ? " (module off)" : string.Empty;
string text;
if (entry.Kind == SettingsEntryKind.Module)
{
var expander = entry.IsExpanded ? "[-]" : "[+]";
text = $"{expander} {checkbox} {entry.Label}";
}
else
{
text = $"{indent}{checkbox} {entry.Label}{disabledSuffix}";
}
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)] + "...";
}
}