コード例 #1
0
        /// <summary>
        /// Writes the prompt to the console.
        /// </summary>
        /// <param name="console">The console to write the prompt to.</param>
        private void WritePrompt(IAnsiConsole console)
        {
            if (console is null)
            {
                throw new ArgumentNullException(nameof(console));
            }

            var builder = new StringBuilder();

            builder.Append(_prompt.TrimEnd());

            if (ShowChoices && Choices.Count > 0)
            {
                var choices = string.Join("/", Choices.Select(choice => TextPrompt <T> .GetTypeConverter().ConvertToInvariantString(choice)));
                builder.AppendFormat(CultureInfo.InvariantCulture, " [blue][[{0}]][/]", choices);
            }

            if (ShowDefaultValue && DefaultValue != null)
            {
                builder.AppendFormat(
                    CultureInfo.InvariantCulture,
                    " [green]({0})[/]",
                    TextPrompt <T> .GetTypeConverter().ConvertToInvariantString(DefaultValue.Value));
            }

            var markup = builder.ToString().Trim();

            if (!markup.EndsWith("?", StringComparison.OrdinalIgnoreCase) &&
                !markup.EndsWith(":", StringComparison.OrdinalIgnoreCase))
            {
                markup += ":";
            }

            console.Markup(markup + " ");
        }
コード例 #2
0
    public ProjectInformation?Select()
    {
        var examples = _finder.FindExamples();

        if (examples.Count == 0)
        {
            _console.Markup("[yellow]No examples could be found.[/]");
            return(null);
        }

        var prompt = new SelectionPrompt <string>();
        var groups = examples.GroupBy(ex => ex.Group);

        if (groups.Count() == 1)
        {
            prompt.AddChoices(examples.Select(x => x.Name));
        }
        else
        {
            var noGroupExamples = new List <string>();

            foreach (var group in groups)
            {
                if (string.IsNullOrEmpty(group.Key))
                {
                    noGroupExamples.AddRange(group.Select(x => x.Name));
                }
                else
                {
                    prompt.AddChoiceGroup(
                        group.Key,
                        group.Select(x => x.Name));
                }
            }

            if (noGroupExamples.Count > 0)
            {
                prompt.AddChoices(noGroupExamples);
            }
        }

        var example = AnsiConsole.Prompt(prompt
                                         .Title("[yellow]Choose example to run[/]")
                                         .MoreChoicesText("[grey](Move up and down to reveal more examples)[/]")
                                         .Mode(SelectionMode.Leaf));

        return(examples.FirstOrDefault(x => x.Name == example));
    }
コード例 #3
0
        public void OnMutantTested(IReadOnlyMutant result)
        {
            switch (result.ResultStatus)
            {
            case MutantStatus.Killed:
                _console.Write(".");
                break;

            case MutantStatus.Survived:
                _console.Markup("[Red]S[/]");
                break;

            case MutantStatus.Timeout:
                _console.Write("T");
                break;
            }
            ;
        }
コード例 #4
0
ファイル: TextPrompt.cs プロジェクト: gitfool/spectre.console
    /// <summary>
    /// Writes the prompt to the console.
    /// </summary>
    /// <param name="console">The console to write the prompt to.</param>
    private void WritePrompt(IAnsiConsole console)
    {
        if (console is null)
        {
            throw new ArgumentNullException(nameof(console));
        }

        var builder = new StringBuilder();

        builder.Append(_prompt.TrimEnd());

        var appendSuffix = false;

        if (ShowChoices && Choices.Count > 0)
        {
            appendSuffix = true;
            var converter    = Converter ?? TypeConverterHelper.ConvertToString;
            var choices      = string.Join("/", Choices.Select(choice => converter(choice)));
            var choicesStyle = ChoicesStyle?.ToMarkup() ?? "blue";
            builder.AppendFormat(CultureInfo.InvariantCulture, " [{0}][[{1}]][/]", choicesStyle, choices);
        }

        if (ShowDefaultValue && DefaultValue != null)
        {
            appendSuffix = true;
            var converter         = Converter ?? TypeConverterHelper.ConvertToString;
            var defaultValueStyle = DefaultValueStyle?.ToMarkup() ?? "green";

            builder.AppendFormat(
                CultureInfo.InvariantCulture,
                " [{0}]({1})[/]",
                defaultValueStyle,
                IsSecret ? "******" : converter(DefaultValue.Value));
        }

        var markup = builder.ToString().Trim();

        if (appendSuffix)
        {
            markup += ":";
        }

        console.Markup(markup + " ");
    }
コード例 #5
0
    public void List()
    {
        var examples = _finder.FindExamples();

        if (examples.Count == 0)
        {
            _console.Markup("[yellow]No examples could be found.[/]");
            return;
        }

        _console.WriteLine();

        var rows = new Grid().Collapse();

        rows.AddColumn();
        foreach (var group in examples.GroupBy(ex => ex.Group))
        {
            rows.AddRow(CreateTable(group.Key, group));
            rows.AddEmptyRow();
        }

        _console.Write(rows);
        _console.MarkupLine("Type [blue]dotnet example --help[/] for help");
    }