8000 Fixed CodeQL report issue by shibayan · Pull Request #233 · shibayan/Sharprompt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixed CodeQL report issue #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Sharprompt.Example/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Text;
using System.Text.Json;

using Sharprompt.Example.Models;

namespace Sharprompt.Example;

// ReSharper disable LocalizableElement
class Program
{
static void Main(string[] args)
Expand Down Expand Up @@ -65,7 +67,7 @@ private static void RunConfirmSample()
private static void RunPasswordSample()
{
var secret = Prompt.Password("Type new password", placeholder: "At least 8 characters", validators: new[] { Validators.Required(), Validators.MinLength(8) });
Console.WriteLine("Password OK");
Console.WriteLine($"Password OK, {secret}");
}

private static void RunSelectSample()
Expand Down Expand Up @@ -101,6 +103,6 @@ private static void RunListSample()
private static void RunBindSample()
{
var model = Prompt.Bind<MyFormModel>();
Console.WriteLine("Forms OK");
Console.WriteLine($"Forms OK, {JsonSerializer.Serialize(model)}");
}
}
15 changes: 7 additions & 8 deletions Sharprompt/Forms/FormBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

using Sharprompt.Drivers;
using Sharprompt.Internal;
Expand Down Expand Up @@ -57,16 +58,14 @@ public T Start()

protected bool TryValidate(object input, IList<Func<object, ValidationResult>> validators)
{
foreach (var validator in validators)
{
var result = validator(input);
var result = validators.Select(x => x(input))
.FirstOrDefault(x => x != ValidationResult.Success);

if (result != ValidationResult.Success)
{
SetError(result);
if (result is not null)
{
SetError(result);

return false;
}
return false;
}

return true;
Expand Down
27 changes: 1 addition & 26 deletions Sharprompt/Internal/OffscreenBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private class Cursor
public int Top { get; set; }
}

private class TextInfo : IEquatable<TextInfo>
private readonly struct TextInfo
{
public TextInfo(string text, ConsoleColor color)
{
Expand All @@ -125,30 +125,5 @@ public TextInfo(string text, ConsoleColor color)
public string Text { get; }
public ConsoleColor Color { get; }
public int Width { get; }

public bool Equals(TextInfo other)
{
if (other is null)
{
return false;
}

if (ReferenceEquals(this, other))
{
return true;
}

return Text == other.Text && Color == other.Color;
}

public override bool Equals(object obj) => Equals(obj as TextInfo);

public override int GetHashCode()
{
unchecked
{
return (Text.GetHashCode() * 397) ^ (int)Color;
}
}
}
}
0