using System;
using System.Collections.Generic;
using System.Globalization;
namespace Spectre.Console.Composition
{
///
/// Represents a border used by tables.
///
public abstract class Border
{
private readonly Dictionary _lookup;
private static readonly Dictionary _borders = new Dictionary
{
{ BorderKind.Ascii, new AsciiBorder() },
{ BorderKind.Square, new SquareBorder() },
};
///
/// Initializes a new instance of the class.
///
protected Border()
{
_lookup = Initialize();
}
///
/// Gets a represented by the specified .
///
/// The kind of border to get.
/// A instance representing the specified .
public static Border GetBorder(BorderKind kind)
{
if (!_borders.TryGetValue(kind, out var border))
{
throw new InvalidOperationException("Unknown border kind");
}
return border;
}
private Dictionary Initialize()
{
var lookup = new Dictionary();
foreach (BorderPart part in Enum.GetValues(typeof(BorderPart)))
{
lookup.Add(part, GetBoxPart(part));
}
return lookup;
}
///
/// Gets the string representation of a specific border part.
///
/// The part to get a string representation for.
/// The number of repetitions.
/// A string representation of the specified border part.
public string GetPart(BorderPart part, int count)
{
return new string(GetBoxPart(part), count);
}
///
/// Gets the string representation of a specific border part.
///
/// The part to get a string representation for.
/// A string representation of the specified border part.
public string GetPart(BorderPart part)
{
return _lookup[part].ToString(CultureInfo.InvariantCulture);
}
///
/// Gets the character representing the specified border part.
///
/// The part to get the character representation for.
/// A character representation of the specified border part.
protected abstract char GetBoxPart(BorderPart part);
}
}