spectreconsole / spectre.console

A .NET library that makes it easier to create beautiful console applications.
https://spectreconsole.net
MIT License
9.43k stars 498 forks source link

No title, one choice, wrong output #773

Open tamasgt opened 2 years ago

tamasgt commented 2 years ago

Hello,

Information

Describe the bug If there is one choice and the title is off, the output is bad.

To Reproduce

using Spectre.Console;
namespace Info;
public static class Program
{
    public static void Main()
    {
        AnsiConsole.Clear();

        var grid = new Grid()
            .AddColumn(new GridColumn().NoWrap().PadRight(4))
            .AddColumn()
            .AddRow("[b]Enrichers[/]", string.Join(", ", AnsiConsole.Profile.Enrichers))
            .AddRow("[b]Color system[/]", $"{AnsiConsole.Profile.Capabilities.ColorSystem}")
            .AddRow("[b]Unicode?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Unicode)}")
            .AddRow("[b]Supports ansi?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Ansi)}")
            .AddRow("[b]Supports links?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Links)}")
            .AddRow("[b]Legacy console?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Legacy)}")
            .AddRow("[b]Interactive?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Interactive)}")
            .AddRow("[b]Terminal?[/]", $"{YesNo(AnsiConsole.Profile.Out.IsTerminal)}")
            .AddRow("[b]Buffer width[/]", $"{AnsiConsole.Console.Profile.Width}")
            .AddRow("[b]Buffer height[/]", $"{AnsiConsole.Console.Profile.Height}")
            .AddRow("[b]Encoding[/]", $"{AnsiConsole.Console.Profile.Encoding.EncodingName}");

        AnsiConsole.Write(
            new Panel(grid)
                .Header("Information"));

        var selectionPromt = new SelectionPrompt<string>();
        // selectionPromt.Title("What's your [green]favorite fruit[/]?");
        selectionPromt.PageSize = 10;
        selectionPromt.MoreChoicesText = "[grey](Move up and down to reveal more fruits)[/]";
        // selectionPromt.AddChoice("Apple");
        selectionPromt.AddChoices(new[] { "Apple", "Béla" });

        // Ask for the user's favorite fruit
        var fruit = AnsiConsole.Prompt(selectionPromt);
    }

    private static string YesNo(bool value)
    {
        return value ? "Yes" : "No";
    }
}

Screenshots Snag_9a4c8c

Tamas


Please upvote :+1: this issue if you are interested in it.

phil-scott-78 commented 2 years ago

I was able to reproduce on my end, thanks for the report. If you get a chance to take a look at submitting a PR with a fix I'd be happy to review too

tamasgt commented 2 years ago

Thank you, unfortunately Spectre.console is new to me to do right PR. But I checked, I think that's the problem. In ListPrompt class:

Snag_3ba0a6

TonWin618 commented 2 months ago

this issue still exists. I modified some code in ListPrompt.cs, and it seems to run fine.

public async Task<ListPromptState<T>> Show(
 ...
  using (new RenderHookScope(_console, hook))
  ...
   //hook.Refresh();