From a23bec4082800330be490384622e887484bd50a5 Mon Sep 17 00:00:00 2001 From: Patrik Svensson Date: Sat, 16 Jan 2021 17:23:58 +0100 Subject: [PATCH] Add profile support Closes #231 --- examples/Console/Colors/Program.cs | 10 +- examples/Console/Info/Program.cs | 16 +- examples/Console/Links/Program.cs | 2 +- examples/Console/Progress/Program.cs | 1 - examples/Console/Prompt/Program.cs | 2 +- .../Fakes/FakeAnsiConsole.cs | 19 +- .../Fakes/FakeConsole.cs | 19 +- .../Fakes/FakeLinkIdentityGenerator.cs | 17 -- src/Spectre.Console.Tests/Constants.cs | 10 +- src/Spectre.Console.Tests/Data/Exceptions.cs | 3 - .../Data/Settings/ArgumentVectorSettings.cs | 2 - .../MultipleArgumentVectorSettings.cs | 4 - .../Data/Settings/OptionVectorSettings.cs | 3 - .../Spectre.Console.Tests.v3.ncrunchproject | 17 +- .../Unit/AnsiConsoleTests.Markup.cs | 30 ++- src/Spectre.Console/AnsiConsole.cs | 25 +-- src/Spectre.Console/AnsiConsoleFactory.cs | 178 +++++++++++++++ src/Spectre.Console/AnsiConsoleSettings.cs | 19 +- src/Spectre.Console/Capabilities.cs | 93 ++++---- .../Annotations/CommandArgumentAttribute.cs | 1 - .../Cli/Annotations/CommandOptionAttribute.cs | 1 - src/Spectre.Console/Cli/CaseSensitivity.cs | 2 - src/Spectre.Console/Cli/CommandApp.cs | 7 +- .../Cli/CommandConfigurationException.cs | 1 - .../Cli/CommandParseException.cs | 1 - .../Cli/CommandRuntimeException.cs | 3 +- .../Cli/CommandTemplateException.cs | 1 - .../Binding/CommandConstructorBinder.cs | 2 +- .../Internal/Binding/CommandPropertyBinder.cs | 2 +- .../Internal/Binding/CommandValueBinder.cs | 2 +- .../Internal/Binding/CommandValueLookup.cs | 2 +- .../Internal/Binding/CommandValueResolver.cs | 2 +- .../Cli/Internal/Collections/IMultiMap.cs | 2 +- .../Cli/Internal/Collections/MultiMap.cs | 2 +- .../Cli/Internal/CommandBinder.cs | 2 +- .../Cli/Internal/CommandExecutor.cs | 2 +- .../Cli/Internal/CommandPart.cs | 2 +- .../Cli/Internal/CommandSuggestor.cs | 2 +- .../Cli/Internal/CommandValidator.cs | 2 +- .../Cli/Internal/Commands/VersionCommand.cs | 2 +- .../Cli/Internal/Commands/XmlDocCommand.cs | 2 +- src/Spectre.Console/Cli/Internal/Composer.cs | 2 +- .../Cli/Internal/Composition/Activators.cs | 2 +- .../Composition/ComponentRegistration.cs | 2 +- .../Internal/Composition/ComponentRegistry.cs | 2 +- .../Composition/DefaultTypeRegistrar.cs | 2 +- .../Composition/DefaultTypeResolver.cs | 2 +- .../Configuration/CommandAppSettings.cs | 2 +- .../Configuration/CommandConfigurator.cs | 2 +- .../Configuration/ConfigurationHelper.cs | 2 +- .../Internal/Configuration/Configurator.cs | 4 +- .../Internal/Configuration/Configurator`1.cs | 2 +- .../Configuration/ConfiguredCommand.cs | 2 +- .../Internal/Configuration/IConfiguration.cs | 2 +- .../Internal/Configuration/TemplateParser.cs | 2 +- .../Internal/Configuration/TemplateToken.cs | 2 +- .../Configuration/TemplateTokenizer.cs | 2 +- src/Spectre.Console/Cli/Internal/Constants.cs | 4 +- .../Cli/Internal/DefaultPairDeconstructor.cs | 2 +- .../Cli/Internal/DelegateCommand.cs | 2 +- .../CommandLineParseExceptionFactory.cs | 2 +- .../CommandLineTemplateExceptionFactory.cs | 2 +- .../Extensions/AnsiConsoleExtensions.cs | 2 +- .../Extensions/CaseSensitivityExtensions.cs | 2 +- .../Cli/Internal/Extensions/ListExtensions.cs | 2 +- .../Cli/Internal/Extensions/TypeExtensions.cs | 2 +- .../Extensions/TypeRegistrarExtensions.cs | 2 +- .../Extensions/XmlElementExtensions.cs | 2 +- .../Cli/Internal/HelpWriter.cs | 2 +- .../Cli/Internal/IPairDeconstructor.cs | 2 +- .../Cli/Internal/Modelling/CommandArgument.cs | 2 +- .../Modelling/CommandContainerExtensions.cs | 2 +- .../Cli/Internal/Modelling/CommandInfo.cs | 2 +- .../Modelling/CommandInfoExtensions.cs | 2 +- .../Cli/Internal/Modelling/CommandModel.cs | 2 +- .../Internal/Modelling/CommandModelBuilder.cs | 2 +- .../Modelling/CommandModelValidator.cs | 2 +- .../Cli/Internal/Modelling/CommandOption.cs | 2 +- .../Internal/Modelling/CommandParameter.cs | 2 +- .../Modelling/CommandParameterComparer.cs | 2 +- .../Internal/Modelling/ICommandContainer.cs | 2 +- .../Cli/Internal/Modelling/ParameterKind.cs | 2 +- .../Cli/Internal/Parsing/CommandTree.cs | 2 +- .../Internal/Parsing/CommandTreeExtensions.cs | 2 +- .../Cli/Internal/Parsing/CommandTreeParser.cs | 4 +- .../Parsing/CommandTreeParserContext.cs | 2 +- .../Parsing/CommandTreeParserResult.cs | 2 +- .../Cli/Internal/Parsing/CommandTreeToken.cs | 2 +- .../Parsing/CommandTreeTokenStream.cs | 2 +- .../Internal/Parsing/CommandTreeTokenizer.cs | 2 +- .../Parsing/CommandTreeTokenizerContext.cs | 2 +- .../Parsing/MappedCommandParameter.cs | 2 +- .../Cli/Internal/ParsingMode.cs | 2 +- .../Cli/Internal/RemainingArguments.cs | 2 +- .../Cli/Internal/StringWriterWithEncoding.cs | 2 +- .../Cli/Internal/TextBuffer.cs | 4 +- .../Cli/Internal/TypeRegistrar.cs | 2 +- .../Cli/Internal/TypeResolverAdapter.cs | 2 +- .../Cli/Internal/VersionHelper.cs | 4 +- src/Spectre.Console/Cli/PairDeconstuctor.cs | 1 - src/Spectre.Console/Color.cs | 1 - src/Spectre.Console/Decoration.cs | 2 - .../AnsiConsoleExtensions.Markup.cs | 1 - .../AnsiConsoleExtensions.Rendering.cs | 4 +- .../Extensions/DayOfWeekExtensions.cs | 2 +- .../Extensions/DictionaryExtensions.cs | 2 +- .../Extensions/EnumerableExtensions.cs | 2 +- .../Extensions/ExceptionExtensions.cs | 1 - .../Extensions/GridExtensions.cs | 1 - .../Obsolete/ObsoleteAlignableExtensions.cs | 32 --- .../Obsolete/ObsoleteCalendarExtensions.cs | 49 ----- .../Obsolete/ObsoleteHasBorderExtensions.cs | 53 ----- .../ObsoleteHasBoxBorderExtensions.cs | 32 --- .../Obsolete/ObsoleteHasCultureExtensions.cs | 80 ------- .../ObsoleteHasTableBorderExtensions.cs | 32 --- .../ObsoleteOverflowableExtensions.cs | 32 --- .../Obsolete/ObsoletePaddableExtensions.cs | 50 ----- .../Obsolete/ObsoletePanelExtensions.cs | 69 ------ .../Obsolete/ObsoleteRuleExtensions.cs | 59 ----- .../Obsolete/ObsoleteStringExtensions.cs | 23 -- .../Obsolete/ObsoleteStyleExtensions.cs | 100 --------- .../Obsolete/ObsoleteTableExtensions.cs | 202 ------------------ .../Extensions/RecorderExtensions.cs | 1 - .../Extensions/StringBuilderExtensions.cs | 2 +- .../Extensions/StringExtensions.cs | 1 - .../Extensions/TableExtensions.cs | 1 - .../Extensions/TextWriterExtensions.cs | 4 +- src/Spectre.Console/IAnsiConsole.cs | 20 +- src/Spectre.Console/ILinkIdentityGenerator.cs | 16 -- src/Spectre.Console/IProfileEnricher.cs | 23 ++ src/Spectre.Console/Internal/Aligner.cs | 2 +- .../Internal/Backends/Ansi/AnsiBackend.cs | 112 ---------- .../{ => Backends}/Ansi/AnsiBuilder.cs | 18 +- .../{ => Backends}/Ansi/AnsiColorBuilder.cs | 2 +- .../Backends/Ansi/AnsiConsoleBackend.cs | 66 ++++++ .../Backends/Ansi/AnsiConsoleCursor.cs | 56 +++++ .../Internal/Backends/Ansi/AnsiCursor.cs | 56 ----- .../Ansi/AnsiDecorationBuilder.cs | 2 +- .../{ => Backends}/Ansi/AnsiDetector.cs | 10 +- .../Ansi/AnsiLinkHasher.cs} | 6 +- .../Internal/Backends/AnsiConsoleFacade.cs | 55 +++++ .../Internal/Backends/BackendBuilder.cs | 77 ------- .../Backends/Fallback/FallbackBackend.cs | 103 --------- .../Internal/Backends/IAnsiConsoleBackend.cs | 28 +++ .../{ => Backends}/InteractivityDetector.cs | 2 +- .../Backends/Legacy/LegacyConsoleBackend.cs | 71 ++++++ .../LegacyConsoleCursor.cs} | 4 +- .../Internal/{Text => }/Cell.cs | 2 +- .../Internal/Collections/ListWithCallback.cs | 2 +- .../Internal/Colors/ColorPalette.Generated.cs | 2 +- .../Internal/Colors/ColorPalette.cs | 2 +- .../Internal/Colors/ColorSystemDetector.cs | 2 +- .../Internal/Colors/ColorTable.Generated.cs | 2 +- .../Internal/Colors/ColorTable.cs | 4 +- src/Spectre.Console/Internal/ConsoleHelper.cs | 2 +- src/Spectre.Console/Internal/ConsoleInput.cs | 17 -- src/Spectre.Console/Internal/Constants.cs | 2 +- .../Internal/DecorationTable.cs | 4 +- src/Spectre.Console/Internal/DefaultInput.cs | 29 +++ src/Spectre.Console/Internal/FileSize.cs | 6 +- src/Spectre.Console/Internal/FileSizeUnit.cs | 6 +- src/Spectre.Console/Internal/Ratio.cs | 2 +- .../Internal/ResourceReader.cs | 2 +- .../{ => Text/Encoding}/HtmlEncoder.cs | 2 +- .../{ => Text/Encoding}/TextEncoder.cs | 2 +- .../Internal/Text/Markup/MarkupParser.cs | 2 +- .../Internal/Text/Markup/MarkupToken.cs | 2 +- .../Internal/Text/Markup/MarkupTokenKind.cs | 2 +- .../Internal/Text/Markup/MarkupTokenizer.cs | 2 +- .../Internal/Text/StringBuffer.cs | 4 +- .../Internal/TypeConverterHelper.cs | 3 +- src/Spectre.Console/Profile.cs | 194 +++++++++++++++++ .../Profiles/AppVeyorProfile.cs | 18 ++ src/Spectre.Console/Profiles/BambooProfile.cs | 18 ++ .../Profiles/BitbucketProfile.cs | 20 ++ .../Profiles/BitriseProfile.cs | 18 ++ .../Profiles/ContinuaCIProfile.cs | 18 ++ src/Spectre.Console/Profiles/GitHubProfile.cs | 28 +++ src/Spectre.Console/Profiles/GitLabProfile.cs | 24 +++ src/Spectre.Console/Profiles/GoCDProfile.cs | 18 ++ .../Profiles/JenkinsProfile.cs | 18 ++ src/Spectre.Console/Profiles/MyGetProfile.cs | 24 +++ .../Profiles/TeamCityProfile.cs | 18 ++ src/Spectre.Console/Profiles/TfsProfile.cs | 18 ++ src/Spectre.Console/Profiles/TravisProfile.cs | 18 ++ src/Spectre.Console/Recorder.cs | 13 +- .../Borders/Tables/MarkdownTableBorder.cs | 1 - .../Rendering/LiveRenderable.cs | 1 - src/Spectre.Console/Rendering/Segment.cs | 1 - src/Spectre.Console/Rendering/SegmentLine.cs | 2 - src/Spectre.Console/Style.cs | 3 - .../{Internal/Text => }/StyleParser.cs | 5 +- src/Spectre.Console/TableBorder.cs | 1 - src/Spectre.Console/Widgets/Calendar.cs | 1 - .../Exceptions}/ExceptionFormat.cs | 0 .../Exceptions}/ExceptionFormatter.cs | 2 +- .../Exceptions}/ExceptionInfo.cs | 4 +- .../Exceptions}/ExceptionParser.cs | 2 +- .../Exceptions}/ExceptionSettings.cs | 0 .../Exceptions}/ExceptionStyle.cs | 0 .../Exceptions}/StackFrameInfo.cs | 3 +- .../Widgets/Figlet/FigletFont.cs | 1 - src/Spectre.Console/Widgets/Grid.cs | 1 - src/Spectre.Console/Widgets/Markup.cs | 1 - src/Spectre.Console/Widgets/Padder.cs | 1 - src/Spectre.Console/Widgets/Paragraph.cs | 1 - .../Progress/Columns/DownloadedColumn.cs | 1 - .../Widgets/Progress/Columns/SpinnerColumn.cs | 1 - .../Progress/Columns/TransferSpeedColumn.cs | 1 - .../Widgets/Progress/Progress.cs | 5 +- .../Widgets/Progress/ProgressContext.cs | 4 - .../Widgets/Progress/ProgressRefreshThread.cs | 2 +- .../Widgets/Progress/ProgressRenderer.cs | 2 +- .../Widgets/Progress/ProgressSample.cs | 2 +- .../Widgets/Progress/ProgressTask.cs | 1 - .../Renderers/DefaultProgressRenderer.cs | 4 +- .../Renderers/FallbackProgressRenderer.cs | 2 +- ...kRenderer.cs => FallbackStatusRenderer.cs} | 6 +- .../Widgets/Progress/Status.cs | 3 +- .../Widgets/Prompt/MultiSelectionPrompt.cs | 5 +- .../Prompt/Rendering/RenderableList.cs | 1 - .../Rendering/RenderableMultiSelectionList.cs | 4 +- .../Rendering/RenderableSelectionList.cs | 4 +- .../Widgets/Prompt/SelectionPrompt.cs | 5 +- .../Widgets/Prompt/TextPrompt.cs | 1 - src/Spectre.Console/Widgets/Rows.cs | 1 - src/Spectre.Console/Widgets/Table/Table.cs | 1 - .../Widgets/Table/TableMeasurer.cs | 1 - .../Widgets/Table/TableRenderer.cs | 1 - src/Spectre.Console/Widgets/Tree.cs | 1 - 230 files changed, 1241 insertions(+), 1628 deletions(-) delete mode 100644 src/Spectre.Console.Testing/Fakes/FakeLinkIdentityGenerator.cs create mode 100644 src/Spectre.Console/AnsiConsoleFactory.cs delete mode 100644 src/Spectre.Console/Extensions/Obsolete/ObsoleteAlignableExtensions.cs delete mode 100644 src/Spectre.Console/Extensions/Obsolete/ObsoleteCalendarExtensions.cs delete mode 100644 src/Spectre.Console/Extensions/Obsolete/ObsoleteHasBorderExtensions.cs delete mode 100644 src/Spectre.Console/Extensions/Obsolete/ObsoleteHasBoxBorderExtensions.cs delete mode 100644 src/Spectre.Console/Extensions/Obsolete/ObsoleteHasCultureExtensions.cs delete mode 100644 src/Spectre.Console/Extensions/Obsolete/ObsoleteHasTableBorderExtensions.cs delete mode 100644 src/Spectre.Console/Extensions/Obsolete/ObsoleteOverflowableExtensions.cs delete mode 100644 src/Spectre.Console/Extensions/Obsolete/ObsoletePaddableExtensions.cs delete mode 100644 src/Spectre.Console/Extensions/Obsolete/ObsoletePanelExtensions.cs delete mode 100644 src/Spectre.Console/Extensions/Obsolete/ObsoleteRuleExtensions.cs delete mode 100644 src/Spectre.Console/Extensions/Obsolete/ObsoleteStringExtensions.cs delete mode 100644 src/Spectre.Console/Extensions/Obsolete/ObsoleteStyleExtensions.cs delete mode 100644 src/Spectre.Console/Extensions/Obsolete/ObsoleteTableExtensions.cs delete mode 100644 src/Spectre.Console/ILinkIdentityGenerator.cs create mode 100644 src/Spectre.Console/IProfileEnricher.cs delete mode 100644 src/Spectre.Console/Internal/Backends/Ansi/AnsiBackend.cs rename src/Spectre.Console/Internal/{ => Backends}/Ansi/AnsiBuilder.cs (75%) rename src/Spectre.Console/Internal/{ => Backends}/Ansi/AnsiColorBuilder.cs (98%) create mode 100644 src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleBackend.cs create mode 100644 src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleCursor.cs delete mode 100644 src/Spectre.Console/Internal/Backends/Ansi/AnsiCursor.cs rename src/Spectre.Console/Internal/{ => Backends}/Ansi/AnsiDecorationBuilder.cs (97%) rename src/Spectre.Console/Internal/{ => Backends}/Ansi/AnsiDetector.cs (92%) rename src/Spectre.Console/Internal/{LinkIdentityGenerator.cs => Backends/Ansi/AnsiLinkHasher.cs} (85%) create mode 100644 src/Spectre.Console/Internal/Backends/AnsiConsoleFacade.cs delete mode 100644 src/Spectre.Console/Internal/Backends/BackendBuilder.cs delete mode 100644 src/Spectre.Console/Internal/Backends/Fallback/FallbackBackend.cs create mode 100644 src/Spectre.Console/Internal/Backends/IAnsiConsoleBackend.cs rename src/Spectre.Console/Internal/{ => Backends}/InteractivityDetector.cs (98%) create mode 100644 src/Spectre.Console/Internal/Backends/Legacy/LegacyConsoleBackend.cs rename src/Spectre.Console/Internal/Backends/{Fallback/FallbackCursor.cs => Legacy/LegacyConsoleCursor.cs} (91%) rename src/Spectre.Console/Internal/{Text => }/Cell.cs (97%) delete mode 100644 src/Spectre.Console/Internal/ConsoleInput.cs create mode 100644 src/Spectre.Console/Internal/DefaultInput.cs rename src/Spectre.Console/Internal/{ => Text/Encoding}/HtmlEncoder.cs (98%) rename src/Spectre.Console/Internal/{ => Text/Encoding}/TextEncoder.cs (94%) create mode 100644 src/Spectre.Console/Profile.cs create mode 100644 src/Spectre.Console/Profiles/AppVeyorProfile.cs create mode 100644 src/Spectre.Console/Profiles/BambooProfile.cs create mode 100644 src/Spectre.Console/Profiles/BitbucketProfile.cs create mode 100644 src/Spectre.Console/Profiles/BitriseProfile.cs create mode 100644 src/Spectre.Console/Profiles/ContinuaCIProfile.cs create mode 100644 src/Spectre.Console/Profiles/GitHubProfile.cs create mode 100644 src/Spectre.Console/Profiles/GitLabProfile.cs create mode 100644 src/Spectre.Console/Profiles/GoCDProfile.cs create mode 100644 src/Spectre.Console/Profiles/JenkinsProfile.cs create mode 100644 src/Spectre.Console/Profiles/MyGetProfile.cs create mode 100644 src/Spectre.Console/Profiles/TeamCityProfile.cs create mode 100644 src/Spectre.Console/Profiles/TfsProfile.cs create mode 100644 src/Spectre.Console/Profiles/TravisProfile.cs rename src/Spectre.Console/{Internal/Text => }/StyleParser.cs (96%) rename src/Spectre.Console/{ => Widgets/Exceptions}/ExceptionFormat.cs (100%) rename src/Spectre.Console/{Internal => Widgets/Exceptions}/ExceptionFormatter.cs (99%) rename src/Spectre.Console/{Internal => Widgets/Exceptions}/ExceptionInfo.cs (88%) rename src/Spectre.Console/{Internal => Widgets/Exceptions}/ExceptionParser.cs (99%) rename src/Spectre.Console/{ => Widgets/Exceptions}/ExceptionSettings.cs (100%) rename src/Spectre.Console/{ => Widgets/Exceptions}/ExceptionStyle.cs (100%) rename src/Spectre.Console/{Internal => Widgets/Exceptions}/StackFrameInfo.cs (93%) rename src/Spectre.Console/Widgets/Progress/Renderers/{StatusFallbackRenderer.cs => FallbackStatusRenderer.cs} (91%) diff --git a/examples/Console/Colors/Program.cs b/examples/Console/Colors/Program.cs index 9527bba..3075c8e 100644 --- a/examples/Console/Colors/Program.cs +++ b/examples/Console/Colors/Program.cs @@ -6,7 +6,7 @@ namespace ColorExample { public static void Main() { - if (AnsiConsole.Capabilities.ColorSystem == ColorSystem.NoColors) + if (AnsiConsole.Profile.ColorSystem == ColorSystem.NoColors) { ///////////////////////////////////////////////////////////////// // No colors @@ -16,7 +16,7 @@ namespace ColorExample return; } - if (AnsiConsole.Capabilities.Supports(ColorSystem.Legacy)) + if (AnsiConsole.Profile.Supports(ColorSystem.Legacy)) { ///////////////////////////////////////////////////////////////// // 3-BIT @@ -39,7 +39,7 @@ namespace ColorExample } } - if (AnsiConsole.Capabilities.Supports(ColorSystem.Standard)) + if (AnsiConsole.Profile.Supports(ColorSystem.Standard)) { ///////////////////////////////////////////////////////////////// // 4-BIT @@ -62,7 +62,7 @@ namespace ColorExample } } - if (AnsiConsole.Capabilities.Supports(ColorSystem.EightBit)) + if (AnsiConsole.Profile.Supports(ColorSystem.EightBit)) { ///////////////////////////////////////////////////////////////// // 8-BIT @@ -89,7 +89,7 @@ namespace ColorExample } } - if (AnsiConsole.Capabilities.Supports(ColorSystem.TrueColor)) + if (AnsiConsole.Profile.Supports(ColorSystem.TrueColor)) { ///////////////////////////////////////////////////////////////// // 24-BIT diff --git a/examples/Console/Info/Program.cs b/examples/Console/Info/Program.cs index 0c2f624..030a455 100644 --- a/examples/Console/Info/Program.cs +++ b/examples/Console/Info/Program.cs @@ -9,12 +9,16 @@ namespace InfoExample var grid = new Grid() .AddColumn(new GridColumn().NoWrap().PadRight(4)) .AddColumn() - .AddRow("[b]Color system[/]", $"{AnsiConsole.Capabilities.ColorSystem}") - .AddRow("[b]Supports ansi?[/]", $"{YesNo(AnsiConsole.Capabilities.SupportsAnsi)}") - .AddRow("[b]Legacy console?[/]", $"{YesNo(AnsiConsole.Capabilities.LegacyConsole)}") - .AddRow("[b]Interactive?[/]", $"{YesNo(AnsiConsole.Capabilities.SupportsInteraction)}") - .AddRow("[b]Buffer width[/]", $"{AnsiConsole.Console.Width}") - .AddRow("[b]Buffer height[/]", $"{AnsiConsole.Console.Height}"); + .AddRow("[b]Profile[/]", $"{AnsiConsole.Console.Profile.Name}") + .AddRow("[b]Color system[/]", $"{AnsiConsole.Profile.ColorSystem}") + .AddRow("[b]Supports ansi?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Ansi)}") + .AddRow("[b]Supports links?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Links)}") + .AddRow("[b]Legacy console?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Legacy)}") + .AddRow("[b]Interactive?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Interactive)}") + .AddRow("[b]TTY?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Tty)}") + .AddRow("[b]Buffer width[/]", $"{AnsiConsole.Console.Profile.Width}") + .AddRow("[b]Buffer height[/]", $"{AnsiConsole.Console.Profile.Height}") + .AddRow("[b]Encoding[/]", $"{AnsiConsole.Console.Profile.Encoding.EncodingName}"); AnsiConsole.Render( new Panel(grid) diff --git a/examples/Console/Links/Program.cs b/examples/Console/Links/Program.cs index ee70d59..f61972e 100644 --- a/examples/Console/Links/Program.cs +++ b/examples/Console/Links/Program.cs @@ -6,7 +6,7 @@ namespace LinkExample { public static void Main() { - if (AnsiConsole.Capabilities.SupportLinks) + if (AnsiConsole.Profile.Capabilities.Links) { AnsiConsole.MarkupLine("[link=https://patriksvensson.se]Click to visit my blog[/]!"); } diff --git a/examples/Console/Progress/Program.cs b/examples/Console/Progress/Program.cs index 05a25ef..6215b9b 100644 --- a/examples/Console/Progress/Program.cs +++ b/examples/Console/Progress/Program.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Threading; using Spectre.Console; diff --git a/examples/Console/Prompt/Program.cs b/examples/Console/Prompt/Program.cs index 40874e6..1822e4f 100644 --- a/examples/Console/Prompt/Program.cs +++ b/examples/Console/Prompt/Program.cs @@ -7,7 +7,7 @@ namespace Cursor public static void Main(string[] args) { // Check if we can accept key strokes - if (!AnsiConsole.Capabilities.SupportsInteraction) + if (!AnsiConsole.Profile.Capabilities.Interactive) { AnsiConsole.MarkupLine("[red]Environment does not support interaction.[/]"); return; diff --git a/src/Spectre.Console.Testing/Fakes/FakeAnsiConsole.cs b/src/Spectre.Console.Testing/Fakes/FakeAnsiConsole.cs index f92ea46..06f1e85 100644 --- a/src/Spectre.Console.Testing/Fakes/FakeAnsiConsole.cs +++ b/src/Spectre.Console.Testing/Fakes/FakeAnsiConsole.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Text; using Spectre.Console.Rendering; namespace Spectre.Console.Testing @@ -13,10 +12,7 @@ namespace Spectre.Console.Testing public string Output => _writer.ToString(); - public Capabilities Capabilities => _console.Capabilities; - public Encoding Encoding => _console.Encoding; - public int Width { get; } - public int Height => _console.Height; + public Profile Profile => _console.Profile; public IAnsiConsoleCursor Cursor => _console.Cursor; public FakeConsoleInput Input { get; } public RenderPipeline Pipeline => _console.Pipeline; @@ -24,21 +20,22 @@ namespace Spectre.Console.Testing IAnsiConsoleInput IAnsiConsole.Input => Input; public FakeAnsiConsole( - ColorSystem system, AnsiSupport ansi = AnsiSupport.Yes, - InteractionSupport interaction = InteractionSupport.Yes, + ColorSystem system, + AnsiSupport ansi = AnsiSupport.Yes, int width = 80) { _writer = new StringWriter(); - _console = AnsiConsole.Create(new AnsiConsoleSettings + + var factory = AnsiConsoleFactory.NoEnrichers(); + _console = factory.Create(new AnsiConsoleSettings { Ansi = ansi, ColorSystem = (ColorSystemSupport)system, - Interactive = interaction, Out = _writer, - LinkIdentityGenerator = new FakeLinkIdentityGenerator(1024), }); - Width = width; + _console.Profile.Width = width; + Input = new FakeConsoleInput(); } diff --git a/src/Spectre.Console.Testing/Fakes/FakeConsole.cs b/src/Spectre.Console.Testing/Fakes/FakeConsole.cs index 048b758..8aade3c 100644 --- a/src/Spectre.Console.Testing/Fakes/FakeConsole.cs +++ b/src/Spectre.Console.Testing/Fakes/FakeConsole.cs @@ -9,14 +9,10 @@ namespace Spectre.Console.Testing { public sealed class FakeConsole : IAnsiConsole, IDisposable { - public Capabilities Capabilities { get; } - public Encoding Encoding { get; } + public Profile Profile { get; } public IAnsiConsoleCursor Cursor => new FakeAnsiConsoleCursor(); public FakeConsoleInput Input { get; } - public int Width { get; } - public int Height { get; } - IAnsiConsoleInput IAnsiConsole.Input => Input; public RenderPipeline Pipeline { get; } @@ -34,13 +30,18 @@ namespace Spectre.Console.Testing bool supportsAnsi = true, ColorSystem colorSystem = ColorSystem.Standard, bool legacyConsole = false, bool interactive = true) { - Capabilities = new Capabilities(supportsAnsi, colorSystem, legacyConsole, interactive); - Encoding = encoding ?? Encoding.UTF8; - Width = width; - Height = height; Writer = new StringWriter(); Input = new FakeConsoleInput(); Pipeline = new RenderPipeline(); + + Profile = new Profile("Fake console", Writer, encoding ?? Encoding.UTF8); + Profile.Width = width; + Profile.Height = height; + Profile.ColorSystem = colorSystem; + Profile.Capabilities.Ansi = supportsAnsi; + Profile.Capabilities.Legacy = legacyConsole; + Profile.Capabilities.Interactive = interactive; + Profile.Capabilities.Links = true; } public void Dispose() diff --git a/src/Spectre.Console.Testing/Fakes/FakeLinkIdentityGenerator.cs b/src/Spectre.Console.Testing/Fakes/FakeLinkIdentityGenerator.cs deleted file mode 100644 index 41f9443..0000000 --- a/src/Spectre.Console.Testing/Fakes/FakeLinkIdentityGenerator.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Spectre.Console.Testing -{ - public sealed class FakeLinkIdentityGenerator : ILinkIdentityGenerator - { - private readonly int _linkId; - - public FakeLinkIdentityGenerator(int linkId) - { - _linkId = linkId; - } - - public int GenerateId(string link, string text) - { - return _linkId; - } - } -} diff --git a/src/Spectre.Console.Tests/Constants.cs b/src/Spectre.Console.Tests/Constants.cs index 8c287e7..9d5b926 100644 --- a/src/Spectre.Console.Tests/Constants.cs +++ b/src/Spectre.Console.Tests/Constants.cs @@ -1,3 +1,5 @@ +using Spectre.Console.Cli; + namespace Spectre.Console.Tests { public static class Constants @@ -5,15 +7,15 @@ namespace Spectre.Console.Tests public static string[] VersionCommand { get; } = new[] { - Spectre.Console.Cli.Internal.Constants.Commands.Branch, - Spectre.Console.Cli.Internal.Constants.Commands.Version, + CliConstants.Commands.Branch, + CliConstants.Commands.Version, }; public static string[] XmlDocCommand { get; } = new[] { - Spectre.Console.Cli.Internal.Constants.Commands.Branch, - Spectre.Console.Cli.Internal.Constants.Commands.XmlDoc, + CliConstants.Commands.Branch, + CliConstants.Commands.XmlDoc, }; } } diff --git a/src/Spectre.Console.Tests/Data/Exceptions.cs b/src/Spectre.Console.Tests/Data/Exceptions.cs index 7dfa4d9..f67979d 100644 --- a/src/Spectre.Console.Tests/Data/Exceptions.cs +++ b/src/Spectre.Console.Tests/Data/Exceptions.cs @@ -1,14 +1,11 @@ using System; -using System.Diagnostics.CodeAnalysis; namespace Spectre.Console.Tests.Data { public static class TestExceptions { - [SuppressMessage("Usage", "CA1801:Review unused parameters", Justification = "")] public static bool MethodThatThrows(int? number) => throw new InvalidOperationException("Throwing!"); - [SuppressMessage("Usage", "CA1801:Review unused parameters", Justification = "")] public static bool GenericMethodThatThrows(int? number) => throw new InvalidOperationException("Throwing!"); public static void ThrowWithInnerException() diff --git a/src/Spectre.Console.Tests/Data/Settings/ArgumentVectorSettings.cs b/src/Spectre.Console.Tests/Data/Settings/ArgumentVectorSettings.cs index eefa000..c6a2c66 100644 --- a/src/Spectre.Console.Tests/Data/Settings/ArgumentVectorSettings.cs +++ b/src/Spectre.Console.Tests/Data/Settings/ArgumentVectorSettings.cs @@ -1,4 +1,3 @@ -using System.Diagnostics.CodeAnalysis; using Spectre.Console.Cli; namespace Spectre.Console.Tests.Data @@ -6,7 +5,6 @@ namespace Spectre.Console.Tests.Data public class ArgumentVectorSettings : CommandSettings { [CommandArgument(0, "")] - [SuppressMessage("Performance", "CA1819:Properties should not return arrays")] public string[] Foo { get; set; } } } diff --git a/src/Spectre.Console.Tests/Data/Settings/MultipleArgumentVectorSettings.cs b/src/Spectre.Console.Tests/Data/Settings/MultipleArgumentVectorSettings.cs index 992a92e..8a6bb3f 100644 --- a/src/Spectre.Console.Tests/Data/Settings/MultipleArgumentVectorSettings.cs +++ b/src/Spectre.Console.Tests/Data/Settings/MultipleArgumentVectorSettings.cs @@ -1,4 +1,3 @@ -using System.Diagnostics.CodeAnalysis; using Spectre.Console.Cli; namespace Spectre.Console.Tests.Data @@ -6,18 +5,15 @@ namespace Spectre.Console.Tests.Data public class MultipleArgumentVectorSettings : CommandSettings { [CommandArgument(0, "")] - [SuppressMessage("Performance", "CA1819:Properties should not return arrays")] public string[] Foo { get; set; } [CommandArgument(0, "")] - [SuppressMessage("Performance", "CA1819:Properties should not return arrays")] public string[] Bar { get; set; } } public class MultipleArgumentVectorSpecifiedFirstSettings : CommandSettings { [CommandArgument(0, "")] - [SuppressMessage("Performance", "CA1819:Properties should not return arrays")] public string[] Foo { get; set; } [CommandArgument(1, "")] diff --git a/src/Spectre.Console.Tests/Data/Settings/OptionVectorSettings.cs b/src/Spectre.Console.Tests/Data/Settings/OptionVectorSettings.cs index e8296e4..d7e8a17 100644 --- a/src/Spectre.Console.Tests/Data/Settings/OptionVectorSettings.cs +++ b/src/Spectre.Console.Tests/Data/Settings/OptionVectorSettings.cs @@ -1,4 +1,3 @@ -using System.Diagnostics.CodeAnalysis; using Spectre.Console.Cli; namespace Spectre.Console.Tests.Data @@ -6,11 +5,9 @@ namespace Spectre.Console.Tests.Data public class OptionVectorSettings : CommandSettings { [CommandOption("--foo")] - [SuppressMessage("Performance", "CA1819:Properties should not return arrays")] public string[] Foo { get; set; } [CommandOption("--bar")] - [SuppressMessage("Performance", "CA1819:Properties should not return arrays")] public int[] Bar { get; set; } } } diff --git a/src/Spectre.Console.Tests/Spectre.Console.Tests.v3.ncrunchproject b/src/Spectre.Console.Tests/Spectre.Console.Tests.v3.ncrunchproject index 2bc3e06..95a483b 100644 --- a/src/Spectre.Console.Tests/Spectre.Console.Tests.v3.ncrunchproject +++ b/src/Spectre.Console.Tests/Spectre.Console.Tests.v3.ncrunchproject @@ -1,18 +1,3 @@  - - - - Spectre.Console.Tests.Unit.Cli.CommandAppTests+Parsing+UnknownCommand.Should_Return_Correct_Text_With_Suggestion_And_No_Arguments_When_Root_Command_Is_Unknown_And_Distance_Is_Small - - - Spectre.Console.Tests.Unit.Cli.CommandAppTests+Parsing+UnknownCommand.Should_Return_Correct_Text_With_Suggestion_When_Command_Followed_By_Argument_Is_Unknown_And_Distance_Is_Small - - - Spectre.Console.Tests.Unit.Cli.CommandAppTests+Parsing+UnknownCommand.Should_Return_Correct_Text_With_Suggestion_When_Root_Command_After_Argument_Is_Unknown_And_Distance_Is_Small - - - Spectre.Console.Tests.Unit.Cli.CommandAppTests+Parsing+UnknownCommand.Should_Return_Correct_Text_With_Suggestion_When_Root_Command_Followed_By_Argument_Is_Unknown_And_Distance_Is_Small - - - + \ No newline at end of file diff --git a/src/Spectre.Console.Tests/Unit/AnsiConsoleTests.Markup.cs b/src/Spectre.Console.Tests/Unit/AnsiConsoleTests.Markup.cs index f8d3006..cef8a69 100644 --- a/src/Spectre.Console.Tests/Unit/AnsiConsoleTests.Markup.cs +++ b/src/Spectre.Console.Tests/Unit/AnsiConsoleTests.Markup.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; using Shouldly; using Spectre.Console.Testing; using Xunit; @@ -8,14 +7,11 @@ namespace Spectre.Console.Tests.Unit { public partial class AnsiConsoleTests { - [SuppressMessage("Naming", "CA1724:Type names should not match namespaces")] public sealed class Markup { [Theory] [InlineData("[yellow]Hello[/]", "Hello")] [InlineData("[yellow]Hello [italic]World[/]![/]", "Hello World!")] - [InlineData("[link=https://patriksvensson.se]Click to visit my blog[/]", "]8;id=1024;https://patriksvensson.se\\Click to visit my blog]8;;\\")] - [InlineData("[link]https://patriksvensson.se[/]", "]8;id=1024;https://patriksvensson.se\\https://patriksvensson.se]8;;\\")] public void Should_Output_Expected_Ansi_For_Markup(string markup, string expected) { // Given @@ -28,6 +24,32 @@ namespace Spectre.Console.Tests.Unit console.Output.ShouldBe(expected); } + [Fact] + public void Should_Output_Expected_Ansi_For_Link_With_Url_And_Text() + { + // Given + var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes); + + // When + console.Markup("[link=https://patriksvensson.se]Click to visit my blog[/]"); + + // Then + console.Output.ShouldMatch("]8;id=[0-9]*;https:\\/\\/patriksvensson\\.se\\\\Click to visit my blog]8;;\\\\"); + } + + [Fact] + public void Should_Output_Expected_Ansi_For_Link_With_Only_Url() + { + // Given + var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes); + + // When + console.Markup("[link]https://patriksvensson.se[/]"); + + // Then + console.Output.ShouldMatch("]8;id=[0-9]*;https:\\/\\/patriksvensson\\.se\\\\https:\\/\\/patriksvensson\\.se]8;;\\\\"); + } + [Theory] [InlineData("[yellow]Hello [[ World[/]", "Hello [ World")] public void Should_Be_Able_To_Escape_Tags(string markup, string expected) diff --git a/src/Spectre.Console/AnsiConsole.cs b/src/Spectre.Console/AnsiConsole.cs index dcdc80f..2d0dc20 100644 --- a/src/Spectre.Console/AnsiConsole.cs +++ b/src/Spectre.Console/AnsiConsole.cs @@ -1,5 +1,4 @@ using System; -using Spectre.Console.Internal; namespace Spectre.Console { @@ -16,6 +15,7 @@ namespace Spectre.Console ColorSystem = ColorSystemSupport.Detect, Out = System.Console.Out, }); + Created = true; return console; }); @@ -33,25 +33,9 @@ namespace Spectre.Console public static IAnsiConsoleCursor Cursor => _recorder?.Cursor ?? _console.Value.Cursor; /// - /// Gets the console's capabilities. + /// Gets the console profile. /// - public static Capabilities Capabilities => Console.Capabilities; - - /// - /// Gets the buffer width of the console. - /// - public static int Width - { - get => Console.Width; - } - - /// - /// Gets the buffer height of the console. - /// - public static int Height - { - get => Console.Height; - } + public static Profile Profile => Console.Profile; /// /// Creates a new instance @@ -61,7 +45,8 @@ namespace Spectre.Console /// An instance. public static IAnsiConsole Create(AnsiConsoleSettings settings) { - return BackendBuilder.Build(settings); + var factory = new AnsiConsoleFactory(); + return factory.Create(settings); } } } diff --git a/src/Spectre.Console/AnsiConsoleFactory.cs b/src/Spectre.Console/AnsiConsoleFactory.cs new file mode 100644 index 0000000..00f9f59 --- /dev/null +++ b/src/Spectre.Console/AnsiConsoleFactory.cs @@ -0,0 +1,178 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; + +namespace Spectre.Console +{ + /// + /// Factory for creating an ANSI console. + /// + public sealed class AnsiConsoleFactory + { + private readonly List _enrichers; + + /// + /// Initializes a new instance of the class. + /// + public AnsiConsoleFactory() + { + _enrichers = new List + { + new AppVeyorProfile(), + new BambooProfile(), + new BitbucketProfile(), + new BitriseProfile(), + new ContinuaCIProfile(), + new GitHubProfile(), + new GitLabProfile(), + new GoCDProfile(), + new JenkinsProfile(), + new MyGetProfile(), + new TeamCityProfile(), + new TfsProfile(), + new TravisProfile(), + }; + } + + /// + /// Initializes a new instance of the class. + /// + /// The profile enrichers to use. + public AnsiConsoleFactory(IEnumerable enrichers) + { + _enrichers = new List(enrichers ?? Enumerable.Empty()); + } + + /// + /// Creates a new without default profile enrichers. + /// + /// A new without default profile enrichers. + public static AnsiConsoleFactory NoEnrichers() + { + return new AnsiConsoleFactory(Enumerable.Empty()); + } + + /// + /// Creates an ANSI console. + /// + /// The settings. + /// An implementation of . + public IAnsiConsole Create(AnsiConsoleSettings settings) + { + if (settings is null) + { + throw new ArgumentNullException(nameof(settings)); + } + + var buffer = settings.Out ?? System.Console.Out; + + // Detect if the terminal support ANSI or not + var (supportsAnsi, legacyConsole) = DetectAnsi(settings, buffer); + + // Use the provided encoding or fall back to UTF-8 + var encoding = buffer.IsStandardOut() ? System.Console.OutputEncoding : Encoding.UTF8; + + // Get the color system + var colorSystem = settings.ColorSystem == ColorSystemSupport.Detect + ? ColorSystemDetector.Detect(supportsAnsi) + : (ColorSystem)settings.ColorSystem; + + // Get whether or not we consider the terminal interactive + var interactive = settings.Interactive == InteractionSupport.Yes; + if (settings.Interactive == InteractionSupport.Detect) + { + interactive = Environment.UserInteractive; + } + + var profile = new Profile("Default", buffer, encoding) + { + ColorSystem = colorSystem, + }; + + profile.Capabilities.Ansi = supportsAnsi; + profile.Capabilities.Links = supportsAnsi && !legacyConsole; + profile.Capabilities.Legacy = legacyConsole; + profile.Capabilities.Interactive = interactive; + + // Enrich the profile + var variables = GetEnvironmentVariables(settings); + var customEnrichers = settings.Enrichers ?? Enumerable.Empty(); + foreach (var enricher in _enrichers.Concat(customEnrichers)) + { + if (enricher.Enabled(variables)) + { + enricher.Enrich(profile); + } + } + + return new AnsiConsoleFacade(profile); + } + + private static IDictionary GetEnvironmentVariables(AnsiConsoleSettings settings) + { + if (settings.EnvironmentVariables != null) + { + return new Dictionary(settings.EnvironmentVariables, StringComparer.OrdinalIgnoreCase); + } + + return Environment.GetEnvironmentVariables() + .Cast() + .Aggregate( + new Dictionary(StringComparer.OrdinalIgnoreCase), + (dictionary, entry) => + { + var key = (string)entry.Key; + if (!dictionary.TryGetValue(key, out _)) + { + dictionary.Add(key, entry.Value as string ?? string.Empty); + } + + return dictionary; + }, + dictionary => dictionary); + } + + private static (bool Ansi, bool Legacy) DetectAnsi(AnsiConsoleSettings settings, System.IO.TextWriter buffer) + { + var supportsAnsi = settings.Ansi == AnsiSupport.Yes; + var legacyConsole = false; + + if (settings.Ansi == AnsiSupport.Detect) + { + (supportsAnsi, legacyConsole) = AnsiDetector.Detect(true); + + // Check whether or not this is a legacy console from the existing instance (if any). + // We need to do this because once we upgrade the console to support ENABLE_VIRTUAL_TERMINAL_PROCESSING + // on Windows, there is no way of detecting whether or not we're running on a legacy console or not. + if (AnsiConsole.Created && !legacyConsole && buffer.IsStandardOut() && AnsiConsole.Profile.Capabilities.Legacy) + { + legacyConsole = AnsiConsole.Profile.Capabilities.Legacy; + } + } + else + { + if (buffer.IsStandardOut()) + { + // Are we running on Windows? + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + // Not the first console we're creating? + if (AnsiConsole.Created) + { + legacyConsole = AnsiConsole.Profile.Capabilities.Legacy; + } + else + { + // Try detecting whether or not this + (_, legacyConsole) = AnsiDetector.Detect(false); + } + } + } + } + + return (supportsAnsi, legacyConsole); + } + } +} diff --git a/src/Spectre.Console/AnsiConsoleSettings.cs b/src/Spectre.Console/AnsiConsoleSettings.cs index 83db057..7cfe9ee 100644 --- a/src/Spectre.Console/AnsiConsoleSettings.cs +++ b/src/Spectre.Console/AnsiConsoleSettings.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.IO; namespace Spectre.Console @@ -19,19 +20,25 @@ namespace Spectre.Console public ColorSystemSupport ColorSystem { get; set; } /// - /// Gets or sets a value indicating whether or - /// not the console is interactive. + /// Gets or sets the out buffer. + /// + public TextWriter? Out { get; set; } + + /// + /// Gets or sets a value indicating whether or not the + /// terminal is interactive or not. /// public InteractionSupport Interactive { get; set; } /// - /// Gets or sets the link identity generator. + /// Gets or sets the environment variables. + /// If not value is provided the default environment variables will be used. /// - public ILinkIdentityGenerator? LinkIdentityGenerator { get; set; } + public Dictionary? EnvironmentVariables { get; set; } /// - /// Gets or sets the out buffer. + /// Gets or sets the profile enrichers to use. /// - public TextWriter? Out { get; set; } + public List? Enrichers { get; set; } } } diff --git a/src/Spectre.Console/Capabilities.cs b/src/Spectre.Console/Capabilities.cs index ef4c9a6..2b781a0 100644 --- a/src/Spectre.Console/Capabilities.cs +++ b/src/Spectre.Console/Capabilities.cs @@ -1,3 +1,5 @@ +using System; + namespace Spectre.Console { /// @@ -5,14 +7,16 @@ namespace Spectre.Console /// public sealed class Capabilities { - /// - /// Gets a value indicating whether or not - /// the console supports Ansi. - /// - public bool SupportsAnsi { get; } + private readonly Profile _profile; /// - /// Gets a value indicating whether or not + /// Gets or sets a value indicating whether or not + /// the console supports Ansi. + /// + public bool Ansi { get; set; } + + /// + /// Gets or sets a value indicating whether or not /// the console support links. /// /// @@ -20,69 +24,48 @@ namespace Spectre.Console /// once we have more information about the terminal /// we're running inside. /// - public bool SupportLinks => SupportsAnsi && !LegacyConsole; + public bool Links { get; set; } /// - /// Gets the color system. - /// - public ColorSystem ColorSystem { get; } - - /// - /// Gets a value indicating whether or not - /// this is a legacy console (cmd.exe). + /// Gets or sets a value indicating whether or not + /// this is a legacy console (cmd.exe) on an OS + /// prior to Windows 10. /// /// /// Only relevant when running on Microsoft Windows. /// - public bool LegacyConsole { get; } + public bool Legacy { get; set; } /// - /// Gets or sets a value indicating whether or not the console supports interaction. + /// Gets a value indicating whether console output + /// has been redirected. /// - public bool SupportsInteraction { get; set; } + public bool Tty + { + get + { + if (_profile.Out.IsStandardOut()) + { + return System.Console.IsOutputRedirected; + } + + // Not stdout, so must be a TTY. + return true; + } + } + + /// + /// Gets or sets a value indicating whether + /// or not the console supports interaction. + /// + public bool Interactive { get; set; } /// /// Initializes a new instance of the class. /// - /// Whether or not ANSI escape sequences are supported. - /// The color system that is supported. - /// Whether or not this is a legacy console. - /// Whether or not the console supports interaction. - public Capabilities(bool supportsAnsi, ColorSystem colorSystem, bool legacyConsole, bool supportsInteraction) + internal Capabilities(Profile profile) { - SupportsAnsi = supportsAnsi; - ColorSystem = colorSystem; - LegacyConsole = legacyConsole; - SupportsInteraction = supportsInteraction; - } - - /// - /// Checks whether the current capabilities supports - /// the specified color system. - /// - /// The color system to check. - /// true if the color system is supported, otherwise false. - public bool Supports(ColorSystem colorSystem) - { - return (int)colorSystem <= (int)ColorSystem; - } - - /// - public override string ToString() - { - var supportsAnsi = SupportsAnsi ? "Yes" : "No"; - var legacyConsole = LegacyConsole ? "Legacy" : "Modern"; - var bits = ColorSystem switch - { - ColorSystem.NoColors => "1 bit", - ColorSystem.Legacy => "3 bits", - ColorSystem.Standard => "4 bits", - ColorSystem.EightBit => "8 bits", - ColorSystem.TrueColor => "24 bits", - _ => "?", - }; - - return $"ANSI={supportsAnsi}, Colors={ColorSystem}, Kind={legacyConsole} ({bits})"; + _profile = profile ?? throw new ArgumentNullException(nameof(profile)); } } } diff --git a/src/Spectre.Console/Cli/Annotations/CommandArgumentAttribute.cs b/src/Spectre.Console/Cli/Annotations/CommandArgumentAttribute.cs index 319ab3e..0e0c6a2 100644 --- a/src/Spectre.Console/Cli/Annotations/CommandArgumentAttribute.cs +++ b/src/Spectre.Console/Cli/Annotations/CommandArgumentAttribute.cs @@ -1,5 +1,4 @@ using System; -using Spectre.Console.Cli.Internal; namespace Spectre.Console.Cli { diff --git a/src/Spectre.Console/Cli/Annotations/CommandOptionAttribute.cs b/src/Spectre.Console/Cli/Annotations/CommandOptionAttribute.cs index 348b03f..86a8537 100644 --- a/src/Spectre.Console/Cli/Annotations/CommandOptionAttribute.cs +++ b/src/Spectre.Console/Cli/Annotations/CommandOptionAttribute.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Spectre.Console.Cli.Internal; namespace Spectre.Console.Cli { diff --git a/src/Spectre.Console/Cli/CaseSensitivity.cs b/src/Spectre.Console/Cli/CaseSensitivity.cs index c9331b6..e1ee9d4 100644 --- a/src/Spectre.Console/Cli/CaseSensitivity.cs +++ b/src/Spectre.Console/Cli/CaseSensitivity.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; namespace Spectre.Console.Cli { @@ -7,7 +6,6 @@ namespace Spectre.Console.Cli /// Represents case sensitivity. /// [Flags] - [SuppressMessage("Naming", "CA1714:Flags enums should have plural names")] public enum CaseSensitivity { /// diff --git a/src/Spectre.Console/Cli/CommandApp.cs b/src/Spectre.Console/Cli/CommandApp.cs index 4d051d7..3e857fb 100644 --- a/src/Spectre.Console/Cli/CommandApp.cs +++ b/src/Spectre.Console/Cli/CommandApp.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading.Tasks; -using Spectre.Console.Cli.Internal; using Spectre.Console.Rendering; namespace Spectre.Console.Cli @@ -74,11 +73,11 @@ namespace Spectre.Console.Cli if (!_executed) { // Add built-in (hidden) commands. - _configurator.AddBranch(Constants.Commands.Branch, cli => + _configurator.AddBranch(CliConstants.Commands.Branch, cli => { cli.HideBranch(); - cli.AddCommand(Constants.Commands.Version); - cli.AddCommand(Constants.Commands.XmlDoc); + cli.AddCommand(CliConstants.Commands.Version); + cli.AddCommand(CliConstants.Commands.XmlDoc); }); _executed = true; diff --git a/src/Spectre.Console/Cli/CommandConfigurationException.cs b/src/Spectre.Console/Cli/CommandConfigurationException.cs index de24650..3f6dce3 100644 --- a/src/Spectre.Console/Cli/CommandConfigurationException.cs +++ b/src/Spectre.Console/Cli/CommandConfigurationException.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using Spectre.Console.Cli.Internal; using Spectre.Console.Rendering; namespace Spectre.Console.Cli diff --git a/src/Spectre.Console/Cli/CommandParseException.cs b/src/Spectre.Console/Cli/CommandParseException.cs index 638fbc2..00c2c81 100644 --- a/src/Spectre.Console/Cli/CommandParseException.cs +++ b/src/Spectre.Console/Cli/CommandParseException.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using Spectre.Console.Cli.Internal; using Spectre.Console.Rendering; namespace Spectre.Console.Cli diff --git a/src/Spectre.Console/Cli/CommandRuntimeException.cs b/src/Spectre.Console/Cli/CommandRuntimeException.cs index d45f764..f498ac4 100644 --- a/src/Spectre.Console/Cli/CommandRuntimeException.cs +++ b/src/Spectre.Console/Cli/CommandRuntimeException.cs @@ -1,5 +1,4 @@ using System; -using Spectre.Console.Cli.Internal; using Spectre.Console.Rendering; namespace Spectre.Console.Cli @@ -33,7 +32,7 @@ namespace Spectre.Console.Cli internal static CommandRuntimeException MissingRequiredArgument(CommandTree node, CommandArgument argument) { - if (node.Command.Name == Constants.DefaultCommandName) + if (node.Command.Name == CliConstants.DefaultCommandName) { return new CommandRuntimeException($"Missing required argument '{argument.Value}'."); } diff --git a/src/Spectre.Console/Cli/CommandTemplateException.cs b/src/Spectre.Console/Cli/CommandTemplateException.cs index 4e89e55..0d31bca 100644 --- a/src/Spectre.Console/Cli/CommandTemplateException.cs +++ b/src/Spectre.Console/Cli/CommandTemplateException.cs @@ -1,5 +1,4 @@ using System.Globalization; -using Spectre.Console.Cli.Internal; using Spectre.Console.Rendering; namespace Spectre.Console.Cli diff --git a/src/Spectre.Console/Cli/Internal/Binding/CommandConstructorBinder.cs b/src/Spectre.Console/Cli/Internal/Binding/CommandConstructorBinder.cs index c32d2c7..f2c473a 100644 --- a/src/Spectre.Console/Cli/Internal/Binding/CommandConstructorBinder.cs +++ b/src/Spectre.Console/Cli/Internal/Binding/CommandConstructorBinder.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Reflection; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandConstructorBinder { diff --git a/src/Spectre.Console/Cli/Internal/Binding/CommandPropertyBinder.cs b/src/Spectre.Console/Cli/Internal/Binding/CommandPropertyBinder.cs index f0275a1..5b9a2e0 100644 --- a/src/Spectre.Console/Cli/Internal/Binding/CommandPropertyBinder.cs +++ b/src/Spectre.Console/Cli/Internal/Binding/CommandPropertyBinder.cs @@ -1,6 +1,6 @@ using System; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandPropertyBinder { diff --git a/src/Spectre.Console/Cli/Internal/Binding/CommandValueBinder.cs b/src/Spectre.Console/Cli/Internal/Binding/CommandValueBinder.cs index 490fbcb..38a206e 100644 --- a/src/Spectre.Console/Cli/Internal/Binding/CommandValueBinder.cs +++ b/src/Spectre.Console/Cli/Internal/Binding/CommandValueBinder.cs @@ -1,6 +1,6 @@ using System; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class CommandValueBinder { diff --git a/src/Spectre.Console/Cli/Internal/Binding/CommandValueLookup.cs b/src/Spectre.Console/Cli/Internal/Binding/CommandValueLookup.cs index 7f305ff..721ba09 100644 --- a/src/Spectre.Console/Cli/Internal/Binding/CommandValueLookup.cs +++ b/src/Spectre.Console/Cli/Internal/Binding/CommandValueLookup.cs @@ -3,7 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class CommandValueLookup : IEnumerable<(CommandParameter Parameter, object? Value)> { diff --git a/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs b/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs index 92dd946..b87eea2 100644 --- a/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs +++ b/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs @@ -2,7 +2,7 @@ using System; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandValueResolver { diff --git a/src/Spectre.Console/Cli/Internal/Collections/IMultiMap.cs b/src/Spectre.Console/Cli/Internal/Collections/IMultiMap.cs index fb6ccd6..dea8012 100644 --- a/src/Spectre.Console/Cli/Internal/Collections/IMultiMap.cs +++ b/src/Spectre.Console/Cli/Internal/Collections/IMultiMap.cs @@ -1,4 +1,4 @@ -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { /// /// Representation of a multi map. diff --git a/src/Spectre.Console/Cli/Internal/Collections/MultiMap.cs b/src/Spectre.Console/Cli/Internal/Collections/MultiMap.cs index f61654a..4a249fd 100644 --- a/src/Spectre.Console/Cli/Internal/Collections/MultiMap.cs +++ b/src/Spectre.Console/Cli/Internal/Collections/MultiMap.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { [SuppressMessage("Performance", "CA1812: Avoid uninstantiated internal classes")] internal sealed class MultiMap : IMultiMap, ILookup, IDictionary, IReadOnlyDictionary diff --git a/src/Spectre.Console/Cli/Internal/CommandBinder.cs b/src/Spectre.Console/Cli/Internal/CommandBinder.cs index 4549b46..4aed252 100644 --- a/src/Spectre.Console/Cli/Internal/CommandBinder.cs +++ b/src/Spectre.Console/Cli/Internal/CommandBinder.cs @@ -1,6 +1,6 @@ using System; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandBinder { diff --git a/src/Spectre.Console/Cli/Internal/CommandExecutor.cs b/src/Spectre.Console/Cli/Internal/CommandExecutor.cs index 7a51dbe..01612b1 100644 --- a/src/Spectre.Console/Cli/Internal/CommandExecutor.cs +++ b/src/Spectre.Console/Cli/Internal/CommandExecutor.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class CommandExecutor { diff --git a/src/Spectre.Console/Cli/Internal/CommandPart.cs b/src/Spectre.Console/Cli/Internal/CommandPart.cs index f089f17..8ba522e 100644 --- a/src/Spectre.Console/Cli/Internal/CommandPart.cs +++ b/src/Spectre.Console/Cli/Internal/CommandPart.cs @@ -1,4 +1,4 @@ -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal enum CommandPart { diff --git a/src/Spectre.Console/Cli/Internal/CommandSuggestor.cs b/src/Spectre.Console/Cli/Internal/CommandSuggestor.cs index bf29af0..b9ca210 100644 --- a/src/Spectre.Console/Cli/Internal/CommandSuggestor.cs +++ b/src/Spectre.Console/Cli/Internal/CommandSuggestor.cs @@ -1,7 +1,7 @@ using System; using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandSuggestor { diff --git a/src/Spectre.Console/Cli/Internal/CommandValidator.cs b/src/Spectre.Console/Cli/Internal/CommandValidator.cs index 663fa28..8be072c 100644 --- a/src/Spectre.Console/Cli/Internal/CommandValidator.cs +++ b/src/Spectre.Console/Cli/Internal/CommandValidator.cs @@ -1,4 +1,4 @@ -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandValidator { diff --git a/src/Spectre.Console/Cli/Internal/Commands/VersionCommand.cs b/src/Spectre.Console/Cli/Internal/Commands/VersionCommand.cs index bdf77ff..2fae7ff 100644 --- a/src/Spectre.Console/Cli/Internal/Commands/VersionCommand.cs +++ b/src/Spectre.Console/Cli/Internal/Commands/VersionCommand.cs @@ -1,7 +1,7 @@ using System.ComponentModel; using System.Diagnostics.CodeAnalysis; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { [Description("Displays the CLI library version")] [SuppressMessage("Performance", "CA1812: Avoid uninstantiated internal classes")] diff --git a/src/Spectre.Console/Cli/Internal/Commands/XmlDocCommand.cs b/src/Spectre.Console/Cli/Internal/Commands/XmlDocCommand.cs index 99aae57..49645c6 100644 --- a/src/Spectre.Console/Cli/Internal/Commands/XmlDocCommand.cs +++ b/src/Spectre.Console/Cli/Internal/Commands/XmlDocCommand.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Xml; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { [Description("Generates an XML representation of the CLI configuration.")] [SuppressMessage("Performance", "CA1812: Avoid uninstantiated internal classes")] diff --git a/src/Spectre.Console/Cli/Internal/Composer.cs b/src/Spectre.Console/Cli/Internal/Composer.cs index 68945fb..abdb3a3 100644 --- a/src/Spectre.Console/Cli/Internal/Composer.cs +++ b/src/Spectre.Console/Cli/Internal/Composer.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Text; using Spectre.Console.Rendering; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class Composer : IRenderable { diff --git a/src/Spectre.Console/Cli/Internal/Composition/Activators.cs b/src/Spectre.Console/Cli/Internal/Composition/Activators.cs index 86ad9f1..9150418 100644 --- a/src/Spectre.Console/Cli/Internal/Composition/Activators.cs +++ b/src/Spectre.Console/Cli/Internal/Composition/Activators.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Reflection; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal abstract class ComponentActivator { diff --git a/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistration.cs b/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistration.cs index e910950..ff1a8fc 100644 --- a/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistration.cs +++ b/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistration.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class ComponentRegistration { diff --git a/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistry.cs b/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistry.cs index c1e0730..d4ee9b1 100644 --- a/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistry.cs +++ b/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistry.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class ComponentRegistry : IDisposable { diff --git a/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeRegistrar.cs b/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeRegistrar.cs index f867e0e..dab76d8 100644 --- a/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeRegistrar.cs +++ b/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeRegistrar.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class DefaultTypeRegistrar : ITypeRegistrar { diff --git a/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeResolver.cs b/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeResolver.cs index b253a73..4c2e38f 100644 --- a/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeResolver.cs +++ b/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeResolver.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class DefaultTypeResolver : IDisposable, ITypeResolver { diff --git a/src/Spectre.Console/Cli/Internal/Configuration/CommandAppSettings.cs b/src/Spectre.Console/Cli/Internal/Configuration/CommandAppSettings.cs index 9e240e0..7fbf26d 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/CommandAppSettings.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/CommandAppSettings.cs @@ -1,6 +1,6 @@ using System; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class CommandAppSettings : ICommandAppSettings { diff --git a/src/Spectre.Console/Cli/Internal/Configuration/CommandConfigurator.cs b/src/Spectre.Console/Cli/Internal/Configuration/CommandConfigurator.cs index a01d011..75d22bf 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/CommandConfigurator.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/CommandConfigurator.cs @@ -1,4 +1,4 @@ -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class CommandConfigurator : ICommandConfigurator { diff --git a/src/Spectre.Console/Cli/Internal/Configuration/ConfigurationHelper.cs b/src/Spectre.Console/Cli/Internal/Configuration/ConfigurationHelper.cs index a383ff8..7812ea8 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/ConfigurationHelper.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/ConfigurationHelper.cs @@ -2,7 +2,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Reflection; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class ConfigurationHelper { diff --git a/src/Spectre.Console/Cli/Internal/Configuration/Configurator.cs b/src/Spectre.Console/Cli/Internal/Configuration/Configurator.cs index 5bb8e67..108196d 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/Configurator.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/Configurator.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using Spectre.Console.Cli.Unsafe; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class Configurator : IUnsafeConfigurator, IConfigurator, IConfiguration { @@ -33,7 +33,7 @@ namespace Spectre.Console.Cli.Internal where TDefaultCommand : class, ICommand { DefaultCommand = ConfiguredCommand.FromType( - Constants.DefaultCommandName, isDefaultCommand: true); + CliConstants.DefaultCommandName, isDefaultCommand: true); } public ICommandConfigurator AddCommand(string name) diff --git a/src/Spectre.Console/Cli/Internal/Configuration/Configurator`1.cs b/src/Spectre.Console/Cli/Internal/Configuration/Configurator`1.cs index 386bfe3..c8f2656 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/Configurator`1.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/Configurator`1.cs @@ -1,7 +1,7 @@ using System; using Spectre.Console.Cli.Unsafe; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class Configurator : IUnsafeBranchConfigurator, IConfigurator where TSettings : CommandSettings diff --git a/src/Spectre.Console/Cli/Internal/Configuration/ConfiguredCommand.cs b/src/Spectre.Console/Cli/Internal/Configuration/ConfiguredCommand.cs index 02f1a35..06a065a 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/ConfiguredCommand.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/ConfiguredCommand.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class ConfiguredCommand { diff --git a/src/Spectre.Console/Cli/Internal/Configuration/IConfiguration.cs b/src/Spectre.Console/Cli/Internal/Configuration/IConfiguration.cs index 799c38b..6477eb3 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/IConfiguration.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/IConfiguration.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { /// /// Represents a configuration. diff --git a/src/Spectre.Console/Cli/Internal/Configuration/TemplateParser.cs b/src/Spectre.Console/Cli/Internal/Configuration/TemplateParser.cs index 2c15fae..3656bb7 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/TemplateParser.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/TemplateParser.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class TemplateParser { diff --git a/src/Spectre.Console/Cli/Internal/Configuration/TemplateToken.cs b/src/Spectre.Console/Cli/Internal/Configuration/TemplateToken.cs index 3ba1a50..c48d150 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/TemplateToken.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/TemplateToken.cs @@ -1,4 +1,4 @@ -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class TemplateToken { diff --git a/src/Spectre.Console/Cli/Internal/Configuration/TemplateTokenizer.cs b/src/Spectre.Console/Cli/Internal/Configuration/TemplateTokenizer.cs index c72996d..0a59bf2 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/TemplateTokenizer.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/TemplateTokenizer.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Text; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class TemplateTokenizer { diff --git a/src/Spectre.Console/Cli/Internal/Constants.cs b/src/Spectre.Console/Cli/Internal/Constants.cs index 42a7e47..f476945 100644 --- a/src/Spectre.Console/Cli/Internal/Constants.cs +++ b/src/Spectre.Console/Cli/Internal/Constants.cs @@ -1,6 +1,6 @@ -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { - internal static class Constants + internal static class CliConstants { public const string DefaultCommandName = "__default_command"; public const string True = "true"; diff --git a/src/Spectre.Console/Cli/Internal/DefaultPairDeconstructor.cs b/src/Spectre.Console/Cli/Internal/DefaultPairDeconstructor.cs index 64134ef..ed7279a 100644 --- a/src/Spectre.Console/Cli/Internal/DefaultPairDeconstructor.cs +++ b/src/Spectre.Console/Cli/Internal/DefaultPairDeconstructor.cs @@ -2,7 +2,7 @@ using System; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { [SuppressMessage("Performance", "CA1812: Avoid uninstantiated internal classes")] internal sealed class DefaultPairDeconstructor : IPairDeconstructor diff --git a/src/Spectre.Console/Cli/Internal/DelegateCommand.cs b/src/Spectre.Console/Cli/Internal/DelegateCommand.cs index 342e522..23cb7a7 100644 --- a/src/Spectre.Console/Cli/Internal/DelegateCommand.cs +++ b/src/Spectre.Console/Cli/Internal/DelegateCommand.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class DelegateCommand : ICommand { diff --git a/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineParseExceptionFactory.cs b/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineParseExceptionFactory.cs index 94304d5..a9902ac 100644 --- a/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineParseExceptionFactory.cs +++ b/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineParseExceptionFactory.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using Spectre.Console.Rendering; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandLineParseExceptionFactory { diff --git a/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineTemplateExceptionFactory.cs b/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineTemplateExceptionFactory.cs index 1ba7373..4ce00d5 100644 --- a/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineTemplateExceptionFactory.cs +++ b/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineTemplateExceptionFactory.cs @@ -1,6 +1,6 @@ using Spectre.Console.Rendering; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandLineTemplateExceptionFactory { diff --git a/src/Spectre.Console/Cli/Internal/Extensions/AnsiConsoleExtensions.cs b/src/Spectre.Console/Cli/Internal/Extensions/AnsiConsoleExtensions.cs index 47d28ac..82c5ac4 100644 --- a/src/Spectre.Console/Cli/Internal/Extensions/AnsiConsoleExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Extensions/AnsiConsoleExtensions.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using Spectre.Console.Rendering; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class AnsiConsoleExtensions { diff --git a/src/Spectre.Console/Cli/Internal/Extensions/CaseSensitivityExtensions.cs b/src/Spectre.Console/Cli/Internal/Extensions/CaseSensitivityExtensions.cs index 3b7e1fd..9ce2814 100644 --- a/src/Spectre.Console/Cli/Internal/Extensions/CaseSensitivityExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Extensions/CaseSensitivityExtensions.cs @@ -1,6 +1,6 @@ using System; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CaseSensitivityExtensions { diff --git a/src/Spectre.Console/Cli/Internal/Extensions/ListExtensions.cs b/src/Spectre.Console/Cli/Internal/Extensions/ListExtensions.cs index 82fb62f..c9f22ae 100644 --- a/src/Spectre.Console/Cli/Internal/Extensions/ListExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Extensions/ListExtensions.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class ListExtensions { diff --git a/src/Spectre.Console/Cli/Internal/Extensions/TypeExtensions.cs b/src/Spectre.Console/Cli/Internal/Extensions/TypeExtensions.cs index b192542..1eb500b 100644 --- a/src/Spectre.Console/Cli/Internal/Extensions/TypeExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Extensions/TypeExtensions.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class TypeExtensions { diff --git a/src/Spectre.Console/Cli/Internal/Extensions/TypeRegistrarExtensions.cs b/src/Spectre.Console/Cli/Internal/Extensions/TypeRegistrarExtensions.cs index b0aeb79..3b2a00a 100644 --- a/src/Spectre.Console/Cli/Internal/Extensions/TypeRegistrarExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Extensions/TypeRegistrarExtensions.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class TypeRegistrarExtensions { diff --git a/src/Spectre.Console/Cli/Internal/Extensions/XmlElementExtensions.cs b/src/Spectre.Console/Cli/Internal/Extensions/XmlElementExtensions.cs index b317001..1eaa098 100644 --- a/src/Spectre.Console/Cli/Internal/Extensions/XmlElementExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Extensions/XmlElementExtensions.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Reflection; using System.Xml; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class XmlElementExtensions { diff --git a/src/Spectre.Console/Cli/Internal/HelpWriter.cs b/src/Spectre.Console/Cli/Internal/HelpWriter.cs index f3f5f23..e9910a9 100644 --- a/src/Spectre.Console/Cli/Internal/HelpWriter.cs +++ b/src/Spectre.Console/Cli/Internal/HelpWriter.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using Spectre.Console.Rendering; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class HelpWriter { diff --git a/src/Spectre.Console/Cli/Internal/IPairDeconstructor.cs b/src/Spectre.Console/Cli/Internal/IPairDeconstructor.cs index 943a5a4..2b5d383 100644 --- a/src/Spectre.Console/Cli/Internal/IPairDeconstructor.cs +++ b/src/Spectre.Console/Cli/Internal/IPairDeconstructor.cs @@ -1,6 +1,6 @@ using System; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { /// /// Represents a pair deconstructor. diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandArgument.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandArgument.cs index 7efe1e5..ceba760 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandArgument.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandArgument.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Reflection; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class CommandArgument : CommandParameter { diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandContainerExtensions.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandContainerExtensions.cs index 6ca1ef7..fbf7419 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandContainerExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandContainerExtensions.cs @@ -1,6 +1,6 @@ using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandContainerExtensions { diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandInfo.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandInfo.cs index ad5160d..9dcb1b6 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandInfo.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandInfo.cs @@ -4,7 +4,7 @@ using System.ComponentModel; using System.Linq; using System.Reflection; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class CommandInfo : ICommandContainer { diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandInfoExtensions.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandInfoExtensions.cs index ce2c361..00940a7 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandInfoExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandInfoExtensions.cs @@ -1,6 +1,6 @@ using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandInfoExtensions { diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandModel.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandModel.cs index bb7a55c..4dfac7d 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandModel.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandModel.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Reflection; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class CommandModel : ICommandContainer { diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandModelBuilder.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandModelBuilder.cs index 5c7f293..585da75 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandModelBuilder.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandModelBuilder.cs @@ -4,7 +4,7 @@ using System.ComponentModel; using System.Linq; using System.Reflection; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandModelBuilder { diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandModelValidator.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandModelValidator.cs index 04ba058..ea6a5ba 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandModelValidator.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandModelValidator.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandModelValidator { diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandOption.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandOption.cs index ec50c0f..f008988 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandOption.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandOption.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Reflection; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class CommandOption : CommandParameter { diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandParameter.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandParameter.cs index f423c67..30722b5 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandParameter.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandParameter.cs @@ -4,7 +4,7 @@ using System.ComponentModel; using System.Linq; using System.Reflection; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal abstract class CommandParameter : ICommandParameterInfo { diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandParameterComparer.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandParameterComparer.cs index 827f1d2..b5ccf16 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandParameterComparer.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandParameterComparer.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandParameterComparer { diff --git a/src/Spectre.Console/Cli/Internal/Modelling/ICommandContainer.cs b/src/Spectre.Console/Cli/Internal/Modelling/ICommandContainer.cs index aa64ee3..7e28721 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/ICommandContainer.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/ICommandContainer.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { /// /// Represents a command container. diff --git a/src/Spectre.Console/Cli/Internal/Modelling/ParameterKind.cs b/src/Spectre.Console/Cli/Internal/Modelling/ParameterKind.cs index b3ed8b0..bf0541c 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/ParameterKind.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/ParameterKind.cs @@ -1,6 +1,6 @@ using System.ComponentModel; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal enum ParameterKind { diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTree.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTree.cs index c7f554a..a11ef65 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTree.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTree.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class CommandTree { diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeExtensions.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeExtensions.cs index e349f91..8819423 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeExtensions.cs @@ -1,7 +1,7 @@ using System; using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandTreeExtensions { diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParser.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParser.cs index 974d80d..a5d4930 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParser.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParser.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal class CommandTreeParser { @@ -317,7 +317,7 @@ namespace Spectre.Console.Cli.Internal { if (parameter.ParameterKind == ParameterKind.Flag) { - if (!Constants.AcceptedBooleanValues.Contains(valueToken.Value, StringComparer.OrdinalIgnoreCase)) + if (!CliConstants.AcceptedBooleanValues.Contains(valueToken.Value, StringComparer.OrdinalIgnoreCase)) { // Flags cannot be assigned a value. throw CommandParseException.CannotAssignValueToFlag(context.Arguments, token); diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParserContext.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParserContext.cs index 1c98bd3..044b9f8 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParserContext.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParserContext.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal class CommandTreeParserContext { diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParserResult.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParserResult.cs index b3132b1..0a2e8af 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParserResult.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParserResult.cs @@ -1,4 +1,4 @@ -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { // Consider removing this in favor for value tuples at some point. internal sealed class CommandTreeParserResult diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeToken.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeToken.cs index a65d603..5ed8a16 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeToken.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeToken.cs @@ -1,4 +1,4 @@ -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class CommandTreeToken { diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenStream.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenStream.cs index 5521d85..6322ecd 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenStream.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenStream.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class CommandTreeTokenStream : IReadOnlyList { diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizer.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizer.cs index 6495b94..b27a421 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizer.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizer.cs @@ -3,7 +3,7 @@ using System.Globalization; using System.Linq; using System.Text; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class CommandTreeTokenizer { diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizerContext.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizerContext.cs index c6cdb24..d4c7f61 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizerContext.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizerContext.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Text; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class CommandTreeTokenizerContext { diff --git a/src/Spectre.Console/Cli/Internal/Parsing/MappedCommandParameter.cs b/src/Spectre.Console/Cli/Internal/Parsing/MappedCommandParameter.cs index 51a6d6d..b68b385 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/MappedCommandParameter.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/MappedCommandParameter.cs @@ -1,4 +1,4 @@ -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { // Consider removing this in favor for value tuples at some point. internal sealed class MappedCommandParameter diff --git a/src/Spectre.Console/Cli/Internal/ParsingMode.cs b/src/Spectre.Console/Cli/Internal/ParsingMode.cs index 83e6fe8..78abbfe 100644 --- a/src/Spectre.Console/Cli/Internal/ParsingMode.cs +++ b/src/Spectre.Console/Cli/Internal/ParsingMode.cs @@ -1,4 +1,4 @@ -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal enum ParsingMode { diff --git a/src/Spectre.Console/Cli/Internal/RemainingArguments.cs b/src/Spectre.Console/Cli/Internal/RemainingArguments.cs index c5951db..dafeec1 100644 --- a/src/Spectre.Console/Cli/Internal/RemainingArguments.cs +++ b/src/Spectre.Console/Cli/Internal/RemainingArguments.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class RemainingArguments : IRemainingArguments { diff --git a/src/Spectre.Console/Cli/Internal/StringWriterWithEncoding.cs b/src/Spectre.Console/Cli/Internal/StringWriterWithEncoding.cs index 89efbb1..948ea26 100644 --- a/src/Spectre.Console/Cli/Internal/StringWriterWithEncoding.cs +++ b/src/Spectre.Console/Cli/Internal/StringWriterWithEncoding.cs @@ -2,7 +2,7 @@ using System; using System.IO; using System.Text; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class StringWriterWithEncoding : StringWriter { diff --git a/src/Spectre.Console/Cli/Internal/TextBuffer.cs b/src/Spectre.Console/Cli/Internal/TextBuffer.cs index 41ee2c2..9490e53 100644 --- a/src/Spectre.Console/Cli/Internal/TextBuffer.cs +++ b/src/Spectre.Console/Cli/Internal/TextBuffer.cs @@ -1,13 +1,11 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.IO; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class TextBuffer : IDisposable { // There is some kind of bug - [SuppressMessage("Usage", "CA2213:Disposable fields should be disposed", Justification = "VS bug")] private readonly StringReader _reader; public bool ReachedEnd => _reader.Peek() == -1; diff --git a/src/Spectre.Console/Cli/Internal/TypeRegistrar.cs b/src/Spectre.Console/Cli/Internal/TypeRegistrar.cs index 00213d7..201c104 100644 --- a/src/Spectre.Console/Cli/Internal/TypeRegistrar.cs +++ b/src/Spectre.Console/Cli/Internal/TypeRegistrar.cs @@ -1,6 +1,6 @@ using System; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class TypeRegistrar : ITypeRegistrarFrontend { diff --git a/src/Spectre.Console/Cli/Internal/TypeResolverAdapter.cs b/src/Spectre.Console/Cli/Internal/TypeResolverAdapter.cs index 85c5f54..c757c42 100644 --- a/src/Spectre.Console/Cli/Internal/TypeResolverAdapter.cs +++ b/src/Spectre.Console/Cli/Internal/TypeResolverAdapter.cs @@ -1,6 +1,6 @@ using System; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal sealed class TypeResolverAdapter : ITypeResolver { diff --git a/src/Spectre.Console/Cli/Internal/VersionHelper.cs b/src/Spectre.Console/Cli/Internal/VersionHelper.cs index dcd50b4..39ce465 100644 --- a/src/Spectre.Console/Cli/Internal/VersionHelper.cs +++ b/src/Spectre.Console/Cli/Internal/VersionHelper.cs @@ -1,12 +1,10 @@ using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Reflection; -namespace Spectre.Console.Cli.Internal +namespace Spectre.Console.Cli { internal static class VersionHelper { - [SuppressMessage("Design", "CA1031:Do not catch general exception types")] public static string GetVersion(Assembly? assembly) { if (assembly == null) diff --git a/src/Spectre.Console/Cli/PairDeconstuctor.cs b/src/Spectre.Console/Cli/PairDeconstuctor.cs index 6fd8653..efb49cd 100644 --- a/src/Spectre.Console/Cli/PairDeconstuctor.cs +++ b/src/Spectre.Console/Cli/PairDeconstuctor.cs @@ -1,5 +1,4 @@ using System; -using Spectre.Console.Cli.Internal; namespace Spectre.Console.Cli { diff --git a/src/Spectre.Console/Color.cs b/src/Spectre.Console/Color.cs index c97bc00..36e51cb 100644 --- a/src/Spectre.Console/Color.cs +++ b/src/Spectre.Console/Color.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics; using System.Globalization; -using Spectre.Console.Internal; namespace Spectre.Console { diff --git a/src/Spectre.Console/Decoration.cs b/src/Spectre.Console/Decoration.cs index 4336eb9..c759a58 100644 --- a/src/Spectre.Console/Decoration.cs +++ b/src/Spectre.Console/Decoration.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; namespace Spectre.Console { @@ -10,7 +9,6 @@ namespace Spectre.Console /// Support for text decorations is up to the terminal. /// [Flags] - [SuppressMessage("Naming", "CA1714:Flags enums should have plural names")] public enum Decoration { /// diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs index 45ea97e..e150b1f 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs @@ -1,6 +1,5 @@ using System; using System.Globalization; -using Spectre.Console.Internal; namespace Spectre.Console { diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Rendering.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Rendering.cs index ed281a6..9849aab 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Rendering.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Rendering.cs @@ -26,7 +26,7 @@ namespace Spectre.Console throw new ArgumentNullException(nameof(renderable)); } - var context = new RenderContext(console.Encoding, console.Capabilities.LegacyConsole); + var context = new RenderContext(console.Profile.Encoding, console.Profile.Capabilities.Legacy); var renderables = console.Pipeline.Process(context, new[] { renderable }); Render(console, context, renderables); @@ -37,7 +37,7 @@ namespace Spectre.Console var result = new List(); foreach (var renderable in renderables) { - result.AddRange(renderable.Render(options, console.Width)); + result.AddRange(renderable.Render(options, console.Profile.Width)); } console.Write(Segment.Merge(result)); diff --git a/src/Spectre.Console/Extensions/DayOfWeekExtensions.cs b/src/Spectre.Console/Extensions/DayOfWeekExtensions.cs index f62ed10..8b597c3 100644 --- a/src/Spectre.Console/Extensions/DayOfWeekExtensions.cs +++ b/src/Spectre.Console/Extensions/DayOfWeekExtensions.cs @@ -1,7 +1,7 @@ using System; using System.Globalization; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class DayOfWeekExtensions { diff --git a/src/Spectre.Console/Extensions/DictionaryExtensions.cs b/src/Spectre.Console/Extensions/DictionaryExtensions.cs index bee3b3d..fdba057 100644 --- a/src/Spectre.Console/Extensions/DictionaryExtensions.cs +++ b/src/Spectre.Console/Extensions/DictionaryExtensions.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class DictionaryExtensions { diff --git a/src/Spectre.Console/Extensions/EnumerableExtensions.cs b/src/Spectre.Console/Extensions/EnumerableExtensions.cs index 0ee405d..ef1b7b8 100644 --- a/src/Spectre.Console/Extensions/EnumerableExtensions.cs +++ b/src/Spectre.Console/Extensions/EnumerableExtensions.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class EnumerableExtensions { diff --git a/src/Spectre.Console/Extensions/ExceptionExtensions.cs b/src/Spectre.Console/Extensions/ExceptionExtensions.cs index e34c0e8..aa0c0aa 100644 --- a/src/Spectre.Console/Extensions/ExceptionExtensions.cs +++ b/src/Spectre.Console/Extensions/ExceptionExtensions.cs @@ -1,5 +1,4 @@ using System; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Extensions/GridExtensions.cs b/src/Spectre.Console/Extensions/GridExtensions.cs index be3dbe2..fbd3bb1 100644 --- a/src/Spectre.Console/Extensions/GridExtensions.cs +++ b/src/Spectre.Console/Extensions/GridExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Extensions/Obsolete/ObsoleteAlignableExtensions.cs b/src/Spectre.Console/Extensions/Obsolete/ObsoleteAlignableExtensions.cs deleted file mode 100644 index e15a6ed..0000000 --- a/src/Spectre.Console/Extensions/Obsolete/ObsoleteAlignableExtensions.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Spectre.Console -{ - /// - /// Contains extension methods for . - /// - public static class ObsoleteAlignableExtensions - { - /// - /// Sets the alignment for an object. - /// - /// The alignable object type. - /// The alignable object. - /// The alignment. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Alignment(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static T SetAlignment(this T obj, Justify alignment) - where T : class, IAlignable - { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - - obj.Alignment = alignment; - return obj; - } - } -} diff --git a/src/Spectre.Console/Extensions/Obsolete/ObsoleteCalendarExtensions.cs b/src/Spectre.Console/Extensions/Obsolete/ObsoleteCalendarExtensions.cs deleted file mode 100644 index c654b6b..0000000 --- a/src/Spectre.Console/Extensions/Obsolete/ObsoleteCalendarExtensions.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Spectre.Console -{ - /// - /// Contains extension methods for . - /// - public static class ObsoleteCalendarExtensions - { - /// - /// Sets the calendar's highlight . - /// - /// The calendar. - /// The highlight style. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use HighlightStyle(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Calendar SetHighlightStyle(this Calendar calendar, Style? style) - { - if (calendar is null) - { - throw new ArgumentNullException(nameof(calendar)); - } - - calendar.HightlightStyle = style ?? Style.Plain; - return calendar; - } - - /// - /// Sets the calendar's header . - /// - /// The calendar. - /// The header style. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use HeaderStyle(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Calendar SetHeaderStyle(this Calendar calendar, Style? style) - { - if (calendar is null) - { - throw new ArgumentNullException(nameof(calendar)); - } - - calendar.HeaderStyle = style ?? Style.Plain; - return calendar; - } - } -} diff --git a/src/Spectre.Console/Extensions/Obsolete/ObsoleteHasBorderExtensions.cs b/src/Spectre.Console/Extensions/Obsolete/ObsoleteHasBorderExtensions.cs deleted file mode 100644 index 0b8f6cf..0000000 --- a/src/Spectre.Console/Extensions/Obsolete/ObsoleteHasBorderExtensions.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Spectre.Console -{ - /// - /// Contains extension methods for . - /// - public static class ObsoleteHasBorderExtensions - { - /// - /// Sets the border style. - /// - /// An object type with a border. - /// The object to set the border color for. - /// The border style to set. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use BorderStyle(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static T SetBorderStyle(this T obj, Style style) - where T : class, IHasBorder - { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - - obj.BorderStyle = style; - return obj; - } - - /// - /// Sets the border color. - /// - /// An object type with a border. - /// The object to set the border color for. - /// The border color to set. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use BorderColor(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static T SetBorderColor(this T obj, Color color) - where T : class, IHasBorder - { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - - obj.BorderStyle = (obj.BorderStyle ?? Style.Plain).Foreground(color); - return obj; - } - } -} diff --git a/src/Spectre.Console/Extensions/Obsolete/ObsoleteHasBoxBorderExtensions.cs b/src/Spectre.Console/Extensions/Obsolete/ObsoleteHasBoxBorderExtensions.cs deleted file mode 100644 index 2e2b0ca..0000000 --- a/src/Spectre.Console/Extensions/Obsolete/ObsoleteHasBoxBorderExtensions.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Spectre.Console -{ - /// - /// Contains extension methods for . - /// - public static class ObsoleteHasBoxBorderExtensions - { - /// - /// Sets the border. - /// - /// An object type with a border. - /// The object to set the border for. - /// The border to use. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Border(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static T SetBorder(this T obj, BoxBorder border) - where T : class, IHasBoxBorder - { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - - obj.Border = border; - return obj; - } - } -} diff --git a/src/Spectre.Console/Extensions/Obsolete/ObsoleteHasCultureExtensions.cs b/src/Spectre.Console/Extensions/Obsolete/ObsoleteHasCultureExtensions.cs deleted file mode 100644 index 44f2452..0000000 --- a/src/Spectre.Console/Extensions/Obsolete/ObsoleteHasCultureExtensions.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.ComponentModel; -using System.Globalization; - -namespace Spectre.Console -{ - /// - /// Contains extension methods for . - /// - public static class ObsoleteHasCultureExtensions - { - /// - /// Sets the culture. - /// - /// An object type with a culture. - /// The object to set the culture for. - /// The culture to set. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Culture(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static T SetCulture(this T obj, CultureInfo culture) - where T : class, IHasCulture - { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - - if (culture is null) - { - throw new ArgumentNullException(nameof(culture)); - } - - obj.Culture = culture; - return obj; - } - - /// - /// Sets the culture. - /// - /// An object type with a culture. - /// The object to set the culture for. - /// The culture to set. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Culture(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static T SetCulture(this T obj, string name) - where T : class, IHasCulture - { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - - obj.Culture = CultureInfo.GetCultureInfo(name); - return obj; - } - - /// - /// Sets the culture. - /// - /// An object type with a culture. - /// The object to set the culture for. - /// The culture to set. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Culture(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static T SetCulture(this T obj, int name) - where T : class, IHasCulture - { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - - obj.Culture = CultureInfo.GetCultureInfo(name); - return obj; - } - } -} diff --git a/src/Spectre.Console/Extensions/Obsolete/ObsoleteHasTableBorderExtensions.cs b/src/Spectre.Console/Extensions/Obsolete/ObsoleteHasTableBorderExtensions.cs deleted file mode 100644 index d2a89df..0000000 --- a/src/Spectre.Console/Extensions/Obsolete/ObsoleteHasTableBorderExtensions.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Spectre.Console -{ - /// - /// Contains extension methods for . - /// - public static class ObsoleteHasTableBorderExtensions - { - /// - /// Sets the border. - /// - /// An object type with a border. - /// The object to set the border for. - /// The border to use. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Border(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static T SetBorder(this T obj, TableBorder border) - where T : class, IHasTableBorder - { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - - obj.Border = border; - return obj; - } - } -} diff --git a/src/Spectre.Console/Extensions/Obsolete/ObsoleteOverflowableExtensions.cs b/src/Spectre.Console/Extensions/Obsolete/ObsoleteOverflowableExtensions.cs deleted file mode 100644 index 929b4b1..0000000 --- a/src/Spectre.Console/Extensions/Obsolete/ObsoleteOverflowableExtensions.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Spectre.Console -{ - /// - /// Contains extension methods for . - /// - public static class ObsoleteOverflowableExtensions - { - /// - /// Sets the overflow strategy. - /// - /// An object implementing . - /// The overflowable object instance. - /// The overflow strategy to use. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Overflow(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static T SetOverflow(this T obj, Overflow overflow) - where T : class, IOverflowable - { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - - obj.Overflow = overflow; - return obj; - } - } -} diff --git a/src/Spectre.Console/Extensions/Obsolete/ObsoletePaddableExtensions.cs b/src/Spectre.Console/Extensions/Obsolete/ObsoletePaddableExtensions.cs deleted file mode 100644 index 117407e..0000000 --- a/src/Spectre.Console/Extensions/Obsolete/ObsoletePaddableExtensions.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Spectre.Console -{ - /// - /// Contains extension methods for . - /// - public static class ObsoletePaddableExtensions - { - /// - /// Sets the left and right padding. - /// - /// An object implementing . - /// The paddable object instance. - /// The left padding to apply. - /// The top padding to apply. - /// The right padding to apply. - /// The bottom padding to apply. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Padding(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static T SetPadding(this T obj, int left, int top, int right, int bottom) - where T : class, IPaddable - { - return SetPadding(obj, new Padding(left, top, right, bottom)); - } - - /// - /// Sets the padding. - /// - /// An object implementing . - /// The paddable object instance. - /// The padding to apply. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Padding(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static T SetPadding(this T obj, Padding padding) - where T : class, IPaddable - { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - - obj.Padding = padding; - return obj; - } - } -} diff --git a/src/Spectre.Console/Extensions/Obsolete/ObsoletePanelExtensions.cs b/src/Spectre.Console/Extensions/Obsolete/ObsoletePanelExtensions.cs deleted file mode 100644 index 0af65b2..0000000 --- a/src/Spectre.Console/Extensions/Obsolete/ObsoletePanelExtensions.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Spectre.Console -{ - /// - /// Contains extension methods for . - /// - public static class ObsoletePanelExtensions - { - /// - /// Sets the panel header. - /// - /// The panel. - /// The header text. - /// The header style. - /// The header alignment. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Header(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Panel SetHeader(this Panel panel, string text, Style? style = null, Justify? alignment = null) - { - if (panel is null) - { - throw new ArgumentNullException(nameof(panel)); - } - - if (text is null) - { - throw new ArgumentNullException(nameof(text)); - } - - alignment ??= panel.Header?.Alignment; - return SetHeader(panel, new PanelHeader(text, alignment)); - } - - /// - /// Sets the panel header. - /// - /// The panel. - /// The header to use. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Header(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Panel SetHeader(this Panel panel, PanelHeader header) - { - if (panel is null) - { - throw new ArgumentNullException(nameof(panel)); - } - - panel.Header = header; - return panel; - } - - /// - /// Sets the panel header style. - /// - /// The panel. - /// The header style. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use markup in header instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Panel HeaderStyle(this Panel panel, Style style) - { - return panel; - } - } -} diff --git a/src/Spectre.Console/Extensions/Obsolete/ObsoleteRuleExtensions.cs b/src/Spectre.Console/Extensions/Obsolete/ObsoleteRuleExtensions.cs deleted file mode 100644 index ede79ae..0000000 --- a/src/Spectre.Console/Extensions/Obsolete/ObsoleteRuleExtensions.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Spectre.Console -{ - /// - /// Contains extension methods for . - /// - public static class ObsoleteRuleExtensions - { - /// - /// Sets the rule title. - /// - /// The rule. - /// The title. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Title(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Rule SetTitle(this Rule rule, string title) - { - if (rule is null) - { - throw new ArgumentNullException(nameof(rule)); - } - - if (title is null) - { - throw new ArgumentNullException(nameof(title)); - } - - rule.Title = title; - return rule; - } - - /// - /// Sets the rule style. - /// - /// The rule. - /// The rule style. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Style(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Rule SetStyle(this Rule rule, Style style) - { - if (rule is null) - { - throw new ArgumentNullException(nameof(rule)); - } - - if (style is null) - { - throw new ArgumentNullException(nameof(style)); - } - - rule.Style = style; - return rule; - } - } -} diff --git a/src/Spectre.Console/Extensions/Obsolete/ObsoleteStringExtensions.cs b/src/Spectre.Console/Extensions/Obsolete/ObsoleteStringExtensions.cs deleted file mode 100644 index 30603d3..0000000 --- a/src/Spectre.Console/Extensions/Obsolete/ObsoleteStringExtensions.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Spectre.Console -{ - /// - /// Contains extension methods for . - /// - public static class ObsoleteStringExtensions - { - /// - /// Escapes text so that it won’t be interpreted as markup. - /// - /// The text to escape. - /// A string that is safe to use in markup. - [Obsolete("Use EscapeMarkup(..) instead.", false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public static string SafeMarkup(this string text) - { - return text.EscapeMarkup(); - } - } -} diff --git a/src/Spectre.Console/Extensions/Obsolete/ObsoleteStyleExtensions.cs b/src/Spectre.Console/Extensions/Obsolete/ObsoleteStyleExtensions.cs deleted file mode 100644 index 2e38440..0000000 --- a/src/Spectre.Console/Extensions/Obsolete/ObsoleteStyleExtensions.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Spectre.Console -{ - /// - /// Contains extension methods for . - /// - public static class ObsoleteStyleExtensions - { - /// - /// Creates a new style from the specified one with - /// the specified foreground color. - /// - /// The style. - /// The foreground color. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Foreground(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Style WithForeground(this Style style, Color color) - { - if (style is null) - { - throw new ArgumentNullException(nameof(style)); - } - - return new Style( - foreground: color, - background: style.Background, - decoration: style.Decoration); - } - - /// - /// Creates a new style from the specified one with - /// the specified background color. - /// - /// The style. - /// The background color. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Background(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Style WithBackground(this Style style, Color color) - { - if (style is null) - { - throw new ArgumentNullException(nameof(style)); - } - - return new Style( - foreground: style.Foreground, - background: color, - decoration: style.Decoration); - } - - /// - /// Creates a new style from the specified one with - /// the specified text decoration. - /// - /// The style. - /// The text decoration. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Decoration(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Style WithDecoration(this Style style, Decoration decoration) - { - if (style is null) - { - throw new ArgumentNullException(nameof(style)); - } - - return new Style( - foreground: style.Foreground, - background: style.Background, - decoration: decoration); - } - - /// - /// Creates a new style from the specified one with - /// the specified link. - /// - /// The style. - /// The link. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Link(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Style WithLink(this Style style, string link) - { - if (style is null) - { - throw new ArgumentNullException(nameof(style)); - } - - return new Style( - foreground: style.Foreground, - background: style.Background, - decoration: style.Decoration, - link: link); - } - } -} diff --git a/src/Spectre.Console/Extensions/Obsolete/ObsoleteTableExtensions.cs b/src/Spectre.Console/Extensions/Obsolete/ObsoleteTableExtensions.cs deleted file mode 100644 index 2005165..0000000 --- a/src/Spectre.Console/Extensions/Obsolete/ObsoleteTableExtensions.cs +++ /dev/null @@ -1,202 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Spectre.Console -{ - /// - /// Contains extension methods for . - /// - public static class ObsoleteTableExtensions - { - /// - /// Sets the table width. - /// - /// The table. - /// The width. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Width(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Table SetWidth(this Table table, int width) - { - if (table is null) - { - throw new ArgumentNullException(nameof(table)); - } - - table.Width = width; - return table; - } - - /// - /// Sets the table heading. - /// - /// The table. - /// The heading. - /// The style. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Heading(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Table SetHeading(this Table table, string text, Style? style = null) - { - if (table is null) - { - throw new ArgumentNullException(nameof(table)); - } - - if (text is null) - { - throw new ArgumentNullException(nameof(text)); - } - - return SetHeading(table, new TableTitle(text, style)); - } - - /// - /// Sets the table heading. - /// - /// The table. - /// The heading. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Heading(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Table SetHeading(this Table table, TableTitle heading) - { - if (table is null) - { - throw new ArgumentNullException(nameof(table)); - } - - table.Title = heading; - return table; - } - - /// - /// Sets the table footnote. - /// - /// The table. - /// The footnote. - /// The style. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Caption(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Table SetFootnote(this Table table, string text, Style? style = null) - { - if (table is null) - { - throw new ArgumentNullException(nameof(table)); - } - - if (text is null) - { - throw new ArgumentNullException(nameof(text)); - } - - return SetFootnote(table, new TableTitle(text, style)); - } - - /// - /// Sets the table footnote. - /// - /// The table. - /// The footnote. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Caption(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Table SetFootnote(this Table table, TableTitle footnote) - { - if (table is null) - { - throw new ArgumentNullException(nameof(table)); - } - - table.Caption = footnote; - return table; - } - - /// - /// Sets the table footnote. - /// - /// The table. - /// The footnote. - /// The style. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Caption(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Table Footnote(this Table table, string text, Style? style = null) - { - if (table is null) - { - throw new ArgumentNullException(nameof(table)); - } - - if (text is null) - { - throw new ArgumentNullException(nameof(text)); - } - - return Footnote(table, new TableTitle(text, style)); - } - - /// - /// Sets the table footnote. - /// - /// The table. - /// The footnote. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Caption(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Table Footnote(this Table table, TableTitle footnote) - { - if (table is null) - { - throw new ArgumentNullException(nameof(table)); - } - - table.Caption = footnote; - return table; - } - - /// - /// Sets the table heading. - /// - /// The table. - /// The heading. - /// The style. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Title(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Table Heading(this Table table, string text, Style? style = null) - { - if (table is null) - { - throw new ArgumentNullException(nameof(table)); - } - - if (text is null) - { - throw new ArgumentNullException(nameof(text)); - } - - return Heading(table, new TableTitle(text, style)); - } - - /// - /// Sets the table heading. - /// - /// The table. - /// The heading. - /// The same instance so that multiple calls can be chained. - [Obsolete("Use Title(..) instead.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Table Heading(this Table table, TableTitle heading) - { - if (table is null) - { - throw new ArgumentNullException(nameof(table)); - } - - table.Title = heading; - return table; - } - } -} diff --git a/src/Spectre.Console/Extensions/RecorderExtensions.cs b/src/Spectre.Console/Extensions/RecorderExtensions.cs index 4b432a5..ca2228a 100644 --- a/src/Spectre.Console/Extensions/RecorderExtensions.cs +++ b/src/Spectre.Console/Extensions/RecorderExtensions.cs @@ -1,5 +1,4 @@ using System; -using Spectre.Console.Internal; namespace Spectre.Console { diff --git a/src/Spectre.Console/Extensions/StringBuilderExtensions.cs b/src/Spectre.Console/Extensions/StringBuilderExtensions.cs index 0a970e0..ff394f6 100644 --- a/src/Spectre.Console/Extensions/StringBuilderExtensions.cs +++ b/src/Spectre.Console/Extensions/StringBuilderExtensions.cs @@ -1,7 +1,7 @@ using System.Globalization; using System.Text; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class StringBuilderExtensions { diff --git a/src/Spectre.Console/Extensions/StringExtensions.cs b/src/Spectre.Console/Extensions/StringExtensions.cs index 7731805..f232dce 100644 --- a/src/Spectre.Console/Extensions/StringExtensions.cs +++ b/src/Spectre.Console/Extensions/StringExtensions.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Extensions/TableExtensions.cs b/src/Spectre.Console/Extensions/TableExtensions.cs index 0ba5216..904c646 100644 --- a/src/Spectre.Console/Extensions/TableExtensions.cs +++ b/src/Spectre.Console/Extensions/TableExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Extensions/TextWriterExtensions.cs b/src/Spectre.Console/Extensions/TextWriterExtensions.cs index 8589a60..9fd4e90 100644 --- a/src/Spectre.Console/Extensions/TextWriterExtensions.cs +++ b/src/Spectre.Console/Extensions/TextWriterExtensions.cs @@ -1,11 +1,9 @@ -using System.Diagnostics.CodeAnalysis; using System.IO; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class TextWriterExtensions { - [SuppressMessage("Design", "CA1031:Do not catch general exception types")] public static bool IsStandardOut(this TextWriter writer) { try diff --git a/src/Spectre.Console/IAnsiConsole.cs b/src/Spectre.Console/IAnsiConsole.cs index 12785a0..e854fa1 100644 --- a/src/Spectre.Console/IAnsiConsole.cs +++ b/src/Spectre.Console/IAnsiConsole.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Text; using Spectre.Console.Rendering; namespace Spectre.Console @@ -10,14 +9,9 @@ namespace Spectre.Console public interface IAnsiConsole { /// - /// Gets the console's capabilities. + /// Gets the console profile. /// - Capabilities Capabilities { get; } - - /// - /// Gets the console output encoding. - /// - Encoding Encoding { get; } + Profile Profile { get; } /// /// Gets the console cursor. @@ -34,16 +28,6 @@ namespace Spectre.Console /// RenderPipeline Pipeline { get; } - /// - /// Gets the buffer width of the console. - /// - int Width { get; } - - /// - /// Gets the buffer height of the console. - /// - int Height { get; } - /// /// Clears the console. /// diff --git a/src/Spectre.Console/ILinkIdentityGenerator.cs b/src/Spectre.Console/ILinkIdentityGenerator.cs deleted file mode 100644 index d52a7f4..0000000 --- a/src/Spectre.Console/ILinkIdentityGenerator.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Spectre.Console -{ - /// - /// Represents a link identity generator. - /// - public interface ILinkIdentityGenerator - { - /// - /// Generates an ID for the given link. - /// - /// The link. - /// The link text. - /// A unique ID for the link. - public int GenerateId(string link, string text); - } -} diff --git a/src/Spectre.Console/IProfileEnricher.cs b/src/Spectre.Console/IProfileEnricher.cs new file mode 100644 index 0000000..2bc52e2 --- /dev/null +++ b/src/Spectre.Console/IProfileEnricher.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; + +namespace Spectre.Console +{ + /// + /// Represents something that can enrich a profile. + /// + public interface IProfileEnricher + { + /// + /// Gets whether or not this enricher is enabled. + /// + /// The environment variables. + /// Whether or not this enricher is enabled. + bool Enabled(IDictionary environmentVariables); + + /// + /// Enriches the profile. + /// + /// The profile to enrich. + void Enrich(Profile profile); + } +} diff --git a/src/Spectre.Console/Internal/Aligner.cs b/src/Spectre.Console/Internal/Aligner.cs index bda90d6..34df9c9 100644 --- a/src/Spectre.Console/Internal/Aligner.cs +++ b/src/Spectre.Console/Internal/Aligner.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using Spectre.Console.Rendering; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class Aligner { diff --git a/src/Spectre.Console/Internal/Backends/Ansi/AnsiBackend.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiBackend.cs deleted file mode 100644 index e4c895a..0000000 --- a/src/Spectre.Console/Internal/Backends/Ansi/AnsiBackend.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using Spectre.Console.Rendering; - -namespace Spectre.Console.Internal -{ - internal sealed class AnsiBackend : IAnsiConsole - { - private readonly TextWriter _out; - private readonly AnsiBuilder _ansiBuilder; - private readonly AnsiCursor _cursor; - private readonly ConsoleInput _input; - private readonly object _lock; - - public Capabilities Capabilities { get; } - public Encoding Encoding { get; } - public RenderPipeline Pipeline { get; } - public IAnsiConsoleCursor Cursor => _cursor; - public IAnsiConsoleInput Input => _input; - - public int Width - { - get - { - if (_out.IsStandardOut()) - { - return ConsoleHelper.GetSafeWidth(Constants.DefaultTerminalWidth); - } - - return Constants.DefaultTerminalWidth; - } - } - - public int Height - { - get - { - if (_out.IsStandardOut()) - { - return ConsoleHelper.GetSafeHeight(Constants.DefaultTerminalHeight); - } - - return Constants.DefaultTerminalHeight; - } - } - - public AnsiBackend(TextWriter @out, Capabilities capabilities, ILinkIdentityGenerator? linkHasher) - { - _out = @out ?? throw new ArgumentNullException(nameof(@out)); - - Capabilities = capabilities ?? throw new ArgumentNullException(nameof(capabilities)); - Encoding = _out.IsStandardOut() ? System.Console.OutputEncoding : Encoding.UTF8; - Pipeline = new RenderPipeline(); - - _ansiBuilder = new AnsiBuilder(Capabilities, linkHasher); - _cursor = new AnsiCursor(this); - _input = new ConsoleInput(); - _lock = new object(); - } - - public void Clear(bool home) - { - lock (_lock) - { - Write(new[] { Segment.Control("\u001b[2J") }); - - if (home) - { - Cursor.SetPosition(0, 0); - } - } - } - - public void Write(IEnumerable segments) - { - lock (_lock) - { - var builder = new StringBuilder(); - foreach (var segment in segments) - { - if (segment.IsControlCode) - { - builder.Append(segment.Text); - continue; - } - - var parts = segment.Text.NormalizeNewLines().Split(new[] { '\n' }); - foreach (var (_, _, last, part) in parts.Enumerate()) - { - if (!string.IsNullOrEmpty(part)) - { - builder.Append(_ansiBuilder.GetAnsi(part, segment.Style)); - } - - if (!last) - { - builder.Append(Environment.NewLine); - } - } - } - - if (builder.Length > 0) - { - _out.Write(builder.ToString()); - _out.Flush(); - } - } - } - } -} \ No newline at end of file diff --git a/src/Spectre.Console/Internal/Ansi/AnsiBuilder.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiBuilder.cs similarity index 75% rename from src/Spectre.Console/Internal/Ansi/AnsiBuilder.cs rename to src/Spectre.Console/Internal/Backends/Ansi/AnsiBuilder.cs index 5ee6de8..85c9ae8 100644 --- a/src/Spectre.Console/Internal/Ansi/AnsiBuilder.cs +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiBuilder.cs @@ -1,17 +1,17 @@ using System; using System.Linq; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal sealed class AnsiBuilder { - private readonly Capabilities _capabilities; - private readonly ILinkIdentityGenerator _linkHasher; + private readonly Profile _profile; + private readonly AnsiLinkHasher _linkHasher; - public AnsiBuilder(Capabilities capabilities, ILinkIdentityGenerator? linkHasher) + public AnsiBuilder(Profile profile) { - _capabilities = capabilities ?? throw new ArgumentNullException(nameof(capabilities)); - _linkHasher = linkHasher ?? new LinkIdentityGenerator(); + _profile = profile ?? throw new ArgumentNullException(nameof(profile)); + _linkHasher = new AnsiLinkHasher(); } public string GetAnsi(string text, Style style) @@ -28,7 +28,7 @@ namespace Spectre.Console.Internal { codes = codes.Concat( AnsiColorBuilder.GetAnsiCodes( - _capabilities.ColorSystem, + _profile.ColorSystem, style.Foreground, true)); } @@ -38,7 +38,7 @@ namespace Spectre.Console.Internal { codes = codes.Concat( AnsiColorBuilder.GetAnsiCodes( - _capabilities.ColorSystem, + _profile.ColorSystem, style.Background, false)); } @@ -54,7 +54,7 @@ namespace Spectre.Console.Internal ? $"\u001b[{ansiCodes}m{text}\u001b[0m" : text; - if (style.Link != null && !_capabilities.LegacyConsole) + if (style.Link != null && !_profile.Capabilities.Legacy) { var link = style.Link; diff --git a/src/Spectre.Console/Internal/Ansi/AnsiColorBuilder.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiColorBuilder.cs similarity index 98% rename from src/Spectre.Console/Internal/Ansi/AnsiColorBuilder.cs rename to src/Spectre.Console/Internal/Backends/Ansi/AnsiColorBuilder.cs index 86b3f13..7cb99b3 100644 --- a/src/Spectre.Console/Internal/Ansi/AnsiColorBuilder.cs +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiColorBuilder.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class AnsiColorBuilder { diff --git a/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleBackend.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleBackend.cs new file mode 100644 index 0000000..5821f6f --- /dev/null +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleBackend.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Spectre.Console.Rendering; + +namespace Spectre.Console +{ + internal sealed class AnsiConsoleBackend : IAnsiConsoleBackend + { + private readonly AnsiBuilder _builder; + private readonly Profile _profile; + + public IAnsiConsoleCursor Cursor { get; } + + public AnsiConsoleBackend(Profile profile) + { + _profile = profile ?? throw new ArgumentNullException(nameof(profile)); + _builder = new AnsiBuilder(profile); + + Cursor = new AnsiConsoleCursor(this); + } + + public void Clear(bool home) + { + Render(new[] { Segment.Control("\u001b[2J") }); + + if (home) + { + Cursor.SetPosition(0, 0); + } + } + + public void Render(IEnumerable segments) + { + var builder = new StringBuilder(); + foreach (var segment in segments) + { + if (segment.IsControlCode) + { + builder.Append(segment.Text); + continue; + } + + var parts = segment.Text.NormalizeNewLines().Split(new[] { '\n' }); + foreach (var (_, _, last, part) in parts.Enumerate()) + { + if (!string.IsNullOrEmpty(part)) + { + builder.Append(_builder.GetAnsi(part, segment.Style)); + } + + if (!last) + { + builder.Append(Environment.NewLine); + } + } + } + + if (builder.Length > 0) + { + _profile.Out.Write(builder.ToString()); + _profile.Out.Flush(); + } + } + } +} diff --git a/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleCursor.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleCursor.cs new file mode 100644 index 0000000..cd33af9 --- /dev/null +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleCursor.cs @@ -0,0 +1,56 @@ +using System; +using Spectre.Console.Rendering; + +namespace Spectre.Console +{ + internal sealed class AnsiConsoleCursor : IAnsiConsoleCursor + { + private readonly AnsiConsoleBackend _backend; + + public AnsiConsoleCursor(AnsiConsoleBackend backend) + { + _backend = backend ?? throw new ArgumentNullException(nameof(backend)); + } + + public void Show(bool show) + { + if (show) + { + _backend.Render(new[] { Segment.Control("\u001b[?25h") }); + } + else + { + _backend.Render(new[] { Segment.Control("\u001b[?25l") }); + } + } + + public void Move(CursorDirection direction, int steps) + { + if (steps == 0) + { + return; + } + + switch (direction) + { + case CursorDirection.Up: + _backend.Render(new[] { Segment.Control($"\u001b[{steps}A") }); + break; + case CursorDirection.Down: + _backend.Render(new[] { Segment.Control($"\u001b[{steps}B") }); + break; + case CursorDirection.Right: + _backend.Render(new[] { Segment.Control($"\u001b[{steps}C") }); + break; + case CursorDirection.Left: + _backend.Render(new[] { Segment.Control($"\u001b[{steps}D") }); + break; + } + } + + public void SetPosition(int column, int line) + { + _backend.Render(new[] { Segment.Control($"\u001b[{line};{column}H") }); + } + } +} diff --git a/src/Spectre.Console/Internal/Backends/Ansi/AnsiCursor.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiCursor.cs deleted file mode 100644 index 28b00d5..0000000 --- a/src/Spectre.Console/Internal/Backends/Ansi/AnsiCursor.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using Spectre.Console.Rendering; - -namespace Spectre.Console.Internal -{ - internal sealed class AnsiCursor : IAnsiConsoleCursor - { - private readonly AnsiBackend _renderer; - - public AnsiCursor(AnsiBackend renderer) - { - _renderer = renderer ?? throw new ArgumentNullException(nameof(renderer)); - } - - public void Show(bool show) - { - if (show) - { - _renderer.Write(Segment.Control("\u001b[?25h")); - } - else - { - _renderer.Write(Segment.Control("\u001b[?25l")); - } - } - - public void Move(CursorDirection direction, int steps) - { - if (steps == 0) - { - return; - } - - switch (direction) - { - case CursorDirection.Up: - _renderer.Write(Segment.Control($"\u001b[{steps}A")); - break; - case CursorDirection.Down: - _renderer.Write(Segment.Control($"\u001b[{steps}B")); - break; - case CursorDirection.Right: - _renderer.Write(Segment.Control($"\u001b[{steps}C")); - break; - case CursorDirection.Left: - _renderer.Write(Segment.Control($"\u001b[{steps}D")); - break; - } - } - - public void SetPosition(int column, int line) - { - _renderer.Write(Segment.Control($"\u001b[{line};{column}H")); - } - } -} \ No newline at end of file diff --git a/src/Spectre.Console/Internal/Ansi/AnsiDecorationBuilder.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiDecorationBuilder.cs similarity index 97% rename from src/Spectre.Console/Internal/Ansi/AnsiDecorationBuilder.cs rename to src/Spectre.Console/Internal/Backends/Ansi/AnsiDecorationBuilder.cs index 65732fa..8be46c2 100644 --- a/src/Spectre.Console/Internal/Ansi/AnsiDecorationBuilder.cs +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiDecorationBuilder.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class AnsiDecorationBuilder { diff --git a/src/Spectre.Console/Internal/Ansi/AnsiDetector.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiDetector.cs similarity index 92% rename from src/Spectre.Console/Internal/Ansi/AnsiDetector.cs rename to src/Spectre.Console/Internal/Backends/Ansi/AnsiDetector.cs index 552169c..0b38158 100644 --- a/src/Spectre.Console/Internal/Ansi/AnsiDetector.cs +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiDetector.cs @@ -9,7 +9,7 @@ using System.Text.RegularExpressions; // https://github.com/keqingrong/supports-ansi/blob/master/index.js ///////////////////////////////////////////////////////////////////////////////////////////////////// -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class AnsiDetector { @@ -34,12 +34,6 @@ namespace Spectre.Console.Internal public static (bool SupportsAnsi, bool LegacyConsole) Detect(bool upgrade) { - // Github action doesn't setup a correct PTY but supports ANSI. - if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("GITHUB_ACTION"))) - { - return (true, false); - } - // Running on Windows? if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { @@ -72,7 +66,6 @@ namespace Spectre.Console.Internal return (false, true); } - [SuppressMessage("Design", "CA1060:Move pinvokes to native methods class")] internal static class Windows { [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore")] @@ -96,7 +89,6 @@ namespace Spectre.Console.Internal [DllImport("kernel32.dll")] public static extern uint GetLastError(); - [SuppressMessage("Design", "CA1031:Do not catch general exception types")] public static bool SupportsAnsi(bool upgrade, out bool isLegacy) { isLegacy = false; diff --git a/src/Spectre.Console/Internal/LinkIdentityGenerator.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiLinkHasher.cs similarity index 85% rename from src/Spectre.Console/Internal/LinkIdentityGenerator.cs rename to src/Spectre.Console/Internal/Backends/Ansi/AnsiLinkHasher.cs index e5d527b..d964091 100644 --- a/src/Spectre.Console/Internal/LinkIdentityGenerator.cs +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiLinkHasher.cs @@ -1,13 +1,13 @@ using System; using System.Runtime.CompilerServices; -namespace Spectre.Console.Internal +namespace Spectre.Console { - internal sealed class LinkIdentityGenerator : ILinkIdentityGenerator + internal sealed class AnsiLinkHasher { private readonly Random _random; - public LinkIdentityGenerator() + public AnsiLinkHasher() { _random = new Random(DateTime.Now.Millisecond); } diff --git a/src/Spectre.Console/Internal/Backends/AnsiConsoleFacade.cs b/src/Spectre.Console/Internal/Backends/AnsiConsoleFacade.cs new file mode 100644 index 0000000..d01e5ae --- /dev/null +++ b/src/Spectre.Console/Internal/Backends/AnsiConsoleFacade.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using Spectre.Console.Rendering; + +namespace Spectre.Console +{ + internal sealed class AnsiConsoleFacade : IAnsiConsole + { + private readonly object _renderLock; + private readonly AnsiConsoleBackend _ansiBackend; + private readonly LegacyConsoleBackend _legacyBackend; + + public Profile Profile { get; } + public IAnsiConsoleCursor Cursor => GetBackend().Cursor; + public IAnsiConsoleInput Input { get; } + public RenderPipeline Pipeline { get; } + + public AnsiConsoleFacade(Profile profile) + { + _renderLock = new object(); + _ansiBackend = new AnsiConsoleBackend(profile); + _legacyBackend = new LegacyConsoleBackend(profile); + + Profile = profile ?? throw new ArgumentNullException(nameof(profile)); + Input = new DefaultInput(Profile); + Pipeline = new RenderPipeline(); + } + + public void Clear(bool home) + { + lock (_renderLock) + { + GetBackend().Clear(home); + } + } + + public void Write(IEnumerable segments) + { + lock (_renderLock) + { + GetBackend().Render(segments); + } + } + + private IAnsiConsoleBackend GetBackend() + { + if (Profile.Capabilities.Ansi) + { + return _ansiBackend; + } + + return _legacyBackend; + } + } +} diff --git a/src/Spectre.Console/Internal/Backends/BackendBuilder.cs b/src/Spectre.Console/Internal/Backends/BackendBuilder.cs deleted file mode 100644 index a2f51e2..0000000 --- a/src/Spectre.Console/Internal/Backends/BackendBuilder.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace Spectre.Console.Internal -{ - internal static class BackendBuilder - { - public static IAnsiConsole Build(AnsiConsoleSettings settings) - { - if (settings is null) - { - throw new ArgumentNullException(nameof(settings)); - } - - var buffer = settings.Out ?? System.Console.Out; - - var supportsAnsi = settings.Ansi == AnsiSupport.Yes; - var legacyConsole = false; - - if (settings.Ansi == AnsiSupport.Detect) - { - (supportsAnsi, legacyConsole) = AnsiDetector.Detect(true); - - // Check whether or not this is a legacy console from the existing instance (if any). - // We need to do this because once we upgrade the console to support ENABLE_VIRTUAL_TERMINAL_PROCESSING - // on Windows, there is no way of detecting whether or not we're running on a legacy console or not. - if (AnsiConsole.Created && !legacyConsole && buffer.IsStandardOut() && AnsiConsole.Capabilities.LegacyConsole) - { - legacyConsole = AnsiConsole.Capabilities.LegacyConsole; - } - } - else - { - if (buffer.IsStandardOut()) - { - // Are we running on Windows? - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Not the first console we're creating? - if (AnsiConsole.Created) - { - legacyConsole = AnsiConsole.Capabilities.LegacyConsole; - } - else - { - // Try detecting whether or not this - (_, legacyConsole) = AnsiDetector.Detect(false); - } - } - } - } - - var supportsInteraction = settings.Interactive == InteractionSupport.Yes; - if (settings.Interactive == InteractionSupport.Detect) - { - supportsInteraction = InteractivityDetector.IsInteractive(); - } - - var colorSystem = settings.ColorSystem == ColorSystemSupport.Detect - ? ColorSystemDetector.Detect(supportsAnsi) - : (ColorSystem)settings.ColorSystem; - - // Get the capabilities - var capabilities = new Capabilities(supportsAnsi, colorSystem, legacyConsole, supportsInteraction); - - // Create the renderer - if (supportsAnsi) - { - return new AnsiBackend(buffer, capabilities, settings.LinkIdentityGenerator); - } - else - { - return new FallbackBackend(buffer, capabilities); - } - } - } -} diff --git a/src/Spectre.Console/Internal/Backends/Fallback/FallbackBackend.cs b/src/Spectre.Console/Internal/Backends/Fallback/FallbackBackend.cs deleted file mode 100644 index c6a9145..0000000 --- a/src/Spectre.Console/Internal/Backends/Fallback/FallbackBackend.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using Spectre.Console.Rendering; - -namespace Spectre.Console.Internal -{ - internal sealed class FallbackBackend : IAnsiConsole - { - private readonly ColorSystem _system; - private readonly FallbackCursor _cursor; - private readonly ConsoleInput _input; - private Style? _lastStyle; - - public Capabilities Capabilities { get; } - public Encoding Encoding { get; } - public RenderPipeline Pipeline { get; } - public IAnsiConsoleCursor Cursor => _cursor; - public IAnsiConsoleInput Input => _input; - - public int Width - { - get { return ConsoleHelper.GetSafeWidth(Constants.DefaultTerminalWidth); } - } - - public int Height - { - get { return ConsoleHelper.GetSafeHeight(Constants.DefaultTerminalHeight); } - } - - public FallbackBackend(TextWriter @out, Capabilities capabilities) - { - if (capabilities == null) - { - throw new ArgumentNullException(nameof(capabilities)); - } - - _system = capabilities.ColorSystem; - _cursor = new FallbackCursor(); - _input = new ConsoleInput(); - - if (@out != System.Console.Out) - { - System.Console.SetOut(@out ?? throw new ArgumentNullException(nameof(@out))); - } - - Capabilities = capabilities; - Encoding = System.Console.OutputEncoding; - Pipeline = new RenderPipeline(); - } - - public void Clear(bool home) - { - var (x, y) = (System.Console.CursorLeft, System.Console.CursorTop); - - System.Console.Clear(); - - if (!home) - { - // Set the cursor position - System.Console.SetCursorPosition(x, y); - } - } - - public void Write(IEnumerable segments) - { - foreach (var segment in segments) - { - if (segment.IsControlCode) - { - continue; - } - - if (_lastStyle?.Equals(segment.Style) != true) - { - SetStyle(segment.Style); - } - - System.Console.Write(segment.Text.NormalizeNewLines(native: true)); - } - } - - private void SetStyle(Style style) - { - _lastStyle = style; - - System.Console.ResetColor(); - - var background = Color.ToConsoleColor(style.Background); - if (_system != ColorSystem.NoColors && (int)background != -1) - { - System.Console.BackgroundColor = background; - } - - var foreground = Color.ToConsoleColor(style.Foreground); - if (_system != ColorSystem.NoColors && (int)foreground != -1) - { - System.Console.ForegroundColor = foreground; - } - } - } -} diff --git a/src/Spectre.Console/Internal/Backends/IAnsiConsoleBackend.cs b/src/Spectre.Console/Internal/Backends/IAnsiConsoleBackend.cs new file mode 100644 index 0000000..2ec0c9b --- /dev/null +++ b/src/Spectre.Console/Internal/Backends/IAnsiConsoleBackend.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using Spectre.Console.Rendering; + +namespace Spectre.Console +{ + /// + /// Represents a console backend. + /// + internal interface IAnsiConsoleBackend + { + /// + /// Gets the console cursor for the backend. + /// + IAnsiConsoleCursor Cursor { get; } + + /// + /// Clears the console. + /// + /// If the cursor should be moved to the home position. + void Clear(bool home); + + /// + /// Renders segments to the console. + /// + /// The segments to render. + void Render(IEnumerable segments); + } +} diff --git a/src/Spectre.Console/Internal/InteractivityDetector.cs b/src/Spectre.Console/Internal/Backends/InteractivityDetector.cs similarity index 98% rename from src/Spectre.Console/Internal/InteractivityDetector.cs rename to src/Spectre.Console/Internal/Backends/InteractivityDetector.cs index c91f296..bd9e7bc 100644 --- a/src/Spectre.Console/Internal/InteractivityDetector.cs +++ b/src/Spectre.Console/Internal/Backends/InteractivityDetector.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class InteractivityDetector { diff --git a/src/Spectre.Console/Internal/Backends/Legacy/LegacyConsoleBackend.cs b/src/Spectre.Console/Internal/Backends/Legacy/LegacyConsoleBackend.cs new file mode 100644 index 0000000..913bb59 --- /dev/null +++ b/src/Spectre.Console/Internal/Backends/Legacy/LegacyConsoleBackend.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using Spectre.Console.Rendering; + +namespace Spectre.Console +{ + internal sealed class LegacyConsoleBackend : IAnsiConsoleBackend + { + private readonly Profile _profile; + private Style _lastStyle; + + public IAnsiConsoleCursor Cursor { get; } + + public LegacyConsoleBackend(Profile profile) + { + _profile = profile ?? throw new System.ArgumentNullException(nameof(profile)); + _lastStyle = Style.Plain; + + Cursor = new LegacyConsoleCursor(); + } + + public void Clear(bool home) + { + var (x, y) = (System.Console.CursorLeft, System.Console.CursorTop); + + System.Console.Clear(); + + if (!home) + { + // Set the cursor position + System.Console.SetCursorPosition(x, y); + } + } + + public void Render(IEnumerable segments) + { + foreach (var segment in segments) + { + if (segment.IsControlCode) + { + continue; + } + + if (_lastStyle?.Equals(segment.Style) != true) + { + SetStyle(segment.Style); + } + + _profile.Out.Write(segment.Text.NormalizeNewLines(native: true)); + } + } + + private void SetStyle(Style style) + { + _lastStyle = style; + + System.Console.ResetColor(); + + var background = Color.ToConsoleColor(style.Background); + if (_profile.ColorSystem != ColorSystem.NoColors && (int)background != -1) + { + System.Console.BackgroundColor = background; + } + + var foreground = Color.ToConsoleColor(style.Foreground); + if (_profile.ColorSystem != ColorSystem.NoColors && (int)foreground != -1) + { + System.Console.ForegroundColor = foreground; + } + } + } +} diff --git a/src/Spectre.Console/Internal/Backends/Fallback/FallbackCursor.cs b/src/Spectre.Console/Internal/Backends/Legacy/LegacyConsoleCursor.cs similarity index 91% rename from src/Spectre.Console/Internal/Backends/Fallback/FallbackCursor.cs rename to src/Spectre.Console/Internal/Backends/Legacy/LegacyConsoleCursor.cs index 475aa87..74bdda9 100644 --- a/src/Spectre.Console/Internal/Backends/Fallback/FallbackCursor.cs +++ b/src/Spectre.Console/Internal/Backends/Legacy/LegacyConsoleCursor.cs @@ -1,6 +1,6 @@ -namespace Spectre.Console.Internal +namespace Spectre.Console { - internal sealed class FallbackCursor : IAnsiConsoleCursor + internal sealed class LegacyConsoleCursor : IAnsiConsoleCursor { public void Show(bool show) { diff --git a/src/Spectre.Console/Internal/Text/Cell.cs b/src/Spectre.Console/Internal/Cell.cs similarity index 97% rename from src/Spectre.Console/Internal/Text/Cell.cs rename to src/Spectre.Console/Internal/Cell.cs index e4f724a..1a8a0ce 100644 --- a/src/Spectre.Console/Internal/Text/Cell.cs +++ b/src/Spectre.Console/Internal/Cell.cs @@ -2,7 +2,7 @@ using System.Linq; using Spectre.Console.Rendering; using Wcwidth; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class Cell { diff --git a/src/Spectre.Console/Internal/Collections/ListWithCallback.cs b/src/Spectre.Console/Internal/Collections/ListWithCallback.cs index 32e58b7..ec7af3b 100644 --- a/src/Spectre.Console/Internal/Collections/ListWithCallback.cs +++ b/src/Spectre.Console/Internal/Collections/ListWithCallback.cs @@ -2,7 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal sealed class ListWithCallback : IList, IReadOnlyList { diff --git a/src/Spectre.Console/Internal/Colors/ColorPalette.Generated.cs b/src/Spectre.Console/Internal/Colors/ColorPalette.Generated.cs index 169bc47..f985769 100644 --- a/src/Spectre.Console/Internal/Colors/ColorPalette.Generated.cs +++ b/src/Spectre.Console/Internal/Colors/ColorPalette.Generated.cs @@ -10,7 +10,7 @@ using System.Collections.Generic; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static partial class ColorPalette { diff --git a/src/Spectre.Console/Internal/Colors/ColorPalette.cs b/src/Spectre.Console/Internal/Colors/ColorPalette.cs index b115df0..8d7f317 100644 --- a/src/Spectre.Console/Internal/Colors/ColorPalette.cs +++ b/src/Spectre.Console/Internal/Colors/ColorPalette.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static partial class ColorPalette { diff --git a/src/Spectre.Console/Internal/Colors/ColorSystemDetector.cs b/src/Spectre.Console/Internal/Colors/ColorSystemDetector.cs index 6f6626f..a7ecc3a 100644 --- a/src/Spectre.Console/Internal/Colors/ColorSystemDetector.cs +++ b/src/Spectre.Console/Internal/Colors/ColorSystemDetector.cs @@ -2,7 +2,7 @@ using System; using System.Runtime.InteropServices; using System.Text.RegularExpressions; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class ColorSystemDetector { diff --git a/src/Spectre.Console/Internal/Colors/ColorTable.Generated.cs b/src/Spectre.Console/Internal/Colors/ColorTable.Generated.cs index d76f334..0c84523 100644 --- a/src/Spectre.Console/Internal/Colors/ColorTable.Generated.cs +++ b/src/Spectre.Console/Internal/Colors/ColorTable.Generated.cs @@ -11,7 +11,7 @@ using System; using System.Collections.Generic; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static partial class ColorTable { diff --git a/src/Spectre.Console/Internal/Colors/ColorTable.cs b/src/Spectre.Console/Internal/Colors/ColorTable.cs index 0e12185..e1012dd 100644 --- a/src/Spectre.Console/Internal/Colors/ColorTable.cs +++ b/src/Spectre.Console/Internal/Colors/ColorTable.cs @@ -1,15 +1,13 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static partial class ColorTable { private static readonly Dictionary _nameLookup; private static readonly Dictionary _numberLookup; - [SuppressMessage("Performance", "CA1810:Initialize reference type static fields inline")] static ColorTable() { _numberLookup = GenerateTable(); diff --git a/src/Spectre.Console/Internal/ConsoleHelper.cs b/src/Spectre.Console/Internal/ConsoleHelper.cs index 8ee8057..5775e0f 100644 --- a/src/Spectre.Console/Internal/ConsoleHelper.cs +++ b/src/Spectre.Console/Internal/ConsoleHelper.cs @@ -1,6 +1,6 @@ using System.IO; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class ConsoleHelper { diff --git a/src/Spectre.Console/Internal/ConsoleInput.cs b/src/Spectre.Console/Internal/ConsoleInput.cs deleted file mode 100644 index 19f4313..0000000 --- a/src/Spectre.Console/Internal/ConsoleInput.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; - -namespace Spectre.Console.Internal -{ - internal sealed class ConsoleInput : IAnsiConsoleInput - { - public ConsoleKeyInfo ReadKey(bool intercept) - { - if (!Environment.UserInteractive) - { - throw new InvalidOperationException("Failed to read input in non-interactive mode."); - } - - return System.Console.ReadKey(intercept); - } - } -} diff --git a/src/Spectre.Console/Internal/Constants.cs b/src/Spectre.Console/Internal/Constants.cs index c7e40f6..b88b474 100644 --- a/src/Spectre.Console/Internal/Constants.cs +++ b/src/Spectre.Console/Internal/Constants.cs @@ -1,4 +1,4 @@ -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class Constants { diff --git a/src/Spectre.Console/Internal/DecorationTable.cs b/src/Spectre.Console/Internal/DecorationTable.cs index 2f2ac32..e65a776 100644 --- a/src/Spectre.Console/Internal/DecorationTable.cs +++ b/src/Spectre.Console/Internal/DecorationTable.cs @@ -1,16 +1,14 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class DecorationTable { private static readonly Dictionary _lookup; private static readonly Dictionary _reverseLookup; - [SuppressMessage("Performance", "CA1810:Initialize reference type static fields inline")] static DecorationTable() { _lookup = new Dictionary(StringComparer.OrdinalIgnoreCase) diff --git a/src/Spectre.Console/Internal/DefaultInput.cs b/src/Spectre.Console/Internal/DefaultInput.cs new file mode 100644 index 0000000..844db0f --- /dev/null +++ b/src/Spectre.Console/Internal/DefaultInput.cs @@ -0,0 +1,29 @@ +using System; + +namespace Spectre.Console +{ + internal sealed class DefaultInput : IAnsiConsoleInput + { + private readonly Profile _profile; + + public DefaultInput(Profile profile) + { + _profile = profile ?? throw new ArgumentNullException(nameof(profile)); + } + + public ConsoleKeyInfo ReadKey(bool intercept) + { + if (_profile.Capabilities.Tty) + { + throw new InvalidOperationException("Cannot read input from a TTY console."); + } + + if (!_profile.Capabilities.Interactive) + { + throw new InvalidOperationException("Failed to read input in non-interactive mode."); + } + + return System.Console.ReadKey(intercept); + } + } +} diff --git a/src/Spectre.Console/Internal/FileSize.cs b/src/Spectre.Console/Internal/FileSize.cs index 9bebaf7..569979d 100644 --- a/src/Spectre.Console/Internal/FileSize.cs +++ b/src/Spectre.Console/Internal/FileSize.cs @@ -1,7 +1,7 @@ using System; using System.Globalization; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal struct FileSize { @@ -31,7 +31,7 @@ namespace Spectre.Console.Internal var bytes = Bytes / @base; - return Unit == FileSizeUnit.Bytes + return Unit == FileSizeUnit.Byte ? ((int)bytes).ToString(culture ?? CultureInfo.InvariantCulture) : bytes.ToString("F1", culture ?? CultureInfo.InvariantCulture); } @@ -78,7 +78,7 @@ namespace Spectre.Console.Internal } } - return FileSizeUnit.Bytes; + return FileSizeUnit.Byte; } private static double GetBase(FileSizeUnit unit) diff --git a/src/Spectre.Console/Internal/FileSizeUnit.cs b/src/Spectre.Console/Internal/FileSizeUnit.cs index 17f522f..6835734 100644 --- a/src/Spectre.Console/Internal/FileSizeUnit.cs +++ b/src/Spectre.Console/Internal/FileSizeUnit.cs @@ -1,10 +1,8 @@ -using System; - -namespace Spectre.Console.Internal +namespace Spectre.Console { internal enum FileSizeUnit { - Bytes = 0, + Byte = 0, KiloByte = 1, MegaByte = 2, GigaByte = 3, diff --git a/src/Spectre.Console/Internal/Ratio.cs b/src/Spectre.Console/Internal/Ratio.cs index 950a9ca..d8fb1ca 100644 --- a/src/Spectre.Console/Internal/Ratio.cs +++ b/src/Spectre.Console/Internal/Ratio.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class Ratio { diff --git a/src/Spectre.Console/Internal/ResourceReader.cs b/src/Spectre.Console/Internal/ResourceReader.cs index e41efbe..01db19b 100644 --- a/src/Spectre.Console/Internal/ResourceReader.cs +++ b/src/Spectre.Console/Internal/ResourceReader.cs @@ -1,7 +1,7 @@ using System; using System.IO; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class ResourceReader { diff --git a/src/Spectre.Console/Internal/HtmlEncoder.cs b/src/Spectre.Console/Internal/Text/Encoding/HtmlEncoder.cs similarity index 98% rename from src/Spectre.Console/Internal/HtmlEncoder.cs rename to src/Spectre.Console/Internal/Text/Encoding/HtmlEncoder.cs index 26b7668..48e5046 100644 --- a/src/Spectre.Console/Internal/HtmlEncoder.cs +++ b/src/Spectre.Console/Internal/Text/Encoding/HtmlEncoder.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Text; using Spectre.Console.Rendering; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal sealed class HtmlEncoder : IAnsiConsoleEncoder { diff --git a/src/Spectre.Console/Internal/TextEncoder.cs b/src/Spectre.Console/Internal/Text/Encoding/TextEncoder.cs similarity index 94% rename from src/Spectre.Console/Internal/TextEncoder.cs rename to src/Spectre.Console/Internal/Text/Encoding/TextEncoder.cs index 7261c90..ce641d2 100644 --- a/src/Spectre.Console/Internal/TextEncoder.cs +++ b/src/Spectre.Console/Internal/Text/Encoding/TextEncoder.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; using Spectre.Console.Rendering; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal sealed class TextEncoder : IAnsiConsoleEncoder { diff --git a/src/Spectre.Console/Internal/Text/Markup/MarkupParser.cs b/src/Spectre.Console/Internal/Text/Markup/MarkupParser.cs index 2eb4b93..e0b809d 100644 --- a/src/Spectre.Console/Internal/Text/Markup/MarkupParser.cs +++ b/src/Spectre.Console/Internal/Text/Markup/MarkupParser.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class MarkupParser { diff --git a/src/Spectre.Console/Internal/Text/Markup/MarkupToken.cs b/src/Spectre.Console/Internal/Text/Markup/MarkupToken.cs index 181289f..1caa1bf 100644 --- a/src/Spectre.Console/Internal/Text/Markup/MarkupToken.cs +++ b/src/Spectre.Console/Internal/Text/Markup/MarkupToken.cs @@ -1,6 +1,6 @@ using System; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal sealed class MarkupToken { diff --git a/src/Spectre.Console/Internal/Text/Markup/MarkupTokenKind.cs b/src/Spectre.Console/Internal/Text/Markup/MarkupTokenKind.cs index 8bb044c..740eda6 100644 --- a/src/Spectre.Console/Internal/Text/Markup/MarkupTokenKind.cs +++ b/src/Spectre.Console/Internal/Text/Markup/MarkupTokenKind.cs @@ -1,4 +1,4 @@ -namespace Spectre.Console.Internal +namespace Spectre.Console { internal enum MarkupTokenKind { diff --git a/src/Spectre.Console/Internal/Text/Markup/MarkupTokenizer.cs b/src/Spectre.Console/Internal/Text/Markup/MarkupTokenizer.cs index 228ce85..a168019 100644 --- a/src/Spectre.Console/Internal/Text/Markup/MarkupTokenizer.cs +++ b/src/Spectre.Console/Internal/Text/Markup/MarkupTokenizer.cs @@ -1,7 +1,7 @@ using System; using System.Text; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal sealed class MarkupTokenizer : IDisposable { diff --git a/src/Spectre.Console/Internal/Text/StringBuffer.cs b/src/Spectre.Console/Internal/Text/StringBuffer.cs index bba60c7..6d41063 100644 --- a/src/Spectre.Console/Internal/Text/StringBuffer.cs +++ b/src/Spectre.Console/Internal/Text/StringBuffer.cs @@ -1,12 +1,10 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.IO; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal sealed class StringBuffer : IDisposable { - [SuppressMessage("Usage", "CA2213:Disposable fields should be disposed", Justification = "False positive")] private readonly StringReader _reader; private readonly int _length; diff --git a/src/Spectre.Console/Internal/TypeConverterHelper.cs b/src/Spectre.Console/Internal/TypeConverterHelper.cs index 07d847e..5d5bd57 100644 --- a/src/Spectre.Console/Internal/TypeConverterHelper.cs +++ b/src/Spectre.Console/Internal/TypeConverterHelper.cs @@ -3,7 +3,7 @@ using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Reflection; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class TypeConverterHelper { @@ -12,7 +12,6 @@ namespace Spectre.Console.Internal return GetTypeConverter().ConvertToInvariantString(input); } - [SuppressMessage("Design", "CA1031:Do not catch general exception types")] public static bool TryConvertFromString(string input, [MaybeNull] out T result) { try diff --git a/src/Spectre.Console/Profile.cs b/src/Spectre.Console/Profile.cs new file mode 100644 index 0000000..e2b550e --- /dev/null +++ b/src/Spectre.Console/Profile.cs @@ -0,0 +1,194 @@ +using System; +using System.IO; +using System.Text; + +namespace Spectre.Console +{ + /// + /// Represents a console profile. + /// + public sealed class Profile + { + private string _name; + private TextWriter _out; + private Encoding _encoding; + private Capabilities _capabilities; + private int? _width; + private int? _height; + + /// + /// Gets or sets the profile name. + /// + public string Name + { + get => _name; + set + { + if (value == null) + { + throw new InvalidOperationException("Profile name cannot be null"); + } + + _name = value; + } + } + + /// + /// Gets or sets the out buffer. + /// + public TextWriter Out + { + get => _out; + set + { + if (value == null) + { + throw new InvalidOperationException("Output buffer cannot be null"); + } + + _out = value; + + // Reset the width and height if not a TTY. + if (!Capabilities.Tty) + { + _width = null; + _height = null; + } + } + } + + /// + /// Gets or sets the console output encoding. + /// + public Encoding Encoding + { + get => _encoding; + set + { + if (value == null) + { + throw new InvalidOperationException("Encoding cannot be null"); + } + + // Need to update the output encoding for stdout? + if (_out.IsStandardOut()) + { + System.Console.OutputEncoding = value; + } + + _encoding = value; + } + } + + /// + /// Gets or sets an explicit console width. + /// + public int Width + { + get => GetWidth(); + set + { + if (_width <= 0) + { + throw new InvalidOperationException("Console width must be greater than zero"); + } + + _width = value; + } + } + + /// + /// Gets or sets an explicit console height. + /// + public int Height + { + get => GetHeight(); + set + { + if (_height <= 0) + { + throw new InvalidOperationException("Console height must be greater than zero"); + } + + _height = value; + } + } + + /// + /// Gets or sets the color system. + /// + public ColorSystem ColorSystem { get; set; } + + /// + /// Gets or sets the capabilities of the profile. + /// + public Capabilities Capabilities + { + get => _capabilities; + set + { + if (value == null) + { + throw new InvalidOperationException("Profile capabilities cannot be null"); + } + + _capabilities = value; + } + } + + /// + /// Initializes a new instance of the class. + /// + /// The profile name. + /// The output buffer. + /// The output encoding. + public Profile(string name, TextWriter @out, Encoding encoding) + { + _name = name ?? throw new ArgumentNullException(nameof(name)); + _out = @out ?? throw new ArgumentNullException(nameof(@out)); + _encoding = encoding ?? throw new ArgumentNullException(nameof(encoding)); + _capabilities = new Capabilities(this); + } + + /// + /// Checks whether the current profile supports + /// the specified color system. + /// + /// The color system to check. + /// true if the color system is supported, otherwise false. + public bool Supports(ColorSystem colorSystem) + { + return (int)colorSystem <= (int)ColorSystem; + } + + private int GetWidth() + { + if (_width != null) + { + return _width.Value; + } + + if (!Capabilities.Tty) + { + return ConsoleHelper.GetSafeWidth(Constants.DefaultTerminalWidth); + } + + return Constants.DefaultTerminalWidth; + } + + private int GetHeight() + { + if (_height != null) + { + return _height.Value; + } + + if (!Capabilities.Tty) + { + return ConsoleHelper.GetSafeHeight(Constants.DefaultTerminalHeight); + } + + return Constants.DefaultTerminalHeight; + } + } +} diff --git a/src/Spectre.Console/Profiles/AppVeyorProfile.cs b/src/Spectre.Console/Profiles/AppVeyorProfile.cs new file mode 100644 index 0000000..f5b6b53 --- /dev/null +++ b/src/Spectre.Console/Profiles/AppVeyorProfile.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Spectre.Console +{ + internal sealed class AppVeyorProfile : IProfileEnricher + { + public bool Enabled(IDictionary environmentVariables) + { + return environmentVariables.ContainsKey("APPVEYOR"); + } + + public void Enrich(Profile profile) + { + profile.Name = "AppVeyor"; + profile.Capabilities.Interactive = false; + } + } +} diff --git a/src/Spectre.Console/Profiles/BambooProfile.cs b/src/Spectre.Console/Profiles/BambooProfile.cs new file mode 100644 index 0000000..15922c6 --- /dev/null +++ b/src/Spectre.Console/Profiles/BambooProfile.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Spectre.Console +{ + internal sealed class BambooProfile : IProfileEnricher + { + public bool Enabled(IDictionary environmentVariables) + { + return environmentVariables.ContainsKey("bamboo_buildNumber"); + } + + public void Enrich(Profile profile) + { + profile.Name = "Bamboo"; + profile.Capabilities.Interactive = false; + } + } +} diff --git a/src/Spectre.Console/Profiles/BitbucketProfile.cs b/src/Spectre.Console/Profiles/BitbucketProfile.cs new file mode 100644 index 0000000..c30b10f --- /dev/null +++ b/src/Spectre.Console/Profiles/BitbucketProfile.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace Spectre.Console +{ + internal sealed class BitbucketProfile : IProfileEnricher + { + public bool Enabled(IDictionary environmentVariables) + { + return environmentVariables.ContainsKey("BITBUCKET_REPO_OWNER") || + environmentVariables.ContainsKey("BITBUCKET_REPO_SLUG") || + environmentVariables.ContainsKey("BITBUCKET_COMMIT"); + } + + public void Enrich(Profile profile) + { + profile.Name = "BitBucket"; + profile.Capabilities.Interactive = false; + } + } +} diff --git a/src/Spectre.Console/Profiles/BitriseProfile.cs b/src/Spectre.Console/Profiles/BitriseProfile.cs new file mode 100644 index 0000000..64762d9 --- /dev/null +++ b/src/Spectre.Console/Profiles/BitriseProfile.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Spectre.Console +{ + internal sealed class BitriseProfile : IProfileEnricher + { + public bool Enabled(IDictionary environmentVariables) + { + return environmentVariables.ContainsKey("BITRISE_BUILD_URL"); + } + + public void Enrich(Profile profile) + { + profile.Name = "Bitrise"; + profile.Capabilities.Interactive = false; + } + } +} diff --git a/src/Spectre.Console/Profiles/ContinuaCIProfile.cs b/src/Spectre.Console/Profiles/ContinuaCIProfile.cs new file mode 100644 index 0000000..bc0b97f --- /dev/null +++ b/src/Spectre.Console/Profiles/ContinuaCIProfile.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Spectre.Console +{ + internal sealed class ContinuaCIProfile : IProfileEnricher + { + public bool Enabled(IDictionary environmentVariables) + { + return environmentVariables.ContainsKey("ContinuaCI.Version"); + } + + public void Enrich(Profile profile) + { + profile.Name = "Continua CI"; + profile.Capabilities.Interactive = false; + } + } +} diff --git a/src/Spectre.Console/Profiles/GitHubProfile.cs b/src/Spectre.Console/Profiles/GitHubProfile.cs new file mode 100644 index 0000000..b04887b --- /dev/null +++ b/src/Spectre.Console/Profiles/GitHubProfile.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; + +namespace Spectre.Console +{ + internal sealed class GitHubProfile : IProfileEnricher + { + public bool Enabled(IDictionary environmentVariables) + { + if (environmentVariables.TryGetValue("GITHUB_ACTIONS", out var value)) + { + return value?.Equals("true", StringComparison.OrdinalIgnoreCase) ?? false; + } + + return false; + } + + public void Enrich(Profile profile) + { + profile.Name = "GitHub Actions"; + profile.Capabilities.Ansi = true; + profile.Capabilities.Legacy = false; + profile.Capabilities.Interactive = false; + profile.Capabilities.Links = false; + profile.Width = 120; + } + } +} diff --git a/src/Spectre.Console/Profiles/GitLabProfile.cs b/src/Spectre.Console/Profiles/GitLabProfile.cs new file mode 100644 index 0000000..cd8bc2a --- /dev/null +++ b/src/Spectre.Console/Profiles/GitLabProfile.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; + +namespace Spectre.Console +{ + internal sealed class GitLabProfile : IProfileEnricher + { + public bool Enabled(IDictionary environmentVariables) + { + if (environmentVariables.TryGetValue("CI_SERVER", out var value)) + { + return value?.Equals("yes", StringComparison.OrdinalIgnoreCase) ?? false; + } + + return false; + } + + public void Enrich(Profile profile) + { + profile.Name = "GitLab"; + profile.Capabilities.Interactive = false; + } + } +} diff --git a/src/Spectre.Console/Profiles/GoCDProfile.cs b/src/Spectre.Console/Profiles/GoCDProfile.cs new file mode 100644 index 0000000..4147ad5 --- /dev/null +++ b/src/Spectre.Console/Profiles/GoCDProfile.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Spectre.Console +{ + internal sealed class GoCDProfile : IProfileEnricher + { + public bool Enabled(IDictionary environmentVariables) + { + return environmentVariables.ContainsKey("GO_SERVER_URL"); + } + + public void Enrich(Profile profile) + { + profile.Name = "GoCD"; + profile.Capabilities.Interactive = false; + } + } +} diff --git a/src/Spectre.Console/Profiles/JenkinsProfile.cs b/src/Spectre.Console/Profiles/JenkinsProfile.cs new file mode 100644 index 0000000..861a363 --- /dev/null +++ b/src/Spectre.Console/Profiles/JenkinsProfile.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Spectre.Console +{ + internal sealed class JenkinsProfile : IProfileEnricher + { + public bool Enabled(IDictionary environmentVariables) + { + return environmentVariables.ContainsKey("JENKINS_URL"); + } + + public void Enrich(Profile profile) + { + profile.Name = "Jenkins"; + profile.Capabilities.Interactive = false; + } + } +} diff --git a/src/Spectre.Console/Profiles/MyGetProfile.cs b/src/Spectre.Console/Profiles/MyGetProfile.cs new file mode 100644 index 0000000..eb8d26c --- /dev/null +++ b/src/Spectre.Console/Profiles/MyGetProfile.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; + +namespace Spectre.Console +{ + internal sealed class MyGetProfile : IProfileEnricher + { + public bool Enabled(IDictionary environmentVariables) + { + if (environmentVariables.TryGetValue("BuildRunner", out var value)) + { + return value?.Equals("MyGet", StringComparison.OrdinalIgnoreCase) ?? false; + } + + return false; + } + + public void Enrich(Profile profile) + { + profile.Name = "MyGet"; + profile.Capabilities.Interactive = false; + } + } +} diff --git a/src/Spectre.Console/Profiles/TeamCityProfile.cs b/src/Spectre.Console/Profiles/TeamCityProfile.cs new file mode 100644 index 0000000..f5d19ea --- /dev/null +++ b/src/Spectre.Console/Profiles/TeamCityProfile.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Spectre.Console +{ + internal sealed class TeamCityProfile : IProfileEnricher + { + public bool Enabled(IDictionary environmentVariables) + { + return environmentVariables.ContainsKey("TEAMCITY_VERSION"); + } + + public void Enrich(Profile profile) + { + profile.Name = "TeamCity"; + profile.Capabilities.Interactive = false; + } + } +} diff --git a/src/Spectre.Console/Profiles/TfsProfile.cs b/src/Spectre.Console/Profiles/TfsProfile.cs new file mode 100644 index 0000000..25681ac --- /dev/null +++ b/src/Spectre.Console/Profiles/TfsProfile.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Spectre.Console +{ + internal sealed class TfsProfile : IProfileEnricher + { + public bool Enabled(IDictionary environmentVariables) + { + return environmentVariables.ContainsKey("TF_BUILD"); + } + + public void Enrich(Profile profile) + { + profile.Name = "TFS"; + profile.Capabilities.Interactive = false; + } + } +} diff --git a/src/Spectre.Console/Profiles/TravisProfile.cs b/src/Spectre.Console/Profiles/TravisProfile.cs new file mode 100644 index 0000000..dacf373 --- /dev/null +++ b/src/Spectre.Console/Profiles/TravisProfile.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Spectre.Console +{ + internal sealed class TravisProfile : IProfileEnricher + { + public bool Enabled(IDictionary environmentVariables) + { + return environmentVariables.ContainsKey("TRAVIS"); + } + + public void Enrich(Profile profile) + { + profile.Name = "Travis"; + profile.Capabilities.Interactive = false; + } + } +} diff --git a/src/Spectre.Console/Recorder.cs b/src/Spectre.Console/Recorder.cs index f1ffadb..c96be0c 100644 --- a/src/Spectre.Console/Recorder.cs +++ b/src/Spectre.Console/Recorder.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; -using System.Text; using Spectre.Console.Rendering; namespace Spectre.Console @@ -10,17 +9,13 @@ namespace Spectre.Console /// /// A console recorder used to record output from a console. /// - [SuppressMessage("Design", "CA1063:Implement IDisposable Correctly")] public class Recorder : IAnsiConsole, IDisposable { private readonly IAnsiConsole _console; private readonly List _recorded; /// - public Capabilities Capabilities => _console.Capabilities; - - /// - public Encoding Encoding => _console.Encoding; + public Profile Profile => _console.Profile; /// public IAnsiConsoleCursor Cursor => _console.Cursor; @@ -28,12 +23,6 @@ namespace Spectre.Console /// public IAnsiConsoleInput Input => _console.Input; - /// - public int Width => _console.Width; - - /// - public int Height => _console.Height; - /// public RenderPipeline Pipeline => _console.Pipeline; diff --git a/src/Spectre.Console/Rendering/Borders/Tables/MarkdownTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/MarkdownTableBorder.cs index 3420ec9..3842e14 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/MarkdownTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/MarkdownTableBorder.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Text; -using Spectre.Console.Internal; namespace Spectre.Console.Rendering { diff --git a/src/Spectre.Console/Rendering/LiveRenderable.cs b/src/Spectre.Console/Rendering/LiveRenderable.cs index 7c3bf5d..5c88d0c 100644 --- a/src/Spectre.Console/Rendering/LiveRenderable.cs +++ b/src/Spectre.Console/Rendering/LiveRenderable.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Spectre.Console.Internal; namespace Spectre.Console.Rendering { diff --git a/src/Spectre.Console/Rendering/Segment.cs b/src/Spectre.Console/Rendering/Segment.cs index e7fed43..6b64837 100644 --- a/src/Spectre.Console/Rendering/Segment.cs +++ b/src/Spectre.Console/Rendering/Segment.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; -using Spectre.Console.Internal; namespace Spectre.Console.Rendering { diff --git a/src/Spectre.Console/Rendering/SegmentLine.cs b/src/Spectre.Console/Rendering/SegmentLine.cs index f643e9d..6978eb6 100644 --- a/src/Spectre.Console/Rendering/SegmentLine.cs +++ b/src/Spectre.Console/Rendering/SegmentLine.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; namespace Spectre.Console.Rendering @@ -7,7 +6,6 @@ namespace Spectre.Console.Rendering /// /// Represents a collection of segments. /// - [SuppressMessage("Naming", "CA1710:Identifiers should have correct suffix")] public sealed class SegmentLine : List { /// diff --git a/src/Spectre.Console/Style.cs b/src/Spectre.Console/Style.cs index 4519d65..b0e1ad0 100644 --- a/src/Spectre.Console/Style.cs +++ b/src/Spectre.Console/Style.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using Spectre.Console.Internal; namespace Spectre.Console { @@ -146,7 +144,6 @@ namespace Spectre.Console /// Implicitly converts into a . /// /// The style string. - [SuppressMessage("Usage", "CA2225:Operator overloads have named alternates")] public static implicit operator Style(string style) { return Parse(style); diff --git a/src/Spectre.Console/Internal/Text/StyleParser.cs b/src/Spectre.Console/StyleParser.cs similarity index 96% rename from src/Spectre.Console/Internal/Text/StyleParser.cs rename to src/Spectre.Console/StyleParser.cs index aaf234c..24a910f 100644 --- a/src/Spectre.Console/Internal/Text/StyleParser.cs +++ b/src/Spectre.Console/StyleParser.cs @@ -1,8 +1,7 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class StyleParser { @@ -138,7 +137,6 @@ namespace Spectre.Console.Internal effectiveLink); } - [SuppressMessage("Design", "CA1031:Do not catch general exception types")] private static Color? ParseHexColor(string hex, out string? error) { error = null; @@ -176,7 +174,6 @@ namespace Spectre.Console.Internal return null; } - [SuppressMessage("Design", "CA1031:Do not catch general exception types")] private static Color? ParseRgbColor(string rgb, out string? error) { try diff --git a/src/Spectre.Console/TableBorder.cs b/src/Spectre.Console/TableBorder.cs index 531bc75..16a1609 100644 --- a/src/Spectre.Console/TableBorder.cs +++ b/src/Spectre.Console/TableBorder.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Text; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Widgets/Calendar.cs b/src/Spectre.Console/Widgets/Calendar.cs index cd93b0d..f7bea90 100644 --- a/src/Spectre.Console/Widgets/Calendar.cs +++ b/src/Spectre.Console/Widgets/Calendar.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/ExceptionFormat.cs b/src/Spectre.Console/Widgets/Exceptions/ExceptionFormat.cs similarity index 100% rename from src/Spectre.Console/ExceptionFormat.cs rename to src/Spectre.Console/Widgets/Exceptions/ExceptionFormat.cs diff --git a/src/Spectre.Console/Internal/ExceptionFormatter.cs b/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs similarity index 99% rename from src/Spectre.Console/Internal/ExceptionFormatter.cs rename to src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs index afb2612..75ae7dd 100644 --- a/src/Spectre.Console/Internal/ExceptionFormatter.cs +++ b/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using Spectre.Console.Rendering; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class ExceptionFormatter { diff --git a/src/Spectre.Console/Internal/ExceptionInfo.cs b/src/Spectre.Console/Widgets/Exceptions/ExceptionInfo.cs similarity index 88% rename from src/Spectre.Console/Internal/ExceptionInfo.cs rename to src/Spectre.Console/Widgets/Exceptions/ExceptionInfo.cs index b8b6fc9..d863d00 100644 --- a/src/Spectre.Console/Internal/ExceptionInfo.cs +++ b/src/Spectre.Console/Widgets/Exceptions/ExceptionInfo.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; +using System.Collections.Generic; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal sealed class ExceptionInfo { diff --git a/src/Spectre.Console/Internal/ExceptionParser.cs b/src/Spectre.Console/Widgets/Exceptions/ExceptionParser.cs similarity index 99% rename from src/Spectre.Console/Internal/ExceptionParser.cs rename to src/Spectre.Console/Widgets/Exceptions/ExceptionParser.cs index 394e208..ad120d0 100644 --- a/src/Spectre.Console/Internal/ExceptionParser.cs +++ b/src/Spectre.Console/Widgets/Exceptions/ExceptionParser.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.Text.RegularExpressions; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal static class ExceptionParser { diff --git a/src/Spectre.Console/ExceptionSettings.cs b/src/Spectre.Console/Widgets/Exceptions/ExceptionSettings.cs similarity index 100% rename from src/Spectre.Console/ExceptionSettings.cs rename to src/Spectre.Console/Widgets/Exceptions/ExceptionSettings.cs diff --git a/src/Spectre.Console/ExceptionStyle.cs b/src/Spectre.Console/Widgets/Exceptions/ExceptionStyle.cs similarity index 100% rename from src/Spectre.Console/ExceptionStyle.cs rename to src/Spectre.Console/Widgets/Exceptions/ExceptionStyle.cs diff --git a/src/Spectre.Console/Internal/StackFrameInfo.cs b/src/Spectre.Console/Widgets/Exceptions/StackFrameInfo.cs similarity index 93% rename from src/Spectre.Console/Internal/StackFrameInfo.cs rename to src/Spectre.Console/Widgets/Exceptions/StackFrameInfo.cs index de03011..746985f 100644 --- a/src/Spectre.Console/Internal/StackFrameInfo.cs +++ b/src/Spectre.Console/Widgets/Exceptions/StackFrameInfo.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Net; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal sealed class StackFrameInfo { @@ -22,7 +22,6 @@ namespace Spectre.Console.Internal LineNumber = lineNumber; } - [SuppressMessage("Design", "CA1031:Do not catch general exception types")] public bool TryGetUri([NotNullWhen(true)] out Uri? result) { try diff --git a/src/Spectre.Console/Widgets/Figlet/FigletFont.cs b/src/Spectre.Console/Widgets/Figlet/FigletFont.cs index c388cef..c48dc80 100644 --- a/src/Spectre.Console/Widgets/Figlet/FigletFont.cs +++ b/src/Spectre.Console/Widgets/Figlet/FigletFont.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using Spectre.Console.Internal; namespace Spectre.Console { diff --git a/src/Spectre.Console/Widgets/Grid.cs b/src/Spectre.Console/Widgets/Grid.cs index 7fedde1..a8a8cd4 100644 --- a/src/Spectre.Console/Widgets/Grid.cs +++ b/src/Spectre.Console/Widgets/Grid.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Widgets/Markup.cs b/src/Spectre.Console/Widgets/Markup.cs index f4405f7..1d426a7 100644 --- a/src/Spectre.Console/Widgets/Markup.cs +++ b/src/Spectre.Console/Widgets/Markup.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Widgets/Padder.cs b/src/Spectre.Console/Widgets/Padder.cs index c8c7536..c04d96d 100644 --- a/src/Spectre.Console/Widgets/Padder.cs +++ b/src/Spectre.Console/Widgets/Padder.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Widgets/Paragraph.cs b/src/Spectre.Console/Widgets/Paragraph.cs index 4a6c447..818a9d8 100644 --- a/src/Spectre.Console/Widgets/Paragraph.cs +++ b/src/Spectre.Console/Widgets/Paragraph.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Widgets/Progress/Columns/DownloadedColumn.cs b/src/Spectre.Console/Widgets/Progress/Columns/DownloadedColumn.cs index a4c8690..e115642 100644 --- a/src/Spectre.Console/Widgets/Progress/Columns/DownloadedColumn.cs +++ b/src/Spectre.Console/Widgets/Progress/Columns/DownloadedColumn.cs @@ -1,6 +1,5 @@ using System; using System.Globalization; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Widgets/Progress/Columns/SpinnerColumn.cs b/src/Spectre.Console/Widgets/Progress/Columns/SpinnerColumn.cs index 00b16dd..1669a17 100644 --- a/src/Spectre.Console/Widgets/Progress/Columns/SpinnerColumn.cs +++ b/src/Spectre.Console/Widgets/Progress/Columns/SpinnerColumn.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Widgets/Progress/Columns/TransferSpeedColumn.cs b/src/Spectre.Console/Widgets/Progress/Columns/TransferSpeedColumn.cs index ed08f4d..0185462 100644 --- a/src/Spectre.Console/Widgets/Progress/Columns/TransferSpeedColumn.cs +++ b/src/Spectre.Console/Widgets/Progress/Columns/TransferSpeedColumn.cs @@ -1,6 +1,5 @@ using System; using System.Globalization; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Widgets/Progress/Progress.cs b/src/Spectre.Console/Widgets/Progress/Progress.cs index 80761fe..ca072fe 100644 --- a/src/Spectre.Console/Widgets/Progress/Progress.cs +++ b/src/Spectre.Console/Widgets/Progress/Progress.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console @@ -148,8 +147,8 @@ namespace Spectre.Console private ProgressRenderer CreateRenderer() { - var caps = _console.Capabilities; - var interactive = caps.SupportsInteraction && caps.SupportsAnsi; + var caps = _console.Profile.Capabilities; + var interactive = caps.Interactive && caps.Ansi; if (interactive) { diff --git a/src/Spectre.Console/Widgets/Progress/ProgressContext.cs b/src/Spectre.Console/Widgets/Progress/ProgressContext.cs index b85fe37..8e71431 100644 --- a/src/Spectre.Console/Widgets/Progress/ProgressContext.cs +++ b/src/Spectre.Console/Widgets/Progress/ProgressContext.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using Spectre.Console.Internal; namespace Spectre.Console { @@ -22,8 +20,6 @@ namespace Spectre.Console /// public bool IsFinished => _tasks.All(task => task.IsFinished); - internal Encoding Encoding => _console.Encoding; - internal ProgressContext(IAnsiConsole console, ProgressRenderer renderer) { _tasks = new List(); diff --git a/src/Spectre.Console/Widgets/Progress/ProgressRefreshThread.cs b/src/Spectre.Console/Widgets/Progress/ProgressRefreshThread.cs index 35cd09e..5a50995 100644 --- a/src/Spectre.Console/Widgets/Progress/ProgressRefreshThread.cs +++ b/src/Spectre.Console/Widgets/Progress/ProgressRefreshThread.cs @@ -1,7 +1,7 @@ using System; using System.Threading; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal sealed class ProgressRefreshThread : IDisposable { diff --git a/src/Spectre.Console/Widgets/Progress/ProgressRenderer.cs b/src/Spectre.Console/Widgets/Progress/ProgressRenderer.cs index 14fc8d4..c3b9dbe 100644 --- a/src/Spectre.Console/Widgets/Progress/ProgressRenderer.cs +++ b/src/Spectre.Console/Widgets/Progress/ProgressRenderer.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using Spectre.Console.Rendering; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal abstract class ProgressRenderer : IRenderHook { diff --git a/src/Spectre.Console/Widgets/Progress/ProgressSample.cs b/src/Spectre.Console/Widgets/Progress/ProgressSample.cs index b8fc57f..2dab697 100644 --- a/src/Spectre.Console/Widgets/Progress/ProgressSample.cs +++ b/src/Spectre.Console/Widgets/Progress/ProgressSample.cs @@ -1,6 +1,6 @@ using System; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal readonly struct ProgressSample { diff --git a/src/Spectre.Console/Widgets/Progress/ProgressTask.cs b/src/Spectre.Console/Widgets/Progress/ProgressTask.cs index 9f7fd69..91b30c0 100644 --- a/src/Spectre.Console/Widgets/Progress/ProgressTask.cs +++ b/src/Spectre.Console/Widgets/Progress/ProgressTask.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Spectre.Console.Internal; namespace Spectre.Console { diff --git a/src/Spectre.Console/Widgets/Progress/Renderers/DefaultProgressRenderer.cs b/src/Spectre.Console/Widgets/Progress/Renderers/DefaultProgressRenderer.cs index 586ded4..2051b1b 100644 --- a/src/Spectre.Console/Widgets/Progress/Renderers/DefaultProgressRenderer.cs +++ b/src/Spectre.Console/Widgets/Progress/Renderers/DefaultProgressRenderer.cs @@ -4,7 +4,7 @@ using System.Diagnostics; using System.Linq; using Spectre.Console.Rendering; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal sealed class DefaultProgressRenderer : ProgressRenderer { @@ -60,7 +60,7 @@ namespace Spectre.Console.Internal _stopwatch.Start(); } - var renderContext = new RenderContext(_console.Encoding, _console.Capabilities.LegacyConsole); + var renderContext = new RenderContext(_console.Profile.Encoding, _console.Profile.Capabilities.Legacy); var delta = _stopwatch.Elapsed - _lastUpdate; _lastUpdate = _stopwatch.Elapsed; diff --git a/src/Spectre.Console/Widgets/Progress/Renderers/FallbackProgressRenderer.cs b/src/Spectre.Console/Widgets/Progress/Renderers/FallbackProgressRenderer.cs index c4dae38..bee35d7 100644 --- a/src/Spectre.Console/Widgets/Progress/Renderers/FallbackProgressRenderer.cs +++ b/src/Spectre.Console/Widgets/Progress/Renderers/FallbackProgressRenderer.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using Spectre.Console.Rendering; -namespace Spectre.Console.Internal +namespace Spectre.Console { internal sealed class FallbackProgressRenderer : ProgressRenderer { diff --git a/src/Spectre.Console/Widgets/Progress/Renderers/StatusFallbackRenderer.cs b/src/Spectre.Console/Widgets/Progress/Renderers/FallbackStatusRenderer.cs similarity index 91% rename from src/Spectre.Console/Widgets/Progress/Renderers/StatusFallbackRenderer.cs rename to src/Spectre.Console/Widgets/Progress/Renderers/FallbackStatusRenderer.cs index 2c88181..4b10c10 100644 --- a/src/Spectre.Console/Widgets/Progress/Renderers/StatusFallbackRenderer.cs +++ b/src/Spectre.Console/Widgets/Progress/Renderers/FallbackStatusRenderer.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using Spectre.Console.Rendering; -namespace Spectre.Console.Internal +namespace Spectre.Console { - internal sealed class StatusFallbackRenderer : ProgressRenderer + internal sealed class FallbackStatusRenderer : ProgressRenderer { private readonly object _lock; private IRenderable? _renderable; @@ -13,7 +13,7 @@ namespace Spectre.Console.Internal public override TimeSpan RefreshRate => TimeSpan.FromMilliseconds(100); - public StatusFallbackRenderer() + public FallbackStatusRenderer() { _lock = new object(); } diff --git a/src/Spectre.Console/Widgets/Progress/Status.cs b/src/Spectre.Console/Widgets/Progress/Status.cs index d11fe4a..57392cc 100644 --- a/src/Spectre.Console/Widgets/Progress/Status.cs +++ b/src/Spectre.Console/Widgets/Progress/Status.cs @@ -1,6 +1,5 @@ using System; using System.Threading.Tasks; -using Spectre.Console.Internal; namespace Spectre.Console { @@ -107,7 +106,7 @@ namespace Spectre.Console var progress = new Progress(_console) { - FallbackRenderer = new StatusFallbackRenderer(), + FallbackRenderer = new FallbackStatusRenderer(), AutoClear = true, AutoRefresh = AutoRefresh, }; diff --git a/src/Spectre.Console/Widgets/Prompt/MultiSelectionPrompt.cs b/src/Spectre.Console/Widgets/Prompt/MultiSelectionPrompt.cs index a1bbf74..43131d8 100644 --- a/src/Spectre.Console/Widgets/Prompt/MultiSelectionPrompt.cs +++ b/src/Spectre.Console/Widgets/Prompt/MultiSelectionPrompt.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console @@ -63,14 +62,14 @@ namespace Spectre.Console /// public List Show(IAnsiConsole console) { - if (!console.Capabilities.SupportsInteraction) + if (!console.Profile.Capabilities.Interactive) { throw new NotSupportedException( "Cannot show multi selection prompt since the current " + "terminal isn't interactive."); } - if (!console.Capabilities.SupportsAnsi) + if (!console.Profile.Capabilities.Ansi) { throw new NotSupportedException( "Cannot show multi selection prompt since the current " + diff --git a/src/Spectre.Console/Widgets/Prompt/Rendering/RenderableList.cs b/src/Spectre.Console/Widgets/Prompt/Rendering/RenderableList.cs index 6931bbc..5823f5a 100644 --- a/src/Spectre.Console/Widgets/Prompt/Rendering/RenderableList.cs +++ b/src/Spectre.Console/Widgets/Prompt/Rendering/RenderableList.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Widgets/Prompt/Rendering/RenderableMultiSelectionList.cs b/src/Spectre.Console/Widgets/Prompt/Rendering/RenderableMultiSelectionList.cs index 97f184f..e38bc99 100644 --- a/src/Spectre.Console/Widgets/Prompt/Rendering/RenderableMultiSelectionList.cs +++ b/src/Spectre.Console/Widgets/Prompt/Rendering/RenderableMultiSelectionList.cs @@ -45,9 +45,9 @@ namespace Spectre.Console protected override int CalculatePageSize(int requestedPageSize) { var pageSize = requestedPageSize; - if (pageSize > _console.Height - 5) + if (pageSize > _console.Profile.Height - 5) { - pageSize = _console.Height - 5; + pageSize = _console.Profile.Height - 5; } return pageSize; diff --git a/src/Spectre.Console/Widgets/Prompt/Rendering/RenderableSelectionList.cs b/src/Spectre.Console/Widgets/Prompt/Rendering/RenderableSelectionList.cs index b9696f9..9f4113e 100644 --- a/src/Spectre.Console/Widgets/Prompt/Rendering/RenderableSelectionList.cs +++ b/src/Spectre.Console/Widgets/Prompt/Rendering/RenderableSelectionList.cs @@ -23,9 +23,9 @@ namespace Spectre.Console protected override int CalculatePageSize(int requestedPageSize) { var pageSize = requestedPageSize; - if (pageSize > _console.Height - 4) + if (pageSize > _console.Profile.Height - 4) { - pageSize = _console.Height - 4; + pageSize = _console.Profile.Height - 4; } return pageSize; diff --git a/src/Spectre.Console/Widgets/Prompt/SelectionPrompt.cs b/src/Spectre.Console/Widgets/Prompt/SelectionPrompt.cs index 3cb6b9c..8ac7b40 100644 --- a/src/Spectre.Console/Widgets/Prompt/SelectionPrompt.cs +++ b/src/Spectre.Console/Widgets/Prompt/SelectionPrompt.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console @@ -50,14 +49,14 @@ namespace Spectre.Console /// T IPrompt.Show(IAnsiConsole console) { - if (!console.Capabilities.SupportsInteraction) + if (!console.Profile.Capabilities.Interactive) { throw new NotSupportedException( "Cannot show selection prompt since the current " + "terminal isn't interactive."); } - if (!console.Capabilities.SupportsAnsi) + if (!console.Profile.Capabilities.Ansi) { throw new NotSupportedException( "Cannot show selection prompt since the current " + diff --git a/src/Spectre.Console/Widgets/Prompt/TextPrompt.cs b/src/Spectre.Console/Widgets/Prompt/TextPrompt.cs index 71af690..45021bb 100644 --- a/src/Spectre.Console/Widgets/Prompt/TextPrompt.cs +++ b/src/Spectre.Console/Widgets/Prompt/TextPrompt.cs @@ -5,7 +5,6 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Text; -using Spectre.Console.Internal; namespace Spectre.Console { diff --git a/src/Spectre.Console/Widgets/Rows.cs b/src/Spectre.Console/Widgets/Rows.cs index b1c144e..692c392 100644 --- a/src/Spectre.Console/Widgets/Rows.cs +++ b/src/Spectre.Console/Widgets/Rows.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Widgets/Table/Table.cs b/src/Spectre.Console/Widgets/Table/Table.cs index f0ff0da..66d04ae 100644 --- a/src/Spectre.Console/Widgets/Table/Table.cs +++ b/src/Spectre.Console/Widgets/Table/Table.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Widgets/Table/TableMeasurer.cs b/src/Spectre.Console/Widgets/Table/TableMeasurer.cs index fa474aa..28c55fc 100644 --- a/src/Spectre.Console/Widgets/Table/TableMeasurer.cs +++ b/src/Spectre.Console/Widgets/Table/TableMeasurer.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Widgets/Table/TableRenderer.cs b/src/Spectre.Console/Widgets/Table/TableRenderer.cs index e82b571..c66b663 100644 --- a/src/Spectre.Console/Widgets/Table/TableRenderer.cs +++ b/src/Spectre.Console/Widgets/Table/TableRenderer.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console diff --git a/src/Spectre.Console/Widgets/Tree.cs b/src/Spectre.Console/Widgets/Tree.cs index 93dfdff..5638e34 100644 --- a/src/Spectre.Console/Widgets/Tree.cs +++ b/src/Spectre.Console/Widgets/Tree.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Spectre.Console.Internal; using Spectre.Console.Rendering; namespace Spectre.Console