mirror of
https://github.com/dnwSilver/tld.git
synced 2024-11-25 16:42:07 +00:00
🥅 Catch error and render.
This commit is contained in:
parent
92e3e37bd1
commit
d7d2fcd0a6
@ -18,6 +18,8 @@ public static class Symbols
|
|||||||
public const string Seo = "";
|
public const string Seo = "";
|
||||||
public const string Auth = "";
|
public const string Auth = "";
|
||||||
public const string NotFound = "";
|
public const string NotFound = "";
|
||||||
|
public const string Error = "";
|
||||||
|
public const string Download = "";
|
||||||
|
|
||||||
public static class Lines
|
public static class Lines
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using TUI.Domain;
|
using TUI.Domain;
|
||||||
|
using TUI.Engine;
|
||||||
using TUI.Engine.Attributes;
|
using TUI.Engine.Attributes;
|
||||||
using TUI.Engine.Components;
|
using TUI.Engine.Components;
|
||||||
|
using TUI.Engine.Theme;
|
||||||
|
|
||||||
namespace TUI.Controls.Components;
|
namespace TUI.Controls.Components;
|
||||||
|
|
||||||
@ -25,16 +27,18 @@ public class VersionComponent : ComponentBase
|
|||||||
{
|
{
|
||||||
var builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
|
|
||||||
// builder.Append(_type.ToString());
|
|
||||||
|
|
||||||
if (_brand is not null)
|
if (_brand is not null)
|
||||||
{
|
{
|
||||||
builder.Append(_brand.ColorLogo());
|
builder.Append(_brand.ColorLogo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
builder.Append(_type.ToImage().Warning());
|
||||||
|
builder.Append(Symbols.Space);
|
||||||
builder.Append(_version);
|
builder.Append(_version);
|
||||||
var sketch = builder.ToString();
|
var sketch = builder.ToString();
|
||||||
|
|
||||||
return new Sketch(_status.Colorize(sketch));
|
return new Sketch(_status.Colorize(sketch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
src/TUI/Controls/Components/VersionExtensions.cs
Normal file
28
src/TUI/Controls/Components/VersionExtensions.cs
Normal 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
|
||||||
|
};
|
||||||
|
}
|
@ -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
|
|
||||||
};
|
|
||||||
}
|
|
@ -16,7 +16,7 @@ public class DependenciesContainer : ContainerBase
|
|||||||
{
|
{
|
||||||
public readonly Project? Project;
|
public readonly Project? Project;
|
||||||
|
|
||||||
private const int VersionColumnWidth = 10;
|
private const int VersionColumnWidth = 11;
|
||||||
|
|
||||||
private const int TitleColumnWidth = 25;
|
private const int TitleColumnWidth = 25;
|
||||||
|
|
||||||
@ -70,6 +70,22 @@ public class DependenciesContainer : ContainerBase
|
|||||||
_dependencies.Add(stub);
|
_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)
|
public void AddDependency(Dependency dependency, VersionStatus status = VersionStatus.BeNice)
|
||||||
{
|
{
|
||||||
var version = new VersionComponent(dependency.Version, dependency.Brand, status, dependency.Type);
|
var version = new VersionComponent(dependency.Version, dependency.Brand, status, dependency.Type);
|
||||||
|
@ -62,20 +62,27 @@ public class DependenciesPage : PageBase
|
|||||||
var project = projectDependencies.Project;
|
var project = projectDependencies.Project;
|
||||||
var actualDependencies = _store.ActualDependencies(project).ToArray();
|
var actualDependencies = _store.ActualDependencies(project).ToArray();
|
||||||
|
|
||||||
foreach (var conventionDependency in _store.ConventionDependencies)
|
if (!actualDependencies.Any())
|
||||||
{
|
{
|
||||||
var actualDependency = actualDependencies.SingleOrDefault(
|
projectDependencies.AddError();
|
||||||
dependency => string.Equals(dependency.Brand.Name, conventionDependency.Brand.Name,
|
}
|
||||||
StringComparison.CurrentCultureIgnoreCase));
|
else
|
||||||
|
{
|
||||||
if (actualDependency is null)
|
foreach (var conventionDependency in _store.ConventionDependencies)
|
||||||
{
|
{
|
||||||
projectDependencies.AddDependencyStub();
|
var actualDependency = actualDependencies.SingleOrDefault(
|
||||||
continue;
|
dependency => string.Equals(dependency.Brand.Name, conventionDependency.Brand.Name,
|
||||||
}
|
StringComparison.CurrentCultureIgnoreCase));
|
||||||
|
|
||||||
var versionType = actualDependency.Comparison(conventionDependency);
|
if (actualDependency is null)
|
||||||
projectDependencies.AddDependency(actualDependency, versionType);
|
{
|
||||||
|
projectDependencies.AddDependencyStub();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var versionType = actualDependency.Comparison(conventionDependency);
|
||||||
|
projectDependencies.AddDependency(actualDependency, versionType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Render();
|
Render();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using TUI.Controls.Components;
|
using TUI.Controls.Components;
|
||||||
using TUI.Domain;
|
using TUI.Domain;
|
||||||
|
using TUI.Engine;
|
||||||
using TUI.Engine.Theme;
|
using TUI.Engine.Theme;
|
||||||
using TUI.Providers.Dependencies;
|
using TUI.Providers.Dependencies;
|
||||||
|
|
||||||
@ -15,14 +16,15 @@ public class DependenciesStore
|
|||||||
|
|
||||||
public IEnumerable<Dependency> ActualDependencies(Project project)
|
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
|
try
|
||||||
{
|
{
|
||||||
return Repository.ReadActual(project);
|
return Repository.ReadActual(project);
|
||||||
}
|
}
|
||||||
catch
|
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>();
|
return new List<Dependency>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user