Skip to content

Expose ITerminal.Width property #1202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/System.CommandLine.Rendering/ITerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public interface ITerminal : IConsole
void HideCursor();

void ShowCursor();

int Width { get; }
}
}
4 changes: 4 additions & 0 deletions src/System.CommandLine.Rendering/SystemConsoleTerminal.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.CommandLine.IO;

namespace System.CommandLine.Rendering
{
public class SystemConsoleTerminal : TerminalBase
Expand All @@ -22,6 +24,8 @@ public override ConsoleColor BackgroundColor
set => System.Console.BackgroundColor = value;
}

public override int Width => Console is SystemConsole system ? system.GetConsoleWindowWidth() : int.MaxValue;

public override ConsoleColor ForegroundColor
{
get => System.Console.ForegroundColor;
Expand Down
2 changes: 2 additions & 0 deletions src/System.CommandLine.Rendering/TerminalBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ protected TerminalBase(IConsole console)

public bool IsInputRedirected => Console.IsInputRedirected;

public abstract int Width { get; }

protected virtual void Dispose(bool disposing)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine.Rendering/TestTerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void OnCharWrittenToOut(char c)

public int Height { get; set; } = 100;

public int Width { get; set; } = 100;
public int Width { get; } = 100;

public virtual void ResetColor()
{
Expand Down
2 changes: 2 additions & 0 deletions src/System.CommandLine.Rendering/VirtualTerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public override void ResetColor()
Ansi.Color.Foreground.Default.EscapeSequence);
}

public override int Width => int.MaxValue;

public override void Clear()
{
Console.Out.Write(
Expand Down