mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-27 05:32:50 +08:00
44 lines
1020 B
C#
44 lines
1020 B
C#
using System.IO;
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|