mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 21:38:16 +08:00
Fallback to default buffer size
Also fixes a bug when using Spectre.Console in GitHub Actions.
This commit is contained in:

committed by
Patrik Svensson

parent
ab73d16583
commit
a16daade6c
@ -21,7 +21,7 @@ namespace Spectre.Console.Internal
|
||||
{
|
||||
if (_out.IsStandardOut())
|
||||
{
|
||||
return System.Console.BufferWidth;
|
||||
return ConsoleHelper.GetSafeBufferWidth(Constants.DefaultBufferWidth);
|
||||
}
|
||||
|
||||
return Constants.DefaultBufferWidth;
|
||||
@ -34,7 +34,7 @@ namespace Spectre.Console.Internal
|
||||
{
|
||||
if (_out.IsStandardOut())
|
||||
{
|
||||
return System.Console.BufferHeight;
|
||||
return ConsoleHelper.GetSafeBufferHeight(Constants.DefaultBufferHeight);
|
||||
}
|
||||
|
||||
return Constants.DefaultBufferHeight;
|
||||
|
@ -3,7 +3,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Spectre.Console.Internal
|
||||
{
|
||||
internal static class ConsoleExtensions
|
||||
internal static class AnsiConsoleExtensions
|
||||
{
|
||||
public static IDisposable PushStyle(this IAnsiConsole console, Style style)
|
||||
{
|
@ -24,7 +24,7 @@ namespace Spectre.Console.Internal
|
||||
{
|
||||
if (_out.IsStandardOut())
|
||||
{
|
||||
return System.Console.BufferWidth;
|
||||
return ConsoleHelper.GetSafeBufferWidth(Constants.DefaultBufferWidth);
|
||||
}
|
||||
|
||||
return Constants.DefaultBufferWidth;
|
||||
@ -37,7 +37,7 @@ namespace Spectre.Console.Internal
|
||||
{
|
||||
if (_out.IsStandardOut())
|
||||
{
|
||||
return System.Console.BufferHeight;
|
||||
return ConsoleHelper.GetSafeBufferHeight(Constants.DefaultBufferHeight);
|
||||
}
|
||||
|
||||
return Constants.DefaultBufferHeight;
|
||||
|
44
src/Spectre.Console/Internal/Utilities/ConsoleHelper.cs
Normal file
44
src/Spectre.Console/Internal/Utilities/ConsoleHelper.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Spectre.Console.Internal
|
||||
{
|
||||
internal static class ConsoleHelper
|
||||
{
|
||||
public static int GetSafeBufferWidth(int defaultValue = Constants.DefaultBufferWidth)
|
||||
{
|
||||
try
|
||||
{
|
||||
var width = System.Console.BufferWidth;
|
||||
if (width == 0)
|
||||
{
|
||||
width = defaultValue;
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetSafeBufferHeight(int defaultValue = Constants.DefaultBufferWidth)
|
||||
{
|
||||
try
|
||||
{
|
||||
var height = System.Console.BufferHeight;
|
||||
if (height == 0)
|
||||
{
|
||||
height = defaultValue;
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user