-
I would like to use the tree (text would be enough) to enrich the selection prompt with more information. That's roughly how I would imagine the representation. this is my source code i'm playing with but it doesn't work. using System; namespace SpectreConsoleTest
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Is there a particular reason why you're trying to convert a tree to a prompt? When you add child-nodes to a For example, the code using System;
using Spectre.Console;
namespace SpectreConsoleTest
{
public static class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Welcome to the rental park of fun vehicles.");
Console.WriteLine("We have everything you always wanted to drive.");
Console.WriteLine();
var prompt = new SelectionPrompt<string>
{
PageSize = 10,
Title = "What's your [blue]favorite fun vehicle[/]?",
Mode = SelectionMode.Leaf
};
var rootCaterpillar = prompt.AddChoice("Caterpillar D8T");
// Add some nodes
var fooCaterpillar = rootCaterpillar.AddChild("[yellow]Engine[/]");
fooCaterpillar.AddChild("Engine Model Cat C15");
fooCaterpillar.AddChild("354 HP");
var barCaterpillar = rootCaterpillar.AddChild("[yellow]Body shape[/]");
barCaterpillar.AddChild("Operating Weight 87600 lb");
barCaterpillar.AddChild("Yellow");
var rootKraussMaffei = prompt.AddChoice("Krauss-Maffei Leopard 2");
// Add some nodes
var fooKraussMaffei = rootKraussMaffei.AddChild("[yellow]Engine[/]");
fooKraussMaffei.AddChild("12-Zylinder-Dieselengine MTU");
fooKraussMaffei.AddChild("CO2 emissions don't care");
var barKraussMaffei = rootKraussMaffei.AddChild("[yellow]Military equipment[/]");
barKraussMaffei.AddChild("Laser sword");
barKraussMaffei.AddChild("Full rotating tower");
var rentalVehicle = AnsiConsole.Prompt(prompt);
AnsiConsole.MarkupLine($"You selected [green]{rentalVehicle}[/]");
}
}
} produces a prompt like: |
Beta Was this translation helpful? Give feedback.
-
@nils-a Thank you for your prompt reply. In my invented example, only the "Caterpillar D8T" and "Krauss-Maffei Leopard 2" vehicles can be rented. For the user (especially the newcomers) I would like to give a few more meta data (in the tree view) to get a feel for what kind of vehicle it is. Could also think of network printers that are standing around somewhere in the company. And the metadata says where it is located in the company. After printing twice, the user no longer reads this and the root name is sufficient, e.g. "Brother MFC-7820N USB Printer" but your idea would work if there was something like that
but there is currently no RootOnly |
Beta Was this translation helpful? Give feedback.
@nils-a Thank you for your prompt reply.
In my invented example, only the "Caterpillar D8T" and "Krauss-Maffei Leopard 2" vehicles can be rented. For the user (especially the newcomers) I would like to give a few more meta data (in the tree view) to get a feel for what kind of vehicle it is.
Could also think of network printers that are standing around somewhere in the company. And the metadata says where it is located in the company. After printing twice, the user no longer reads this and the root name is sufficient, e.g. "Brother MFC-7820N USB Printer"
but your idea would work if there was something like that