Add profile support

Closes #231
This commit is contained in:
Patrik Svensson
2021-01-16 17:23:58 +01:00
committed by Patrik Svensson
parent 913a7b1e37
commit a23bec4082
230 changed files with 1241 additions and 1628 deletions

View File

@ -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;
/// <summary>
/// Gets the console's capabilities.
/// Gets the console profile.
/// </summary>
public static Capabilities Capabilities => Console.Capabilities;
/// <summary>
/// Gets the buffer width of the console.
/// </summary>
public static int Width
{
get => Console.Width;
}
/// <summary>
/// Gets the buffer height of the console.
/// </summary>
public static int Height
{
get => Console.Height;
}
public static Profile Profile => Console.Profile;
/// <summary>
/// Creates a new <see cref="IAnsiConsole"/> instance
@ -61,7 +45,8 @@ namespace Spectre.Console
/// <returns>An <see cref="IAnsiConsole"/> instance.</returns>
public static IAnsiConsole Create(AnsiConsoleSettings settings)
{
return BackendBuilder.Build(settings);
var factory = new AnsiConsoleFactory();
return factory.Create(settings);
}
}
}

View File

@ -0,0 +1,178 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace Spectre.Console
{
/// <summary>
/// Factory for creating an ANSI console.
/// </summary>
public sealed class AnsiConsoleFactory
{
private readonly List<IProfileEnricher> _enrichers;
/// <summary>
/// Initializes a new instance of the <see cref="AnsiConsoleFactory"/> class.
/// </summary>
public AnsiConsoleFactory()
{
_enrichers = new List<IProfileEnricher>
{
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(),
};
}
/// <summary>
/// Initializes a new instance of the <see cref="AnsiConsoleFactory"/> class.
/// </summary>
/// <param name="enrichers">The profile enrichers to use.</param>
public AnsiConsoleFactory(IEnumerable<IProfileEnricher> enrichers)
{
_enrichers = new List<IProfileEnricher>(enrichers ?? Enumerable.Empty<IProfileEnricher>());
}
/// <summary>
/// Creates a new <see cref="AnsiConsoleFactory"/> without default profile enrichers.
/// </summary>
/// <returns>A new <see cref="AnsiConsoleFactory"/> without default profile enrichers.</returns>
public static AnsiConsoleFactory NoEnrichers()
{
return new AnsiConsoleFactory(Enumerable.Empty<IProfileEnricher>());
}
/// <summary>
/// Creates an ANSI console.
/// </summary>
/// <param name="settings">The settings.</param>
/// <returns>An implementation of <see cref="IAnsiConsole"/>.</returns>
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<IProfileEnricher>();
foreach (var enricher in _enrichers.Concat(customEnrichers))
{
if (enricher.Enabled(variables))
{
enricher.Enrich(profile);
}
}
return new AnsiConsoleFacade(profile);
}
private static IDictionary<string, string> GetEnvironmentVariables(AnsiConsoleSettings settings)
{
if (settings.EnvironmentVariables != null)
{
return new Dictionary<string, string>(settings.EnvironmentVariables, StringComparer.OrdinalIgnoreCase);
}
return Environment.GetEnvironmentVariables()
.Cast<System.Collections.DictionaryEntry>()
.Aggregate(
new Dictionary<string, string>(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);
}
}
}

View File

@ -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; }
/// <summary>
/// Gets or sets a value indicating whether or
/// not the console is interactive.
/// Gets or sets the out buffer.
/// </summary>
public TextWriter? Out { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not the
/// terminal is interactive or not.
/// </summary>
public InteractionSupport Interactive { get; set; }
/// <summary>
/// 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.
/// </summary>
public ILinkIdentityGenerator? LinkIdentityGenerator { get; set; }
public Dictionary<string, string>? EnvironmentVariables { get; set; }
/// <summary>
/// Gets or sets the out buffer.
/// Gets or sets the profile enrichers to use.
/// </summary>
public TextWriter? Out { get; set; }
public List<IProfileEnricher>? Enrichers { get; set; }
}
}

View File

@ -1,3 +1,5 @@
using System;
namespace Spectre.Console
{
/// <summary>
@ -5,14 +7,16 @@ namespace Spectre.Console
/// </summary>
public sealed class Capabilities
{
/// <summary>
/// Gets a value indicating whether or not
/// the console supports Ansi.
/// </summary>
public bool SupportsAnsi { get; }
private readonly Profile _profile;
/// <summary>
/// Gets a value indicating whether or not
/// Gets or sets a value indicating whether or not
/// the console supports Ansi.
/// </summary>
public bool Ansi { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not
/// the console support links.
/// </summary>
/// <remarks>
@ -20,69 +24,48 @@ namespace Spectre.Console
/// once we have more information about the terminal
/// we're running inside.
/// </remarks>
public bool SupportLinks => SupportsAnsi && !LegacyConsole;
public bool Links { get; set; }
/// <summary>
/// Gets the color system.
/// </summary>
public ColorSystem ColorSystem { get; }
/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// Only relevant when running on Microsoft Windows.
/// </remarks>
public bool LegacyConsole { get; }
public bool Legacy { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not the console supports interaction.
/// Gets a value indicating whether console output
/// has been redirected.
/// </summary>
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;
}
}
/// <summary>
/// Gets or sets a value indicating whether
/// or not the console supports interaction.
/// </summary>
public bool Interactive { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="Capabilities"/> class.
/// </summary>
/// <param name="supportsAnsi">Whether or not ANSI escape sequences are supported.</param>
/// <param name="colorSystem">The color system that is supported.</param>
/// <param name="legacyConsole">Whether or not this is a legacy console.</param>
/// <param name="supportsInteraction">Whether or not the console supports interaction.</param>
public Capabilities(bool supportsAnsi, ColorSystem colorSystem, bool legacyConsole, bool supportsInteraction)
internal Capabilities(Profile profile)
{
SupportsAnsi = supportsAnsi;
ColorSystem = colorSystem;
LegacyConsole = legacyConsole;
SupportsInteraction = supportsInteraction;
}
/// <summary>
/// Checks whether the current capabilities supports
/// the specified color system.
/// </summary>
/// <param name="colorSystem">The color system to check.</param>
/// <returns><c>true</c> if the color system is supported, otherwise <c>false</c>.</returns>
public bool Supports(ColorSystem colorSystem)
{
return (int)colorSystem <= (int)ColorSystem;
}
/// <inheritdoc/>
public override string ToString()
{
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));
}
}
}

View File

@ -1,5 +1,4 @@
using System;
using Spectre.Console.Cli.Internal;
namespace Spectre.Console.Cli
{

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Spectre.Console.Cli.Internal;
namespace Spectre.Console.Cli
{

View File

@ -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.
/// </summary>
[Flags]
[SuppressMessage("Naming", "CA1714:Flags enums should have plural names")]
public enum CaseSensitivity
{
/// <summary>

View File

@ -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<VersionCommand>(Constants.Commands.Version);
cli.AddCommand<XmlDocCommand>(Constants.Commands.XmlDoc);
cli.AddCommand<VersionCommand>(CliConstants.Commands.Version);
cli.AddCommand<XmlDocCommand>(CliConstants.Commands.XmlDoc);
});
_executed = true;

View File

@ -1,6 +1,5 @@
using System;
using System.Linq;
using Spectre.Console.Cli.Internal;
using Spectre.Console.Rendering;
namespace Spectre.Console.Cli

View File

@ -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

View File

@ -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}'.");
}

View File

@ -1,5 +1,4 @@
using System.Globalization;
using Spectre.Console.Cli.Internal;
using Spectre.Console.Rendering;
namespace Spectre.Console.Cli

View File

@ -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
{

View File

@ -1,6 +1,6 @@
using System;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal static class CommandPropertyBinder
{

View File

@ -1,6 +1,6 @@
using System;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class CommandValueBinder
{

View File

@ -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)>
{

View File

@ -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
{

View File

@ -1,4 +1,4 @@
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
/// <summary>
/// Representation of a multi map.

View File

@ -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<TKey, TValue> : IMultiMap, ILookup<TKey, TValue>, IDictionary<TKey, TValue>, IReadOnlyDictionary<TKey, TValue>

View File

@ -1,6 +1,6 @@
using System;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal static class CommandBinder
{

View File

@ -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
{

View File

@ -1,4 +1,4 @@
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal enum CommandPart
{

View File

@ -1,7 +1,7 @@
using System;
using System.Linq;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal static class CommandSuggestor
{

View File

@ -1,4 +1,4 @@
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal static class CommandValidator
{

View File

@ -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")]

View File

@ -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")]

View File

@ -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
{

View File

@ -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
{

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class ComponentRegistration
{

View File

@ -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
{

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class DefaultTypeRegistrar : ITypeRegistrar
{

View File

@ -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
{

View File

@ -1,6 +1,6 @@
using System;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class CommandAppSettings : ICommandAppSettings
{

View File

@ -1,4 +1,4 @@
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class CommandConfigurator : ICommandConfigurator
{

View File

@ -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
{

View File

@ -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<TDefaultCommand>(
Constants.DefaultCommandName, isDefaultCommand: true);
CliConstants.DefaultCommandName, isDefaultCommand: true);
}
public ICommandConfigurator AddCommand<TCommand>(string name)

View File

@ -1,7 +1,7 @@
using System;
using Spectre.Console.Cli.Unsafe;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class Configurator<TSettings> : IUnsafeBranchConfigurator, IConfigurator<TSettings>
where TSettings : CommandSettings

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class ConfiguredCommand
{

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
/// <summary>
/// Represents a configuration.

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal static class TemplateParser
{

View File

@ -1,4 +1,4 @@
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class TemplateToken
{

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Text;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal static class TemplateTokenizer
{

View File

@ -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";

View File

@ -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

View File

@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class DelegateCommand : ICommand
{

View File

@ -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
{

View File

@ -1,6 +1,6 @@
using Spectre.Console.Rendering;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal static class CommandLineTemplateExceptionFactory
{

View File

@ -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
{

View File

@ -1,6 +1,6 @@
using System;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal static class CaseSensitivityExtensions
{

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal static class ListExtensions
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -1,6 +1,6 @@
using System;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
/// <summary>
/// Represents a pair deconstructor.

View File

@ -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
{

View File

@ -1,6 +1,6 @@
using System.Linq;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal static class CommandContainerExtensions
{

View File

@ -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
{

View File

@ -1,6 +1,6 @@
using System.Linq;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal static class CommandInfoExtensions
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal static class CommandParameterComparer
{

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
/// <summary>
/// Represents a command container.

View File

@ -1,6 +1,6 @@
using System.ComponentModel;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal enum ParameterKind
{

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class CommandTree
{

View File

@ -1,7 +1,7 @@
using System;
using System.Linq;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal static class CommandTreeExtensions
{

View File

@ -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);

View File

@ -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
{

View File

@ -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

View File

@ -1,4 +1,4 @@
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class CommandTreeToken
{

View File

@ -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<CommandTreeToken>
{

View File

@ -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
{

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Text;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class CommandTreeTokenizerContext
{

View File

@ -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

View File

@ -1,4 +1,4 @@
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal enum ParsingMode
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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;

View File

@ -1,6 +1,6 @@
using System;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class TypeRegistrar : ITypeRegistrarFrontend
{

View File

@ -1,6 +1,6 @@
using System;
namespace Spectre.Console.Cli.Internal
namespace Spectre.Console.Cli
{
internal sealed class TypeResolverAdapter : ITypeResolver
{

View File

@ -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)

View File

@ -1,5 +1,4 @@
using System;
using Spectre.Console.Cli.Internal;
namespace Spectre.Console.Cli
{

View File

@ -1,7 +1,6 @@
using System;
using System.Diagnostics;
using System.Globalization;
using Spectre.Console.Internal;
namespace Spectre.Console
{

View File

@ -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.
/// </remarks>
[Flags]
[SuppressMessage("Naming", "CA1714:Flags enums should have plural names")]
public enum Decoration
{
/// <summary>

View File

@ -1,6 +1,5 @@
using System;
using System.Globalization;
using Spectre.Console.Internal;
namespace Spectre.Console
{

View File

@ -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<Segment>();
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));

View File

@ -1,7 +1,7 @@
using System;
using System.Globalization;
namespace Spectre.Console.Internal
namespace Spectre.Console
{
internal static class DayOfWeekExtensions
{

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Spectre.Console.Internal
namespace Spectre.Console
{
internal static class DictionaryExtensions
{

View File

@ -2,7 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
namespace Spectre.Console.Internal
namespace Spectre.Console
{
internal static class EnumerableExtensions
{

View File

@ -1,5 +1,4 @@
using System;
using Spectre.Console.Internal;
using Spectre.Console.Rendering;
namespace Spectre.Console

View File

@ -1,6 +1,5 @@
using System;
using System.Linq;
using Spectre.Console.Internal;
using Spectre.Console.Rendering;
namespace Spectre.Console

View File

@ -1,32 +0,0 @@
using System;
using System.ComponentModel;
namespace Spectre.Console
{
/// <summary>
/// Contains extension methods for <see cref="IAlignable"/>.
/// </summary>
public static class ObsoleteAlignableExtensions
{
/// <summary>
/// Sets the alignment for an <see cref="IAlignable"/> object.
/// </summary>
/// <typeparam name="T">The alignable object type.</typeparam>
/// <param name="obj">The alignable object.</param>
/// <param name="alignment">The alignment.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Alignment(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T SetAlignment<T>(this T obj, Justify alignment)
where T : class, IAlignable
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
obj.Alignment = alignment;
return obj;
}
}
}

View File

@ -1,49 +0,0 @@
using System;
using System.ComponentModel;
namespace Spectre.Console
{
/// <summary>
/// Contains extension methods for <see cref="Calendar"/>.
/// </summary>
public static class ObsoleteCalendarExtensions
{
/// <summary>
/// Sets the calendar's highlight <see cref="Style"/>.
/// </summary>
/// <param name="calendar">The calendar.</param>
/// <param name="style">The highlight style.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[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;
}
/// <summary>
/// Sets the calendar's header <see cref="Style"/>.
/// </summary>
/// <param name="calendar">The calendar.</param>
/// <param name="style">The header style.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[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;
}
}
}

View File

@ -1,53 +0,0 @@
using System;
using System.ComponentModel;
namespace Spectre.Console
{
/// <summary>
/// Contains extension methods for <see cref="IHasBorder"/>.
/// </summary>
public static class ObsoleteHasBorderExtensions
{
/// <summary>
/// Sets the border style.
/// </summary>
/// <typeparam name="T">An object type with a border.</typeparam>
/// <param name="obj">The object to set the border color for.</param>
/// <param name="style">The border style to set.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use BorderStyle(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T SetBorderStyle<T>(this T obj, Style style)
where T : class, IHasBorder
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
obj.BorderStyle = style;
return obj;
}
/// <summary>
/// Sets the border color.
/// </summary>
/// <typeparam name="T">An object type with a border.</typeparam>
/// <param name="obj">The object to set the border color for.</param>
/// <param name="color">The border color to set.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use BorderColor(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T SetBorderColor<T>(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;
}
}
}

View File

@ -1,32 +0,0 @@
using System;
using System.ComponentModel;
namespace Spectre.Console
{
/// <summary>
/// Contains extension methods for <see cref="IHasBoxBorder"/>.
/// </summary>
public static class ObsoleteHasBoxBorderExtensions
{
/// <summary>
/// Sets the border.
/// </summary>
/// <typeparam name="T">An object type with a border.</typeparam>
/// <param name="obj">The object to set the border for.</param>
/// <param name="border">The border to use.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Border(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T SetBorder<T>(this T obj, BoxBorder border)
where T : class, IHasBoxBorder
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
obj.Border = border;
return obj;
}
}
}

View File

@ -1,80 +0,0 @@
using System;
using System.ComponentModel;
using System.Globalization;
namespace Spectre.Console
{
/// <summary>
/// Contains extension methods for <see cref="IHasCulture"/>.
/// </summary>
public static class ObsoleteHasCultureExtensions
{
/// <summary>
/// Sets the culture.
/// </summary>
/// <typeparam name="T">An object type with a culture.</typeparam>
/// <param name="obj">The object to set the culture for.</param>
/// <param name="culture">The culture to set.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Culture(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T SetCulture<T>(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;
}
/// <summary>
/// Sets the culture.
/// </summary>
/// <typeparam name="T">An object type with a culture.</typeparam>
/// <param name="obj">The object to set the culture for.</param>
/// <param name="name">The culture to set.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Culture(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T SetCulture<T>(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;
}
/// <summary>
/// Sets the culture.
/// </summary>
/// <typeparam name="T">An object type with a culture.</typeparam>
/// <param name="obj">The object to set the culture for.</param>
/// <param name="name">The culture to set.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Culture(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T SetCulture<T>(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;
}
}
}

View File

@ -1,32 +0,0 @@
using System;
using System.ComponentModel;
namespace Spectre.Console
{
/// <summary>
/// Contains extension methods for <see cref="IHasTableBorder"/>.
/// </summary>
public static class ObsoleteHasTableBorderExtensions
{
/// <summary>
/// Sets the border.
/// </summary>
/// <typeparam name="T">An object type with a border.</typeparam>
/// <param name="obj">The object to set the border for.</param>
/// <param name="border">The border to use.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Border(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T SetBorder<T>(this T obj, TableBorder border)
where T : class, IHasTableBorder
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
obj.Border = border;
return obj;
}
}
}

Some files were not shown because too many files have changed in this diff Show More