🥅 Catch error and render.

This commit is contained in:
Kolosov Alexandr 2024-06-14 16:45:30 +05:00
parent 92e3e37bd1
commit d7d2fcd0a6
8 changed files with 76 additions and 33 deletions

View File

@ -18,6 +18,8 @@ public static class Symbols
public const string Seo = "󰚩";
public const string Auth = "";
public const string NotFound = "";
public const string Error = "";
public const string Download = "";
public static class Lines
{

View File

@ -1,7 +1,9 @@
using System.Text;
using TUI.Domain;
using TUI.Engine;
using TUI.Engine.Attributes;
using TUI.Engine.Components;
using TUI.Engine.Theme;
namespace TUI.Controls.Components;
@ -25,16 +27,18 @@ public class VersionComponent : ComponentBase
{
var builder = new StringBuilder();
// builder.Append(_type.ToString());
if (_brand is not null)
{
builder.Append(_brand.ColorLogo());
}
builder.Append(_type.ToImage().Warning());
builder.Append(Symbols.Space);
builder.Append(_version);
var sketch = builder.ToString();
return new Sketch(_status.Colorize(sketch));
}
}
}

View File

@ -0,0 +1,28 @@
using TUI.Engine.Theme;
namespace TUI.Controls.Components;
public static class VersionExtensions
{
public static string ToImage(this VersionType versionType)
=>
versionType switch
{
VersionType.Alpha => "󰀫",
VersionType.Beta => "󰂡",
VersionType.Candidate => "󰑣",
VersionType.Canary => "󱗆",
VersionType.Next => "󰒭",
_ => ""
};
public static string Colorize(this VersionStatus versionStatus, string value) =>
versionStatus switch
{
VersionStatus.TooOld => value.Warning(),
VersionStatus.ToNew => value.Info(),
VersionStatus.SoGood => value.Hint(),
VersionStatus.BeNice => value.Main(),
_ => value
};
}

View File

@ -9,4 +9,4 @@ public enum VersionType
Alpha,
Beta,
Next,
}
}

View File

@ -1,16 +0,0 @@
using TUI.Engine.Theme;
namespace TUI.Controls.Components;
public static class VersionTypeExtensions
{
public static string Colorize(this VersionStatus versionStatus, string value) =>
versionStatus switch
{
VersionStatus.TooOld => value.Warning(),
VersionStatus.ToNew => value.Info(),
VersionStatus.SoGood => value.Hint(),
VersionStatus.BeNice => value.Main(),
_ => value
};
}

View File

@ -16,7 +16,7 @@ public class DependenciesContainer : ContainerBase
{
public readonly Project? Project;
private const int VersionColumnWidth = 10;
private const int VersionColumnWidth = 11;
private const int TitleColumnWidth = 25;
@ -70,6 +70,22 @@ public class DependenciesContainer : ContainerBase
_dependencies.Add(stub);
}
public void AddError()
{
var size = new Size(25, 1);
var stub = new StubComponent(size, (Symbols.Error + Symbols.Space + " Something went wrong").Error());
stub.SetPadding(Level.Normal);
stub.SetAlignment(Horizontal.Right);
stub.SetFixed(Orientation.Horizontal, 25);
if (Project is not null && Project.Legacy)
{
stub.StyleContext = new StyleContext(Palette.DisableColor);
}
_dependencies.Add(stub);
}
public void AddDependency(Dependency dependency, VersionStatus status = VersionStatus.BeNice)
{
var version = new VersionComponent(dependency.Version, dependency.Brand, status, dependency.Type);

View File

@ -62,20 +62,27 @@ public class DependenciesPage : PageBase
var project = projectDependencies.Project;
var actualDependencies = _store.ActualDependencies(project).ToArray();
foreach (var conventionDependency in _store.ConventionDependencies)
if (!actualDependencies.Any())
{
var actualDependency = actualDependencies.SingleOrDefault(
dependency => string.Equals(dependency.Brand.Name, conventionDependency.Brand.Name,
StringComparison.CurrentCultureIgnoreCase));
if (actualDependency is null)
projectDependencies.AddError();
}
else
{
foreach (var conventionDependency in _store.ConventionDependencies)
{
projectDependencies.AddDependencyStub();
continue;
var actualDependency = actualDependencies.SingleOrDefault(
dependency => string.Equals(dependency.Brand.Name, conventionDependency.Brand.Name,
StringComparison.CurrentCultureIgnoreCase));
if (actualDependency is null)
{
projectDependencies.AddDependencyStub();
continue;
}
var versionType = actualDependency.Comparison(conventionDependency);
projectDependencies.AddDependency(actualDependency, versionType);
}
var versionType = actualDependency.Comparison(conventionDependency);
projectDependencies.AddDependency(actualDependency, versionType);
}
Render();

View File

@ -1,5 +1,6 @@
using TUI.Controls.Components;
using TUI.Domain;
using TUI.Engine;
using TUI.Engine.Theme;
using TUI.Providers.Dependencies;
@ -15,14 +16,15 @@ public class DependenciesStore
public IEnumerable<Dependency> ActualDependencies(Project project)
{
SpeakerComponent.Instance.Shout("", $"Fetch actual dependencies for project {project.Name.Main()}");
SpeakerComponent.Instance.Shout(Symbols.Download.Info(), $"Fetch actual dependencies for project {project.Name.Main
()}");
try
{
return Repository.ReadActual(project);
}
catch
{
SpeakerComponent.Instance.Shout("", $"Fetch failed for project{project.Name}");
SpeakerComponent.Instance.Shout(Symbols.Error.Error(), $"Fetch failed for project{project.Name}");
return new List<Dependency>();
}
}