Skip to content

Commit 8d23503

Browse files
committed
*
1 parent 10ee92d commit 8d23503

File tree

10 files changed

+215
-164
lines changed

10 files changed

+215
-164
lines changed

SmartImage.Lib 3/Engines/Impl/Search/SauceNaoEngine.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
130130
goto ret;
131131

132132
}
133-
else {
134-
result.Status = SearchResultStatus.Success;
135133

136-
// TODO: HACK
134+
result.Status = SearchResultStatus.Success;
137135

138-
/*var allSisters = imageResults
136+
// TODO: HACK
137+
138+
/*var allSisters = imageResults
139139
.SelectMany(ir => ir.Children)
140140
.DistinctBy(s => s.Url)
141141
.ToList(); // note: need ToList()
@@ -146,8 +146,6 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
146146
ir.Children.AddRange(allSisters.Where(irs => irs.Parent == ir));
147147
}*/
148148

149-
}
150-
151149
result.Results.AddRange(imageResults);
152150

153151
// result.Results[0] = (imageResults.First());
@@ -370,7 +368,6 @@ private static SauceNaoDataResult Parse(INode result)
370368
sndr.Creator = nodes[++i].TextContent.Trim(' ');
371369

372370
// var idx = Array.IndexOf(sndr.Urls, nodes[i].TryGetAttribute(Serialization.Atr_href));
373-
continue;
374371
}
375372

376373
}
@@ -514,8 +511,8 @@ public SearchResultItem Convert(SearchResult r, out SearchResultItem[] children)
514511
var idxStr = Index.ToString();
515512
string siteName = Index != 0 ? idxStr : null;
516513

517-
var site = Kantan.Text.Strings.NormalizeNull(siteName);
518-
var title = Kantan.Text.Strings.NormalizeNull(WebsiteTitle);
514+
var site = Strings.NormalizeNull(siteName);
515+
var title = Strings.NormalizeNull(WebsiteTitle);
519516

520517
var sb = new StringBuilder();
521518

@@ -552,11 +549,11 @@ public SearchResultItem Convert(SearchResult r, out SearchResultItem[] children)
552549

553550
// Similarity = Similarity,
554551
Description = siteName,
555-
Artist = Kantan.Text.Strings.NormalizeNull(Creator),
556-
Source = Kantan.Text.Strings.NormalizeNull(Material),
557-
Character = Kantan.Text.Strings.NormalizeNull(Character),
552+
Artist = Strings.NormalizeNull(Creator),
553+
Source = Strings.NormalizeNull(Material),
554+
Character = Strings.NormalizeNull(Character),
558555
Site = site,
559-
Title = Kantan.Text.Strings.NormalizeNull(Title),
556+
Title = Strings.NormalizeNull(Title),
560557
Metadata = meta,
561558
Thumbnail = Thumbnail,
562559
ThumbnailTitle = ThumbnailTitle

SmartImage.Lib 3/SearchConfig.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace SmartImage.Lib;
1313

14-
public sealed class SearchConfig : IDataTable, INotifyPropertyChanged
14+
public sealed class SearchConfig : INotifyPropertyChanged
1515
{
1616
#region Defaults
1717

@@ -205,7 +205,7 @@ public void Save()
205205
Debug.WriteLine($"Saved to {Configuration.FilePath}", nameof(Save));
206206
}
207207

208-
public DataTable ToTable()
208+
/*public DataTable ToTable()
209209
{
210210
var table = new DataTable("Configuration");
211211
@@ -225,12 +225,12 @@ public DataTable ToTable()
225225
table.Rows.Add(Resources.S_AutoSearch, AutoSearch);
226226
table.Rows.Add(Resources.S_SauceNaoKey, SauceNaoKey);
227227
/*table.Rows.Add(Resources.S_HydrusEndpoint, HydrusEndpoint);
228-
table.Rows.Add(Resources.S_HydrusKey, HydrusKey);*/
228+
table.Rows.Add(Resources.S_HydrusKey, HydrusKey);#1#
229229
230230
// table.Rows.Add("Path", new FileInfo(Configuration.FilePath).Name);
231231
232232
return table;
233-
}
233+
}*/
234234

235235
public event PropertyChangedEventHandler PropertyChanged;
236236

SmartImage.Lib 3/SearchQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public long Size
5959
[MNNW(true, nameof(Uni))]
6060
public bool HasUni => Uni != null;
6161

62-
internal SearchQuery([CBN] UniSource f)
62+
internal SearchQuery([MN] UniSource f)
6363
{
6464
Uni = f;
6565

SmartImage.Rdx/Cli/CliFormat.Elements.cs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Deci SmartImage.Rdx CliFormat.Elements.cs
22
// $File.CreatedYear-$File.CreatedMonth-26 @ 1:25
33

4-
using System.Collections.ObjectModel;
54
using SmartImage.Lib.Engines;
65
using Spectre.Console;
76

@@ -12,22 +11,22 @@ internal static partial class CliFormat
1211

1312
// Ideally a dictionary would be used here...
1413

15-
internal static readonly Style s_styleName = new(decoration: Decoration.Italic);
14+
internal static readonly Style Sty_Name = new(decoration: Decoration.Italic);
1615

17-
internal static readonly Style s_styleSim = new(Color.Wheat1, decoration: Decoration.None);
16+
internal static readonly Style Sty_Sim = new(Color.Wheat1, decoration: Decoration.None);
1817

19-
internal static readonly Style s_styleUrl = new(Color.Cyan1, decoration: Decoration.None);
18+
internal static readonly Style Sty_Url = new(Color.Cyan1, decoration: Decoration.None);
2019

21-
public static readonly Color Color1 = new(0x80, 0xFF, 0x80);
20+
public static readonly Color Clr_Misc1 = new(0x80, 0xFF, 0x80);
2221

23-
internal static readonly Text EmptyText = new(string.Empty);
22+
internal static readonly Text Txt_Empty = new(string.Empty);
2423

2524
internal const string STR_DEFAULT = "-";
2625

2726
static CliFormat() { }
2827

2928
internal static readonly IReadOnlyDictionary<SearchEngineOptions, Color> EngineColors =
30-
new Dictionary<SearchEngineOptions, Color>()
29+
new Dictionary<SearchEngineOptions, Color>
3130
{
3231
{ SearchEngineOptions.SauceNao, Color.Green },
3332
{ SearchEngineOptions.EHentai, Color.Purple },
@@ -43,4 +42,24 @@ static CliFormat() { }
4342

4443
internal static readonly Capabilities ProfileCapabilities = AConsole.Profile.Capabilities;
4544

45+
internal static readonly bool IsLinux = OperatingSystem.IsLinux();
46+
internal static readonly bool IsWindows = OperatingSystem.IsWindows();
47+
internal static readonly bool IsMacOs = OperatingSystem.IsMacOS();
48+
49+
public static Grid CreateInfoGrid()
50+
{
51+
var grd = new Grid();
52+
grd.AddColumns(2);
53+
54+
grd.AddRow("OS", $"{GetOS()} / {Environment.OSVersion}");
55+
grd.AddRow("Runtime", $"{Environment.Version}");
56+
57+
grd.AddRow("Terminal ANSI", $"{ProfileCapabilities.Ansi}");
58+
grd.AddRow("Terminal colors", $"{ProfileCapabilities.ColorSystem}");
59+
grd.AddRow("Terminal links", $"{ProfileCapabilities.Links}");
60+
grd.AddRow("Terminal Unicode", $"{ProfileCapabilities.Unicode}");
61+
62+
return grd;
63+
}
64+
4665
}

SmartImage.Rdx/Cli/CliFormat.cs

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
using Flurl;
55
using Kantan.Utilities;
66
using SmartImage.Lib.Engines;
7-
using SmartImage.Lib.Results;
87
using Spectre.Console;
8+
using Spectre.Console.Cli;
99
using Spectre.Console.Rendering;
1010

1111
// $User.Name $File.ProjectName $File.FileName
@@ -14,7 +14,7 @@
1414
namespace SmartImage.Rdx.Cli;
1515

1616
[Flags]
17-
internal enum ResultTableFormat
17+
internal enum ResultShellFormat
1818
{
1919

2020
None = 0,
@@ -31,14 +31,7 @@ internal enum ResultFileFormat
3131
{
3232

3333
None = 0,
34-
Csv,
35-
36-
}
37-
38-
public abstract class Formatter
39-
{
40-
41-
public abstract IRenderable Format(SearchResult s);
34+
Delimited,
4235

4336
}
4437

@@ -60,7 +53,28 @@ public static FigletFont LoadFigletFontFromResource(string name, out MemoryStrea
6053
return ff;
6154
}
6255

63-
public static Table GetTableForFormat(ResultTableFormat format)
56+
public static void Dump(CommandSettings settings)
57+
{
58+
var table = new Table().RoundedBorder();
59+
table.AddColumn("[grey]Name[/]");
60+
table.AddColumn("[grey]Value[/]");
61+
62+
var properties = settings.GetType().GetProperties();
63+
64+
foreach (var property in properties) {
65+
var value = property.GetValue(settings)
66+
?.ToString()
67+
?.Replace("[", "[[");
68+
69+
table.AddRow(
70+
property.Name,
71+
value ?? "[grey]null[/]");
72+
}
73+
74+
AnsiConsole.Write(table);
75+
}
76+
77+
public static Table GetTableForFormat(ResultShellFormat format)
6478
{
6579

6680
var fmt = format.GetSetFlags(true, true);
@@ -103,7 +117,7 @@ public static STable DTableToSTable(DTable dt)
103117
}
104118

105119
if (x == null) {
106-
return EmptyText;
120+
return Txt_Empty;
107121
}
108122

109123
return new Text(x.ToString());
@@ -115,4 +129,22 @@ public static STable DTableToSTable(DTable dt)
115129
return t;
116130
}
117131

132+
internal static string? GetOS()
133+
{
134+
string? os = null;
135+
136+
if (IsLinux) {
137+
os = "Linux";
138+
139+
}
140+
else if (IsWindows) {
141+
os = "Windows";
142+
}
143+
else if (IsMacOs) {
144+
os = "Mac";
145+
}
146+
147+
return os;
148+
}
149+
118150
}

SmartImage.Rdx/Program.cs

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ namespace SmartImage.Rdx;
2424
public static class Program
2525
{
2626

27-
internal static readonly bool IsLinux = OperatingSystem.IsLinux();
28-
internal static readonly bool IsWindows = OperatingSystem.IsWindows();
29-
internal static readonly bool IsMacOs = OperatingSystem.IsMacOS();
30-
3127
public static async Task<int> Main(string[] args)
3228
{
3329
Debug.WriteLine(AConsole.Profile.Height);
@@ -39,63 +35,34 @@ public static async Task<int> Main(string[] args)
3935

4036
var fg = new FigletText(ff, R1.Name)
4137
.LeftJustified()
42-
.Color(CliFormat.Color1);
38+
.Color(CliFormat.Clr_Misc1);
4339

4440
AConsole.Write(fg);
4541

4642
#if DEBUG
4743
AConsole.WriteLine(args.QuickJoin());
4844

4945
#endif
50-
string? os = null;
51-
52-
if (IsLinux) {
53-
os = "Linux";
54-
55-
}
56-
else if (IsWindows) {
57-
os = "Windows";
58-
}
59-
else if (IsMacOs) {
60-
os = "Mac";
61-
}
62-
63-
var grd = new Grid();
64-
grd.AddColumns(2);
6546

66-
grd.AddRow("OS", $"{os} / {Environment.OSVersion}");
67-
grd.AddRow("Runtime", $"{Environment.Version}");
68-
69-
grd.AddRow("Terminal ANSI", $"{CliFormat.ProfileCapabilities.Ansi}");
70-
grd.AddRow("Terminal colors", $"{CliFormat.ProfileCapabilities.ColorSystem}");
71-
grd.AddRow("Terminal links", $"{CliFormat.ProfileCapabilities.Links}");
72-
grd.AddRow("Terminal Unicode", $"{CliFormat.ProfileCapabilities.Unicode}");
73-
74-
var env = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process);
47+
Grid grd = CliFormat.CreateInfoGrid();
7548

7649
AConsole.Write(grd);
7750

51+
// var env = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process);
52+
7853
var app = new CommandApp<SearchCommand>();
7954

8055
app.Configure(c =>
8156
{
8257
c.PropagateExceptions();
8358
c.SetHelpProvider(new HelpProvider(c.Settings));
84-
59+
8560
//...
8661
});
8762

8863
try {
89-
res:
9064
var x = await app.RunAsync(args);
9165

92-
switch ((Act) x) {
93-
case Act.Restart:
94-
goto res;
95-
96-
break;
97-
}
98-
9966
return x;
10067
}
10168
catch (Exception e) {

SmartImage.Rdx/Properties/launchSettings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"Profile 4b": {
3333
"commandName": "Project",
34-
"commandLineArgs": "\"C:\\Users\\Deci\\Pictures\\Epic anime\\__re_l_mayer_ergo_proxy_drawn_by_comin__e152c5c48b0058a3374542def4f59c3a.jpg\" -f \"Csv\" -o \"output.csv\" -r \"None\""
34+
"commandLineArgs": "\"C:\\Users\\Deci\\Pictures\\Epic anime\\__re_l_mayer_ergo_proxy_drawn_by_comin__e152c5c48b0058a3374542def4f59c3a.jpg\" -f \"Delimited\" -o \"output.csv\" -r \"None\""
3535
},
3636
"Profile 5": {
3737
"commandName": "Project",
@@ -40,6 +40,10 @@
4040
"Profile 6": {
4141
"commandName": "Project",
4242
"commandLineArgs": "\"C:\\Users\\Deci\\Pictures\\Epic anime\\__re_l_mayer_ergo_proxy_drawn_by_comin__e152c5c48b0058a3374542def4f59c3a.jpg\" -r \"None\" -f \"Csv\" -o \"output.csv\""
43+
},
44+
"Profile 4c": {
45+
"commandName": "Project",
46+
"commandLineArgs": "\"C:\\Users\\Deci\\Pictures\\Epic anime\\__re_l_mayer_ergo_proxy_drawn_by_comin__e152c5c48b0058a3374542def4f59c3a.jpg\" -d \" \" -o \"output.txt\" -r \"None\""
4347
}
4448
}
4549
}

0 commit comments

Comments
 (0)