spectreconsole / spectre.console

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

MultilineTaskDescriptionColumn for Progress #261

Open Yaroshvitaliy opened 3 years ago

Yaroshvitaliy commented 3 years ago

It would be useful to implement MultilineTaskDescriptionColumn for Progress. This didn't help me for multiline description:

    public sealed class MultilineTaskDescriptionColumn : ProgressColumn
    {
        /// <inheritdoc/>
        protected internal override bool NoWrap => true;

        /// <inheritdoc/>
        public override IRenderable Render(RenderContext context, ProgressTask task, TimeSpan deltaTime)
        {
            //var text = task.Description?.RemoveNewLines()?.Trim();
            //return new Markup(text ?? string.Empty).Overflow(Overflow.Ellipsis).RightAligned();

            return new Markup(task.Description ?? string.Empty);
        }
    }

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

patriksvensson commented 3 years ago

@Yaroshvitaliy You will need to set "NoWrap" to false for that to work:

image

Yaroshvitaliy commented 3 years ago

@patriksvensson I tried NoWrap set to false but it didn't help me. I mean Environment.NewLine is not working.

Yaroshvitaliy commented 3 years ago

I can see the following code in ProgressTask:

description = description?.RemoveNewLines()?.Trim();
patriksvensson commented 3 years ago

Yeah, Environment.Newline is probably not working. It will wrap the text at the end of the column.

Yaroshvitaliy commented 3 years ago

Environment.Newline is what I need as a separator between lines, so could you reopen the issue since my original question is not answered? Maybe anoter string/object property can be added to ProgressTask so that it can be used in custom advabced columns?

kzu commented 3 months ago

I just created my own column as initially proposed and it worked like a charm:

    class MultilineTaskDescriptionColumn : ProgressColumn
    {
        public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime)
        {
            return new Markup(task.Description ?? string.Empty)
                .Overflow(Overflow.Ellipsis)
                .Justify(Justify.Left);
        }
    }

image

It would be nice if there was a Multiline property, say, to avoid the call to RemoveNewLines(), but it's no biggie IMO.