Add calendar control

Closes #101
This commit is contained in:
Patrik Svensson
2020-10-16 16:43:33 +02:00
committed by Patrik Svensson
parent 0a0380ae0a
commit 3f2ca49071
14 changed files with 833 additions and 1 deletions

View File

@ -0,0 +1,88 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Spectre.Console.Internal.Collections
{
internal sealed class ListWithCallback<T> : IList<T>
{
private readonly List<T> _list;
private readonly Action _callback;
public T this[int index]
{
get => _list[index];
set => _list[index] = value;
}
public int Count => _list.Count;
public bool IsReadOnly => false;
public ListWithCallback(Action callback)
{
_list = new List<T>();
_callback = callback ?? throw new ArgumentNullException(nameof(callback));
}
public void Add(T item)
{
_list.Add(item);
_callback();
}
public void Clear()
{
_list.Clear();
_callback();
}
public bool Contains(T item)
{
return _list.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
_list.CopyTo(array, arrayIndex);
_callback();
}
public IEnumerator<T> GetEnumerator()
{
return _list.GetEnumerator();
}
public int IndexOf(T item)
{
return _list.IndexOf(item);
}
public void Insert(int index, T item)
{
_list.Insert(index, item);
_callback();
}
public bool Remove(T item)
{
var result = _list.Remove(item);
if (result)
{
_callback();
}
return result;
}
public void RemoveAt(int index)
{
_list.RemoveAt(index);
_callback();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Globalization;
namespace Spectre.Console.Internal
{
internal static class DayOfWeekExtensions
{
public static string GetAbbreviatedDayName(this DayOfWeek day, CultureInfo culture)
{
culture ??= CultureInfo.InvariantCulture;
var name = culture.DateTimeFormat.GetAbbreviatedDayName(day);
if (name.Length > 0 && char.IsLower(name[0]))
{
name = string.Format(culture, "{0}{1}", char.ToUpper(name[0], culture), name.Substring(1));
}
return name;
}
public static DayOfWeek GetNextWeekDay(this DayOfWeek day)
{
var next = (int)day + 1;
if (next > (int)DayOfWeek.Saturday)
{
return DayOfWeek.Sunday;
}
return (DayOfWeek)next;
}
}
}