mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2025-10-25 15:19:23 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47fd646d21 | ||
|
|
a06859dcb5 | ||
|
|
7d3a67e6ae | ||
|
|
f4497b1278 | ||
|
|
a16daade6c | ||
|
|
ab73d16583 | ||
|
|
f2566f2ca4 | ||
|
|
358b0225b4 |
10
.github/workflows/ci.yaml
vendored
10
.github/workflows/ci.yaml
vendored
@@ -31,6 +31,16 @@ jobs:
|
||||
with:
|
||||
dotnet-version: 3.1.301
|
||||
|
||||
- name: Integration Tests
|
||||
shell: bash
|
||||
run: |
|
||||
dotnet tool restore
|
||||
dotnet example diagnostic
|
||||
dotnet example table
|
||||
dotnet example grid
|
||||
dotnet example panel
|
||||
dotnet example colors
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: |
|
||||
|
||||
4
.github/workflows/publish.yaml
vendored
4
.github/workflows/publish.yaml
vendored
@@ -19,7 +19,7 @@ jobs:
|
||||
|
||||
build:
|
||||
name: Build
|
||||
if: "!contains(github.event.head_commit.message, 'skip-ci')"
|
||||
if: "!contains(github.event.head_commit.message, 'skip-ci') || startsWith(github.ref, 'refs/tags/')"
|
||||
strategy:
|
||||
matrix:
|
||||
kind: ['linux', 'windows', 'macOS']
|
||||
@@ -55,7 +55,7 @@ jobs:
|
||||
publish:
|
||||
name: Publish
|
||||
needs: [build]
|
||||
if: "!contains(github.event.head_commit.message, 'skip-ci')"
|
||||
if: "!contains(github.event.head_commit.message, 'skip-ci') || startsWith(github.ref, 'refs/tags/')"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
|
||||
8
docs/README.md
Normal file
8
docs/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Documentation
|
||||
|
||||
Preview the documentation locally by running the following
|
||||
from your favourite shell:
|
||||
|
||||
```
|
||||
> dotnet run -- preview --virtual-dir "spectre.console"
|
||||
```
|
||||
@@ -27,6 +27,27 @@
|
||||
<body class="d-flex flex-column">
|
||||
<div class="flex-grow-1 d-flex flex-column">
|
||||
|
||||
<nav id="topnav" class="navbar navbar-expand-lg navbar-light">
|
||||
<div class="container py-3">
|
||||
<a class="navbar-brand" href="/spectre.console/docs"><img id="logo" src="/spectre.console/assets/logo.svg" alt="Spectre.Console"> Spectre.Console</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarText">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link font-weight-light font-size-lg text-red" href="https://github.com/sponsors/patriksvensson"><i class="far fa-heart"></i> Sponsor</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link font-weight-light font-size-lg" href="https://github.com/spectresystems/spectre.console"><i class="fab fa-github"></i> GitHub</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@if (IsSectionDefined(Constants.Sections.Splash))
|
||||
{
|
||||
@RenderSection(Constants.Sections.Splash, false)
|
||||
|
||||
@@ -20,6 +20,17 @@ $thebackground: $gray-200;
|
||||
height: 15px;
|
||||
}
|
||||
|
||||
#topnav {
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
#topnav .container {
|
||||
padding-top: 0px !important;
|
||||
padding-bottom: 0px !important;
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
@media screen {
|
||||
@include media-breakpoint-up(md) {
|
||||
body {
|
||||
|
||||
@@ -13,72 +13,3 @@ NoContainer: true
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@* <div class="container py-3">
|
||||
<div class="row">
|
||||
<div class="col-sm py-3">
|
||||
<div class="row">
|
||||
<div class="col-md-2">
|
||||
<i class="fad fa-heartbeat fa-2x icon-md-100 icon-theme"></i>
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<h3 class="font-weight-bold font-size-base text-dark mb-2">A beautiful console</h3>
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
Aenean elementum est lorem, at auctor nibh rhoncus eget.
|
||||
Ut lorem leo, aliquet sit amet tortor vitae, aliquet eleifend dui.
|
||||
Etiam lectus diam, maximus a pretium a, lacinia in augue.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm py-3">
|
||||
<div class="row">
|
||||
<div class="col-md-2">
|
||||
<i class="fad fa-code fa-2x icon-md-100 icon-theme"></i>
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<h3 class="font-weight-bold font-size-base text-dark mb-2">Rich formatting language</h3>
|
||||
<p>
|
||||
Donec at rutrum turpis. Etiam tempor sed ex quis pharetra.
|
||||
Suspendisse ullamcorper at magna ac efficitur. Nulla ornare,
|
||||
lectus feugiat ornare ultricies, nunc lorem maximus ipsum,
|
||||
nec accumsan eros tellus quis ante
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm py-3">
|
||||
<div class="row">
|
||||
<div class="col-md-2">
|
||||
<i class="fad fa-cogs fa-2x icon-md-100 icon-theme"></i>
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<h3 class="font-weight-bold font-size-base text-dark mb-2">Configurable</h3>
|
||||
<p>
|
||||
Suspendisse vel condimentum tortor. Fusce tempus ligula ut eros finibus,
|
||||
nec fermentum ipsum hendrerit. Proin eu diam in tortor vestibulum bibendum.
|
||||
Integer tincidunt felis eu urna pulvinar vehicula.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm py-3">
|
||||
<div class="row">
|
||||
<div class="col-md-2">
|
||||
<i class="fad fa-search fa-2x icon-md-100 icon-theme"></i>
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<h3 class="font-weight-bold font-size-base text-dark mb-2">Find problems quickly</h3>
|
||||
<p>
|
||||
Aliquam nec nisl ullamcorper, aliquam mauris sit amet, sagittis orci.
|
||||
Aenean sapien dui, eleifend eget sapien nec, tristique accumsan tortor.
|
||||
Quisque ex quam, rhoncus sagittis consequat id, euismod sit amet dolor.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> *@
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Docs.Shortcodes
|
||||
var table = new XElement("table", new XAttribute("class", "table"));
|
||||
var header = new XElement("tr", new XAttribute("class", "color-row"));
|
||||
header.Add(new XElement("th", ""));
|
||||
header.Add(new XElement("th", "#"));
|
||||
header.Add(new XElement("th", "Name"));
|
||||
header.Add(new XElement("th", "RGB"));
|
||||
header.Add(new XElement("th", "Hex"));
|
||||
@@ -38,7 +39,8 @@ namespace Docs.Shortcodes
|
||||
new XElement("span",
|
||||
new XAttribute("class", "color-representation"),
|
||||
new XAttribute("style", $"background-color:{color.Hex};")));
|
||||
var name = new XElement("td", new XElement("code", color.Name.ToLower()));
|
||||
var name = new XElement("td", new XElement("code", color.Number.ToString()));
|
||||
var number = new XElement("td", new XElement("code", color.Name.ToLower()));
|
||||
var rgb = new XElement("td", new XElement("code", $"{color.R},{color.G},{color.B}"));
|
||||
var hex = new XElement("td", new XElement("code", color.Hex));
|
||||
var clr = new XElement("td", new XElement("code", color.ClrName));
|
||||
@@ -47,6 +49,7 @@ namespace Docs.Shortcodes
|
||||
var row = new XElement("tr");
|
||||
row.Add(rep);
|
||||
row.Add(name);
|
||||
row.Add(number);
|
||||
row.Add(rgb);
|
||||
row.Add(hex);
|
||||
row.Add(clr);
|
||||
|
||||
@@ -13,6 +13,12 @@
|
||||
"commands": [
|
||||
"gpr"
|
||||
]
|
||||
},
|
||||
"dotnet-example": {
|
||||
"version": "0.8.0",
|
||||
"commands": [
|
||||
"dotnet-example"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,44 @@ using Spectre.Console;
|
||||
|
||||
namespace ColorExample
|
||||
{
|
||||
class Program
|
||||
public static class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
if (AnsiConsole.Capabilities.ColorSystem == ColorSystem.NoColors)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// No colors
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
AnsiConsole.WriteLine("No colors are supported.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (AnsiConsole.Capabilities.Supports(ColorSystem.Legacy))
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 3-BIT
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
AnsiConsole.ResetColors();
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.MarkupLine("[bold underline]3-bit Colors[/]");
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
AnsiConsole.Background = Color.FromInt32(i);
|
||||
AnsiConsole.Write(string.Format(" {0,-9}", AnsiConsole.Background.ToString()));
|
||||
AnsiConsole.ResetColors();
|
||||
if ((i + 1) % 8 == 0)
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (AnsiConsole.Capabilities.Supports(ColorSystem.Standard))
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 4-BIT
|
||||
@@ -25,7 +60,10 @@ namespace ColorExample
|
||||
AnsiConsole.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (AnsiConsole.Capabilities.Supports(ColorSystem.EightBit))
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 8-BIT
|
||||
/////////////////////////////////////////////////////////////////
|
||||
@@ -49,7 +87,10 @@ namespace ColorExample
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (AnsiConsole.Capabilities.Supports(ColorSystem.TrueColor))
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 24-BIT
|
||||
/////////////////////////////////////////////////////////////////
|
||||
@@ -75,4 +116,5 @@ namespace ColorExample
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
14
examples/Diagnostic/Diagnostic.csproj
Normal file
14
examples/Diagnostic/Diagnostic.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Description>Displays the capabilities of the current console.</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
18
examples/Diagnostic/Program.cs
Normal file
18
examples/Diagnostic/Program.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace Diagnostic
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
AnsiConsole.MarkupLine("Color system: [bold]{0}[/]", AnsiConsole.Capabilities.ColorSystem);
|
||||
AnsiConsole.MarkupLine("Supports ansi? [bold]{0}[/]", AnsiConsole.Capabilities.SupportsAnsi);
|
||||
AnsiConsole.MarkupLine("Legacy console? [bold]{0}[/]", AnsiConsole.Capabilities.LegacyConsole);
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.MarkupLine("Buffer width: [bold]{0}[/]", AnsiConsole.Console.Width);
|
||||
AnsiConsole.MarkupLine("Buffer height: [bold]{0}[/]", AnsiConsole.Console.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace GridExample
|
||||
static void Main(string[] args)
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.MarkupLine("Usage: [grey]dotnet [blue]run[/] [[options] [[[[--] <additional arguments>...]][/]");
|
||||
AnsiConsole.MarkupLine("Usage: [grey]dotnet [blue]run[/] [[options]] [[[[--]] <additional arguments>...]]]][/]");
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
var grid = new Grid();
|
||||
|
||||
@@ -7,9 +7,8 @@ namespace PanelExample
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var content = new Markup(
|
||||
"[underline]I[/] heard [underline on blue]you[/] like 📦\n\n\n\n" +
|
||||
"So I put a 📦 in a 📦\n\n" +
|
||||
"😅").Centered();
|
||||
"[underline]I[/] heard [underline on blue]you[/] like panels\n\n\n\n" +
|
||||
"So I put a panel in a panel").Centered();
|
||||
|
||||
AnsiConsole.Render(
|
||||
new Panel(
|
||||
|
||||
@@ -41,16 +41,16 @@ namespace TableExample
|
||||
table.AddColumn(new TableColumn("[blue]Bar[/]") { Alignment = Justify.Right, NoWrap = true });
|
||||
|
||||
// Add some rows
|
||||
table.AddRow("[blue][underline]Hell[/]o[/]", "World 🌍");
|
||||
table.AddRow("[blue][underline]Hell[/]o[/]", "World");
|
||||
table.AddRow("[yellow]Patrik [green]\"Hello World\"[/] Svensson[/]", "Was [underline]here[/]!");
|
||||
table.AddEmptyRow();
|
||||
table.AddRow(
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " +
|
||||
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " +
|
||||
"dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat " +
|
||||
"non proident, sunt in culpa qui officia deserunt mollit anim id est laborum", "◀ Strange language");
|
||||
"non proident, sunt in culpa qui officia deserunt mollit anim id est laborum", "<- Strange language");
|
||||
table.AddEmptyRow();
|
||||
table.AddRow("Hej 👋", "[green]Världen[/]");
|
||||
table.AddRow("Hej", "[green]Världen[/]");
|
||||
|
||||
AnsiConsole.Render(table);
|
||||
}
|
||||
@@ -81,7 +81,7 @@ namespace TableExample
|
||||
table.AddColumn(new TableColumn(new Panel("[u]Baz[/]").SetBorderColor(Color.Blue)));
|
||||
|
||||
// Add some rows
|
||||
table.AddRow(new Text("Hello").Centered(), new Markup("[red]World![/] 🌍"), Text.Empty);
|
||||
table.AddRow(new Text("Hello").Centered(), new Markup("[red]World![/]"), Text.Empty);
|
||||
table.AddRow(second, new Text("Whaaat"), new Text("Lol"));
|
||||
table.AddRow(new Markup("[blue]Hej[/]").Centered(), new Markup("[yellow]Världen![/]"), Text.Empty);
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grid", "..\examples\Grid\Gr
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Colors", "..\examples\Colors\Colors.csproj", "{1F51C55C-BA4C-4856-9001-0F7924FFB179}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Diagnostic", "..\examples\Diagnostic\Diagnostic.csproj", "{4337F255-88E9-4408-81A3-DF1AF58AC753}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -107,6 +109,18 @@ Global
|
||||
{1F51C55C-BA4C-4856-9001-0F7924FFB179}.Release|x64.Build.0 = Release|Any CPU
|
||||
{1F51C55C-BA4C-4856-9001-0F7924FFB179}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{1F51C55C-BA4C-4856-9001-0F7924FFB179}.Release|x86.Build.0 = Release|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Release|x64.Build.0 = Release|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -116,6 +130,7 @@ Global
|
||||
{BFF37228-B376-4ADD-9657-4E501F929713} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{C7FF6FDB-FB59-4517-8669-521C96AB7323} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{1F51C55C-BA4C-4856-9001-0F7924FFB179} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
{4337F255-88E9-4408-81A3-DF1AF58AC753} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {5729B071-67A0-48FB-8B1B-275E6822086C}
|
||||
|
||||
@@ -38,6 +38,17 @@ namespace Spectre.Console
|
||||
LegacyConsole = legacyConsole;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the current capabilities supports
|
||||
/// the specified color system.
|
||||
/// </summary>
|
||||
/// <param name="colorSystem">The color system to check.</param>
|
||||
/// <returns><c>true</c> if the color system is supported, otherwise <c>false</c>.</returns>
|
||||
public bool Supports(ColorSystem colorSystem)
|
||||
{
|
||||
return (int)colorSystem <= (int)ColorSystem;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
@@ -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