Skip to content

Commit

Permalink
Merge pull request #2 from ChrisPulman/SetupBuild
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman authored Aug 27, 2023
2 parents 5cdf7d3 + 37c6e38 commit bd18450
Show file tree
Hide file tree
Showing 29 changed files with 150 additions and 128 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<LangVersion>preview</LangVersion>
<Configuration>$(TargetFramework)</Configuration>
<Company>ChrisPulman</Company>
<NoWarn>CS1591;IDE0190;IDE1006</NoWarn>
<NoWarn>CS1591;IDE0190;IDE1006;RCS1198</NoWarn>
<Nullable>enable</Nullable>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
11 changes: 1 addition & 10 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
InvokedTargets = new[] { nameof(Compile), nameof(Deploy) })]
partial class Build : NukeBuild
{
//// Support plugins are available for:
//// - JetBrains ReSharper https://nuke.build/resharper
//// - JetBrains Rider https://nuke.build/rider
//// - Microsoft VisualStudio https://nuke.build/visualstudio
//// - Microsoft VSCode https://nuke.build/vscode

public static int Main() => Execute<Build>(x => x.Compile);

[GitRepository] readonly GitRepository Repository;
Expand Down Expand Up @@ -61,10 +55,7 @@ partial class Build : NukeBuild

Target Restore => _ => _
.DependsOn(Clean)
.Executes(() =>
{
DotNetRestore(s => s.SetProjectFile(Solution));
});
.Executes(() => DotNetRestore(s => s.SetProjectFile(Solution)));

Target Compile => _ => _
.DependsOn(Restore, Print)
Expand Down
1 change: 1 addition & 0 deletions src/CombinedExample/CombinedExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>False</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions src/LiveTableExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public static class Program
/// <summary>
/// Defines the entry point of the application.
/// </summary>
/// <param name="args">The arguments.</param>
public static void Main(string[] args)
public static void Main()
{
var table = new Table().Expand().BorderColor(Color.Grey);
table.AddColumn("[yellow]Source currency[/]");
Expand Down
14 changes: 5 additions & 9 deletions src/ProgressExample/DescriptionGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@ static DescriptionGenerator()
/// <returns>A bool.</returns>
public static bool TryGenerate(out string name)
{
var iterations = 0;
while (iterations < 25)
for (var iterations = 0; iterations < 25; iterations++)
{
name = Generate();
if (!_used.Contains(name))
{
_used.Add(name);
return true;
}

iterations++;
}

name = Generate();
Expand All @@ -51,9 +48,8 @@ public static bool TryGenerate(out string name)
/// Generates this instance.
/// </summary>
/// <returns>A string.</returns>
public static string Generate()
{
return _verbs[_random.Next(0, _verbs.Length)]
+ " " + _nouns[_random.Next(0, _nouns.Length)];
}
public static string Generate() =>
_verbs[_random.Next(0, _verbs.Length)]
+ " "
+ _nouns[_random.Next(0, _nouns.Length)];
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public T Receive()
/// <param name="cancellationToken">A cancellation token.</param>
/// <returns>The received message.</returns>
/// <exception cref="OperationCanceledException">The operation was cancelled.</exception>
[SuppressMessage("Roslynator", "RCS1231:Make parameter ref read-only.", Justification = "Netstandard does not support")]
public T Receive(CancellationToken cancellationToken)
{
_sync.Wait(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public override void Send(SendOrPostCallback d, object? state)
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="OperationCanceledException">The operation was canceled.</exception>
[SuppressMessage("Roslynator", "RCS1231:Make parameter ref read-only.", Justification = "Netstandard does not support")]
public void Start(CancellationToken cancellationToken)
{
Message msg;
Expand Down
2 changes: 2 additions & 0 deletions src/Spectre.Console.Rx/Spectre.Console/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ public override readonly int GetHashCode()
return hash;
}
#else
#pragma warning disable IDE0022 // Use expression body for method
return HashCode.Combine(R, G, B);
#pragma warning restore IDE0022 // Use expression body for method
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion src/Spectre.Console.Rx/Spectre.Console/Emoji.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static void Remap(string tag, string emoji)
/// </summary>
/// <param name="value">A string with emojis codes, e.g. "Hello :smiley:!".</param>
/// <returns>A string with emoji codes replaced with actual emoji.</returns>
[SuppressMessage("Roslynator", "RCS1231:Make parameter ref read-only.", Justification = "Netstandard does not suppport")]
public static string Replace(ReadOnlySpan<char> value)
{
var output = new StringBuilder();
Expand Down Expand Up @@ -110,7 +111,7 @@ private static bool TryGetEmoji(string emoji, out string value)
return false;
}

private static int IndexOf(this ReadOnlySpan<char> span, char value, int startIndex)
private static int IndexOf(this in ReadOnlySpan<char> span, char value, int startIndex)
{
var indexInSlice = span.Slice(startIndex).IndexOf(value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public static T Prompt<T>(this IAnsiConsole console, IPrompt<T> prompt)
/// <returns>The prompt input result.</returns>
public static T Ask<T>(this IAnsiConsole console, string prompt, CultureInfo? culture)
{
var textPrompt = new TextPrompt<T>(prompt);
textPrompt.Culture = culture;
var textPrompt = new TextPrompt<T>(prompt)
{
Culture = culture
};
return textPrompt.Show(console);
}

Expand All @@ -61,4 +63,4 @@ public static T Ask<T>(this IAnsiConsole console, string prompt, CultureInfo? cu
DefaultValue = defaultValue,
}
.Show(console);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public static class CalendarExtensions
/// <param name="calendar">The calendar to add the calendar event to.</param>
/// <param name="date">The calendar event date.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
#if NET6_0_OR_GREATER
[SuppressMessage("Roslynator", "RCS1231:Make parameter ref read-only.", Justification = "Netstandard does not support")]
#endif
public static Calendar AddCalendarEvent(this Calendar calendar, DateTime date) => AddCalendarEvent(calendar, string.Empty, date.Year, date.Month, date.Day);

/// <summary>
Expand All @@ -23,6 +26,9 @@ public static class CalendarExtensions
/// <param name="description">The calendar event description.</param>
/// <param name="date">The calendar event date.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
#if NET6_0_OR_GREATER
[SuppressMessage("Roslynator", "RCS1231:Make parameter ref read-only.", Justification = "Netstandard does not support")]
#endif
public static Calendar AddCalendarEvent(this Calendar calendar, string description, DateTime date) => AddCalendarEvent(calendar, description, date.Year, date.Month, date.Day);

/// <summary>
Expand Down Expand Up @@ -120,4 +126,4 @@ public static Calendar HideHeader(this Calendar calendar)
calendar.ShowHeader = false;
return calendar;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static T Padding<T>(this T obj, int horizontal, int vertical)
/// <param name="obj">The paddable object instance.</param>
/// <param name="padding">The padding to apply.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static T Padding<T>(this T obj, Padding padding)
public static T Padding<T>(this T obj, in Padding padding)
where T : class, IPaddable
{
if (obj is null)
Expand All @@ -122,4 +122,4 @@ public static T Padding<T>(this T obj, Padding padding)
obj.Padding = padding;
return obj;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static StringBuilder AppendWithStyle(this StringBuilder builder, Style? s
return builder.Append(value);
}

public static void AppendSpan(this StringBuilder builder, ReadOnlySpan<char> span) =>
public static void AppendSpan(this StringBuilder builder, in ReadOnlySpan<char> span) =>

// NetStandard 2 lacks the override for StringBuilder to add the span. We'll need to convert the span
// to a string for it, but for .NET 6.0 or newer we'll use the override.
Expand Down
13 changes: 6 additions & 7 deletions src/Spectre.Console.Rx/Spectre.Console/Live/LiveRenderable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ internal sealed class LiveRenderable(IAnsiConsole console) : Renderable
{
private readonly object _lock = new();
private readonly IAnsiConsole _console = console ?? throw new ArgumentNullException(nameof(console));
private IRenderable? _renderable;
private SegmentShape? _shape;

public LiveRenderable(IAnsiConsole console, IRenderable renderable)
: this(console) => _renderable = renderable ?? throw new ArgumentNullException(nameof(renderable));
: this(console) => Target = renderable ?? throw new ArgumentNullException(nameof(renderable));

public IRenderable? Target => _renderable;
public IRenderable? Target { get; private set; }

public bool DidOverflow { get; private set; }

[MemberNotNullWhen(true, nameof(Target))]
public bool HasRenderable => _renderable != null;
public bool HasRenderable => Target != null;

public VerticalOverflow Overflow { get; set; } = VerticalOverflow.Ellipsis;

Expand All @@ -30,7 +29,7 @@ public void SetRenderable(IRenderable? renderable)
{
lock (_lock)
{
_renderable = renderable;
Target = renderable;
}
}

Expand Down Expand Up @@ -68,9 +67,9 @@ protected override IEnumerable<Segment> Render(RenderOptions options, int maxWid
{
DidOverflow = false;

if (_renderable != null)
if (Target != null)
{
var segments = _renderable.Render(options, maxWidth);
var segments = Target.Render(options, maxWidth);
var lines = Segment.SplitLines(segments);

var shape = SegmentShape.Calculate(options, lines);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public T Get<T>(string key)
return default;
}

if (!(value is T))
if (value is not T)
{
throw new InvalidOperationException("State value is of the wrong type.");
}
Expand Down Expand Up @@ -65,7 +65,7 @@ public T Update<T>(string key, Func<T, T> func)
var old = default(T);
if (_state.TryGetValue(key, out var value))
{
if (!(value is T))
if (value is not T)
{
throw new InvalidOperationException("State value is of the wrong type.");
}
Expand All @@ -77,4 +77,4 @@ public T Update<T>(string key, Func<T, T> func)
return (T)_state[key];
}
}
}
}
10 changes: 8 additions & 2 deletions src/Spectre.Console.Rx/Spectre.Console/Padding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,23 @@ public Padding(int horizontal, int vertical)
/// <param name="left">The first <see cref="Padding"/> instance to compare.</param>
/// <param name="right">The second <see cref="Padding"/> instance to compare.</param>
/// <returns><c>true</c> if the two instances are equal, otherwise <c>false</c>.</returns>
public static bool operator ==(Padding left, Padding right) => left.Equals(right);
public static bool operator ==(in Padding left, in Padding right) => left.Equals(right);

/// <summary>
/// Checks if two <see cref="Padding"/> instances are not equal.
/// </summary>
/// <param name="left">The first <see cref="Padding"/> instance to compare.</param>
/// <param name="right">The second <see cref="Padding"/> instance to compare.</param>
/// <returns><c>true</c> if the two instances are not equal, otherwise <c>false</c>.</returns>
public static bool operator !=(Padding left, Padding right) => !(left == right);
public static bool operator !=(in Padding left, in Padding right) => !(left == right);

/// <inheritdoc/>
public override bool Equals(object? obj) => obj is Padding padding && Equals(padding);

/// <inheritdoc/>
public override int GetHashCode()
{
#if NETSTANDARD2_0
unchecked
{
var hash = (int)2166136261;
Expand All @@ -85,6 +86,11 @@ public override int GetHashCode()
hash = (hash * 16777619) ^ Bottom.GetHashCode();
return hash;
}
#else
#pragma warning disable IDE0022 // Use expression body for method
return HashCode.Combine(Left, Top, Right, Bottom);
#pragma warning restore IDE0022 // Use expression body for method
#endif
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace Spectre.Console.Rx;
public sealed class MultiSelectionPrompt<T>(IEqualityComparer<T>? comparer = null) : IPrompt<List<T>>, IListPromptStrategy<T>
where T : notnull
{

/// <summary>
/// Gets or sets the title.
/// </summary>
Expand Down Expand Up @@ -224,22 +223,22 @@ IRenderable IListPromptStrategy<T>.Render(IAnsiConsole console, bool scrollable,
grid.AddEmptyRow();
}

foreach (var item in items)
foreach (var (index, node) in items)
{
var current = item.Index == cursorIndex;
var current = index == cursorIndex;
var style = current ? highlightStyle : Style.Plain;

var indent = new string(' ', item.Node.Depth * 2);
var prompt = item.Index == cursorIndex ? ListPromptConstants.Arrow : new string(' ', ListPromptConstants.Arrow.Length);
var indent = new string(' ', node.Depth * 2);
var prompt = index == cursorIndex ? ListPromptConstants.Arrow : new string(' ', ListPromptConstants.Arrow.Length);

var text = (Converter ?? TypeConverterHelper.ConvertToString)?.Invoke(item.Node.Data) ?? item.Node.Data.ToString() ?? "?";
var text = (Converter ?? TypeConverterHelper.ConvertToString)?.Invoke(node.Data) ?? node.Data.ToString() ?? "?";
if (current)
{
text = text.RemoveMarkup().EscapeMarkup();
}

var checkbox = item.Node.IsSelected
? (item.Node.IsGroup && Mode == SelectionMode.Leaf
var checkbox = node.IsSelected
? (node.IsGroup && Mode == SelectionMode.Leaf
? ListPromptConstants.GroupSelectedCheckbox : ListPromptConstants.SelectedCheckbox)
: ListPromptConstants.Checkbox;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,17 @@ IRenderable IListPromptStrategy<T>.Render(IAnsiConsole console, bool scrollable,
grid.AddEmptyRow();
}

foreach (var item in items)
foreach (var (index, node) in items)
{
var current = item.Index == cursorIndex;
var prompt = item.Index == cursorIndex ? ListPromptConstants.Arrow : new string(' ', ListPromptConstants.Arrow.Length);
var style = item.Node.IsGroup && Mode == SelectionMode.Leaf
var current = index == cursorIndex;
var prompt = index == cursorIndex ? ListPromptConstants.Arrow : new string(' ', ListPromptConstants.Arrow.Length);
var style = node.IsGroup && Mode == SelectionMode.Leaf
? disabledStyle
: current ? highlightStyle : Style.Plain;

var indent = new string(' ', item.Node.Depth * 2);
var indent = new string(' ', node.Depth * 2);

var text = (Converter ?? TypeConverterHelper.ConvertToString)?.Invoke(item.Node.Data) ?? item.Node.Data.ToString() ?? "?";
var text = (Converter ?? TypeConverterHelper.ConvertToString)?.Invoke(node.Data) ?? node.Data.ToString() ?? "?";
if (current)
{
text = text.RemoveMarkup().EscapeMarkup();
Expand Down
6 changes: 1 addition & 5 deletions src/Spectre.Console.Rx/Spectre.Console/Recorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public class Recorder(IAnsiConsole console) : IAnsiConsole
/// <inheritdoc/>
[SuppressMessage("Usage", "CA1816:Dispose methods should call SuppressFinalize", Justification = "Only used for scoping")]
[SuppressMessage("Design", "CA1063:Implement IDisposable Correctly", Justification = "Only used for scoping")]
public void Dispose()
{
// Only used for scoping.
_console.Dispose();
}
public void Dispose() => _console.Dispose(); // Only used for scoping.

/// <inheritdoc/>
public void Clear(bool home) => _console.Clear(home);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IAnsiConsoleEncoder
/// Encodes the specified <see cref="IRenderable"/> enumerator.
/// </summary>
/// <param name="console">The console to use when encoding.</param>
/// <param name="renderable">The renderable objects to encode.</param>
/// <param name="renderables">The renderable objects to encode.</param>
/// <returns>A string representing the encoded result.</returns>
string Encode(IAnsiConsole console, IEnumerable<IRenderable> renderable);
}
string Encode(IAnsiConsole console, IEnumerable<IRenderable> renderables);
}
Loading

0 comments on commit bd18450

Please sign in to comment.