Skip to content

Rows sizing is inconsistent #1188

@rcdailey

Description

@rcdailey

Information

  • OS: Windows
  • Version: 0.46
  • Terminal: Powershell, Windows Rider Integrated Terminal

Describe the bug

Sizing of Panel is confusing and buggy:

  • There's no way to make the panel fit its contents. Instead, it expands the full width of the terminal (which looks ugly)
  • Depending on the content I put in it, the size behavior changes.

To Reproduce

See MCVE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Spectre.Console;
using Spectre.Console.Cli;
using Spectre.Console.Rendering;

namespace ConsoleApp1;

public enum SupportedServices { Radarr, Sonarr }

public record MyConfig(string InstanceName, SupportedServices Service);

public class ConfigLocalLister : Command<ConfigLocalLister.CliSettings>
{
    public class CliSettings : CommandSettings
    {

    }

    private readonly IAnsiConsole _console;

    public ConfigLocalLister(IAnsiConsole console)
    {
        _console = console;
    }

    private void List()
    {
        var appDataDir = @"C:\appDataDir";
        var tree = new Tree(appDataDir);

        var configsDict = new Dictionary<string, MyConfig[]>
        {
            {
                "radarr.yml", new[]
                {
                    new MyConfig("instance1", SupportedServices.Radarr),
                }
            },
            {
                "sonarr.yml", new[]
                {
                    new MyConfig("instance2", SupportedServices.Sonarr),
                    new MyConfig("instance3", SupportedServices.Sonarr),
                }
            },
            {
                "both.yml", new[]
                {
                    new MyConfig("instance4", SupportedServices.Radarr),
                    new MyConfig("instance5", SupportedServices.Radarr),
                    new MyConfig("instance6", SupportedServices.Sonarr),
                    new MyConfig("instance7", SupportedServices.Sonarr),
                }
            },
        };

        foreach (var configPath in configsDict.Keys)
        {
            var configs = configsDict[configPath];

            var rows = new List<IRenderable>();
            BuildInstanceTree(rows, configs, SupportedServices.Radarr);
            BuildInstanceTree(rows, configs, SupportedServices.Sonarr);

            if (!rows.Any())
            {
                rows.Add(new Markup("([red]Empty[/])"));
            }

            var rowsWidget = new Rows(rows);
            var panel = new Panel(rowsWidget)
                .Header(configPath);

            tree.AddNode(panel);
        }

        _console.WriteLine();
        _console.Write(tree);
    }

    private static void BuildInstanceTree(
        ICollection<IRenderable> rows,
        MyConfig[] registry,
        SupportedServices service)
    {
        var configs = registry.Where(x => x.Service == service).ToList();
        if (!configs.Any())
        {
            return;
        }

        var tree = new Tree(service.ToString());
        tree.AddNodes(configs.Select(c =>
            Markup.FromInterpolated($"[blue]{c.InstanceName}[/]")));

        if (rows.Any())
        {
            // This causes the size of the panel to adjust to the length of this line
            rows.Add(new Text("---------------------------"));
        }

        rows.Add(tree);
    }

    public override int Execute(CommandContext context, CliSettings settings)
    {
        List();
        return 0;
    }
}

public static class Program
{
    public static void Main(string[] args)
    {
        var app = new CommandApp();
        app.Configure(c =>
        {
            c.AddCommand<ConfigLocalLister>("list");
        });

        app.Run(args);
    }
}

Expected behavior

  1. There should be a way to tell the panel to fit its contents
  2. The third panel in the tree is sized inconsistently; the inconsistency is the bug but I don't know what the actual expected sizing behavior is.

Screenshots

image

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions