Skip to content

Commit bbbb572

Browse files
Allow wrapping of status text
Closes #2152
1 parent a0913f8 commit bbbb572

5 files changed

Lines changed: 51 additions & 3 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+

2+
* Building AppHost...
3+
playground\HealthChecks\HealthChecksSa
4+
ndbox.AppHost\AppHost.csproj
5+
6+
* Building AppHost...
7+
playground\HealthChecks\HealthChecksSa
8+
ndbox.AppHost\AppHost.csproj
9+

src/Spectre.Console.Tests/Expectations/Public_API.Output.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,6 +3138,7 @@
31383138
public TaskDescriptionColumn() { }
31393139
public Spectre.Console.Justify Alignment { get; set; }
31403140
protected override bool NoWrap { get; }
3141+
public bool Wrap { get; set; }
31413142
public override Spectre.Console.Rendering.IRenderable Render(Spectre.Console.Rendering.RenderOptions options, Spectre.Console.ProgressTask task, System.TimeSpan deltaTime) { }
31423143
}
31433144
[System.Diagnostics.DebuggerDisplay("{_text,nq}")]

src/Spectre.Console.Tests/Unit/Live/StatusTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,29 @@ public Task Should_Render_Status_Correctly()
4848
// Then
4949
return Verifier.Verify(console.Output);
5050
}
51+
52+
[Fact]
53+
[Expectation("Render_LongText")]
54+
[GitHubIssue("https://github.com/spectreconsole/spectre.console/issues/2152")]
55+
public Task Should_Wrap_Status_Text_That_Exceeds_The_Console_Width()
56+
{
57+
// Given
58+
var console = new TestConsole()
59+
.Width(40)
60+
.Interactive();
61+
62+
var status = new Status(console)
63+
{
64+
AutoRefresh = false,
65+
Spinner = new DummySpinner1(),
66+
};
67+
68+
// When
69+
status.Start(
70+
"Building AppHost... playground\\HealthChecks\\HealthChecksSandbox.AppHost\\AppHost.csproj",
71+
ctx => ctx.Refresh());
72+
73+
// Then
74+
return Verifier.Verify(console.Output);
75+
}
5176
}

src/Spectre.Console/Live/Progress/Columns/TaskDescriptionColumn.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ namespace Spectre.Console;
66
public sealed class TaskDescriptionColumn : ProgressColumn
77
{
88
/// <inheritdoc/>
9-
protected internal override bool NoWrap => true;
9+
protected internal override bool NoWrap => !Wrap;
10+
11+
/// <summary>
12+
/// Gets or sets a value indicating whether the description should wrap
13+
/// onto multiple lines when it's wider than the available space.
14+
/// Defaults to <c>false</c>, which truncates the description with an ellipsis.
15+
/// </summary>
16+
public bool Wrap { get; set; }
1017

1118
/// <summary>
1219
/// Gets or sets the alignment of the task description.
@@ -17,6 +24,8 @@ public sealed class TaskDescriptionColumn : ProgressColumn
1724
public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime)
1825
{
1926
var text = task.Description?.RemoveNewLines()?.Trim();
20-
return new Markup(text ?? string.Empty).Overflow(Overflow.Ellipsis).Justify(Alignment);
27+
return new Markup(text ?? string.Empty)
28+
.Overflow(Wrap ? Overflow.Fold : Overflow.Ellipsis)
29+
.Justify(Alignment);
2130
}
2231
}

src/Spectre.Console/Live/Status/Status.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ public async Task<T> StartAsync<T>(string status, Func<StatusContext, Task<T>> f
105105
progress.Columns(new ProgressColumn[]
106106
{
107107
spinnerColumn,
108-
new TaskDescriptionColumn(),
108+
new TaskDescriptionColumn
109+
{
110+
Wrap = true,
111+
Alignment = Justify.Left,
112+
},
109113
});
110114

111115
return await progress.StartAsync(async ctx =>

0 commit comments

Comments
 (0)