Skip to content

Commit 8b8ee19

Browse files
committed
Hotfixes
1 parent d4ed74f commit 8b8ee19

6 files changed

Lines changed: 93 additions & 44 deletions

File tree

SmartImage.Lib/Engines/Search/TraceMoeEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
7777

7878
ret:
7979

80-
if (tm is { Error: { } }) {
80+
if (!String.IsNullOrWhiteSpace(tm?.Error)) {
8181
// Debug.WriteLine($"{Name} :: API error: {tm.Error}", nameof(GetResultAsync));
8282
Logger.LogDebug("{Name} :: API error {Err} in {Fn}", Name, tm.Error, nameof(GetResultAsync));
8383
sr.ErrorMessage = tm.Error;

SmartImage.Rdx/Commands/Common/CustomHelpProvider.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ namespace SmartImage.Rdx.Commands.Common;
1111
internal class CustomHelpProvider : HelpProvider
1212
{
1313

14-
public CustomHelpProvider(ICommandAppSettings settings)
15-
: base(settings) { }
14+
public CustomHelpProvider(ICommandAppSettings settings) : base(settings) { }
1615

1716
public override IEnumerable<IRenderable> GetUsage(ICommandModel model, ICommandInfo? command)
1817
{
@@ -37,8 +36,8 @@ public override IEnumerable<IRenderable> GetDescription(ICommandModel model, ICo
3736
{
3837
Text.NewLine,
3938
new Text("DESCRIPTION:", new Style(SpcColor.Yellow, decoration: Decoration.Bold)), Text.NewLine,
40-
new Text($" Homepage: {R1.Url_Repo}", new Style(link: R1.Url_Repo)), Text.NewLine,
41-
new Text($" Wiki: {R1.Url_Wiki}", new Style(link: R1.Url_Wiki)), Text.NewLine,
39+
new Text($" Homepage: {R1.Url_Repo}", new Style(link: R1.Url_Repo)), Text.NewLine,
40+
new Text($" Wiki: {R1.Url_Wiki}", new Style(link: R1.Url_Wiki)), Text.NewLine,
4241
Text.NewLine,
4342
Text.NewLine,
4443
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Author: Deci | Project: SmartImage.Rdx | Name: ConsoleAction.cs
2+
// Date: 2026/02/21 @ 14:02:02
3+
4+
#nullable disable
5+
using Spectre.Console;
6+
using Spectre.Console.Rendering;
7+
8+
namespace SmartImage.Rdx.Commands.Search;
9+
10+
internal class ConsoleAction
11+
{
12+
13+
public string Descr { get; }
14+
15+
public delegate bool RenderableFunction(LiveDisplayContext ldc, IRenderable ci);
16+
17+
public RenderableFunction Func {get;}
18+
}

SmartImage.Rdx/Commands/Search/SearchCommand.cs

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ static SearchCommand() { }
8484

8585
public SearchCommand()
8686
{
87-
m_cts = new CancellationTokenSource();
88-
m_ctsRun = new CancellationTokenSource();
87+
m_cts = new CancellationTokenSource();
88+
m_ctsRun = new CancellationTokenSource();
8989
m_ctsRunSearch = new CancellationTokenSource();
9090

9191
// m_results = new();
9292
m_resultTables = new ConcurrentDictionary<SearchResult, SpcTable>();
9393
m_previewCanvasCache = new MemoryCache("Buf");
9494

9595
// m_prompts = new ConcurrentDictionary<SearchResult, SelectionPrompt<SearchResultItem>>();
96-
Query = SearchQuery.Null;
96+
Query = SearchQuery.Null;
9797
}
9898

9999
#region
@@ -171,7 +171,7 @@ public override async Task<int> ExecuteAsync(CommandContext context, SearchComma
171171
);
172172

173173
// AnsiConsole.Write(m_layout);
174-
174+
175175
try {
176176

177177
IRenderable elem = CommandSettings.Interactive ? m_layout : m_mainTable;
@@ -223,7 +223,7 @@ private async Task RunSearchLiveAsync(LiveDisplayContext c, CancellationToken ct
223223
#if UNITTEST
224224
return;
225225
#endif
226-
226+
227227
var search = Client.RunSearchAsync(Query, token: ct);
228228

229229
while (!ct.IsCancellationRequested && await Client.ResultChannel.Reader.WaitToReadAsync(ct)) {
@@ -336,8 +336,8 @@ await AnsiConsole.Live(srTable).StartAsync(async (f) =>
336336
SearchResultItem scnItm = sri.ScannedItems[i];
337337
scnItm.CalculateSimilarity(Query.Source);
338338

339-
// var scnRow = scnItm.GetItemRow(sel.ItemIdx, i);
340-
// srTable.InsertRow(selIdx + i + 1, scnRow);
339+
var scnRow = scnItm.GetItemRow(sel.ItemIdx, i);
340+
srTable.InsertRow(selIdx + i + 1, scnRow);
341341
}
342342

343343
// m_prompts[sr].AddChoiceGroup(sri, sri.ScannedItems);
@@ -451,24 +451,52 @@ private CanvasImage GetPreview(SearchResultItem sri)
451451
return ci;
452452
}
453453

454+
455+
private const ConsoleKey PREV_KEY_RESIZE_INTERNAL = ConsoleKey.S;
456+
private const ConsoleKey PREV_KEY_MAXWIDTH_BUFWIDTH = ConsoleKey.M;
457+
private const ConsoleKey PREV_KEY_RESIZE_SCALE = ConsoleKey.R;
458+
private const ConsoleKey PREV_KEY_EXIT = ConsoleKey.Escape;
459+
460+
private static readonly Dictionary<ConsoleKey, string> _keyDescriptions = new()
461+
{
462+
{ PREV_KEY_RESIZE_INTERNAL, "Resize (internal)" },
463+
{ PREV_KEY_RESIZE_SCALE, "Resize (scale)" },
464+
{ PREV_KEY_MAXWIDTH_BUFWIDTH, "Set max preview width to buffer width" },
465+
{ PREV_KEY_EXIT, "Exit preview" },
466+
};
467+
468+
private static readonly string _descRow =
469+
_keyDescriptions.Aggregate(String.Empty, (s, kv) => { return s + Markup.Escape(($"[{kv.Key}] : {kv.Value}")) + " | "; });
470+
471+
454472
private void ShowPreview(CanvasImage ci, SearchResultItem sri)
455473
{
456474
var (w, h) = (AnsiConsole.Profile.Width, AC.Profile.Height);
457475

458-
var pnl = new Panel(ci) { Expand = true, Border = BoxBorder.None, Header = new PanelHeader($"{sri.Value}") };
459-
/*var sriLayout = new Layout("Info");
476+
var pnl = new Panel(ci)
477+
{
478+
Expand = true,
479+
Border = BoxBorder.None,
480+
Header = new PanelHeader($"{sri.Value}"),
481+
};
482+
483+
var sriLayout = new Layout("Preview");
460484

461-
sriLayout.SplitColumns(
462-
new Layout("Metadata"),
463-
new Layout("Image")
485+
sriLayout.SplitRows(
486+
new Layout("Image") { Ratio = 2 },
487+
new Layout("Details") { Size = 2}
464488
);
465489

490+
// var grid = sri.GetItemInfoGrid();
491+
var infoGrid = new Grid() { Expand = false, };
492+
infoGrid.AddColumns(2);
493+
infoGrid.AddRow(["Keys", _descRow]);
494+
infoGrid.AddRow(["Metadata", sri.ToString()]);
466495

467-
var grid = sri.GetInfoGrid();
468-
sriLayout["Metadata"].Update(grid);
469-
sriLayout["Image"].Update(ci);*/
496+
sriLayout["Image"].Update(pnl);
497+
sriLayout["Details"].Update(infoGrid);
470498

471-
AnsiConsole.Live(pnl).Start(ldc =>
499+
AnsiConsole.Live(sriLayout).Start(ldc =>
472500
{
473501
while (true) {
474502
// ci.MaxWidth = mw < 0 ? null : mw;
@@ -482,15 +510,15 @@ private void ShowPreview(CanvasImage ci, SearchResultItem sri)
482510
switch (cki.Value.Key) {
483511

484512

485-
case ConsoleKey.S:
513+
case PREV_KEY_RESIZE_INTERNAL:
486514
ci.Mutate(act => { act.Resize(sri.Image.Width, sri.Image.Height); });
487515
break;
488516

489-
case ConsoleKey.M:
517+
case PREV_KEY_MAXWIDTH_BUFWIDTH:
490518
ci.MaxWidth = w;
491519
break;
492520

493-
case ConsoleKey.R:
521+
case PREV_KEY_RESIZE_SCALE:
494522
ci.Mutate(act =>
495523
{
496524
var cs = act.GetCurrentSize();
@@ -502,15 +530,14 @@ private void ShowPreview(CanvasImage ci, SearchResultItem sri)
502530
ci.MaxWidth = null;
503531
continue;
504532

505-
case ConsoleKey.Escape:
533+
case PREV_KEY_EXIT:
506534
return;
507535

508536
}
509537
}
510538
});
511539

512540

513-
return;
514541
}
515542

516543
#endregion

SmartImage.Rdx/Commands/Search/SearchCommandSettings.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public sealed class SearchCommandSettings : CommonCommandSettings
2222
{
2323

2424
[CommandArgument(0, "<query>")]
25-
[Description("Query: file or URL; see wiki")]
25+
[Description($"Query: file or URL. Specify {QUERY_DEFAULT_CLIPBOARD} to read from clipboard (Windows only)")]
2626
public string? Query { get; private set; }
2727

2828
#region
@@ -58,8 +58,6 @@ public sealed class SearchCommandSettings : CommonCommandSettings
5858
public const OutputFields OUTPUT_FIELDS_DEFAULT =
5959
OutputFields.Name | OutputFields.Similarity | OutputFields.Url;
6060

61-
public const string QUERY_DEFAULT_CLIPBOARD = "<clipboard>";
62-
6361
[MNNW(true, nameof(OutputFile))]
6462
internal bool HasOutputFile => !String.IsNullOrWhiteSpace(OutputFile);
6563

@@ -80,25 +78,22 @@ public sealed class SearchCommandSettings : CommonCommandSettings
8078

8179
#endregion
8280

83-
// public bool? Silent { get; private set; } //todo
84-
85-
// public const string PROP_ARG_RESULTS = "$all_results";
86-
8781
[CommandOption("--interactive")]
8882
[DefaultValue(true)]
8983
[Description("Interactive results")]
9084
public bool Interactive { get; private set; }
9185

92-
[CommandOption("--clipboard")]
93-
[DefaultValue(false)]
94-
[Description("Clipboard")]
95-
public bool UseClipboard { get; private set; }
86+
public const string QUERY_DEFAULT_CLIPBOARD = "<clipboard>";
9687

9788
public override ValidationResult Validate()
9889
{
9990
var result = base.Validate();
10091

101-
if (UseClipboard && OperatingSystem.IsWindows()) {
92+
if (Query == QUERY_DEFAULT_CLIPBOARD) {
93+
if (!OperatingSystem.IsWindows()) {
94+
return ValidationResult.Error("Clipboard input is only supported on Windows");
95+
}
96+
10297
Clipboard.Open();
10398

10499
string? data = null;
@@ -112,13 +107,14 @@ public override ValidationResult Validate()
112107
else if (Clipboard.IsFormatAvailable((uint) ClipboardFormat.CF_HDROP)) {
113108
data = Clipboard.GetDragQueryList().FirstOrDefault();
114109
}
115-
else { }
110+
else {
111+
return ValidationResult.Error($"No valid clipboard format detected");
112+
}
116113

117114
if (data != null) {
118115
Query = data;
119116
}
120117

121-
// var data2 = Novus.Win32.Clipboard.GetData((uint) ClipboardFormat.BMP2);
122118
Clipboard.Close();
123119
}
124120

SmartImage.Rdx/Shell/Renderables.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ public IRenderable[] GetFullResultRow(int i, Style style)
7575
return [name, url, sim, artist, wh];
7676
}
7777

78-
public Grid GetInfoGrid()
78+
public Grid GetItemInfoGrid()
7979
{
80+
// TODO
81+
8082
IRenderable url;
8183
var link = sri.Url;
8284
Style linkStyle;
@@ -100,13 +102,20 @@ public Grid GetInfoGrid()
100102
var elems = new List<IRenderable>() { name, url, sim, artist, wh };
101103

102104
// var elems2 = [sri.Character, sri.Source, sri.Description, sri.Site];
103-
var elemnames = new String[] { nameof(sri.Character), nameof(sri.Source), nameof(sri.Description), nameof(sri.Site),nameof(sri.Title) };
105+
var elemNames = new String[]
106+
{
107+
nameof(sri.Character),
108+
nameof(sri.Source),
109+
nameof(sri.Description),
110+
nameof(sri.Site),
111+
nameof(sri.Title)
112+
};
104113

105114
/*var fields = sri.GetType().GetProperties(BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public)
106115
.Where(x => x.GetValue(sri) != null);*/
107116

108-
foreach (string elemname in elemnames) {
109-
var prop = sri.GetType().GetProperty(elemname, BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public);
117+
foreach (string elemName in elemNames) {
118+
var prop = sri.GetType().GetProperty(elemName, BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public);
110119

111120
if (prop is {}) {
112121
var val = prop.GetValue(sri);

0 commit comments

Comments
 (0)