Skip to content

Commit 327fb7b

Browse files
committed
Final changes for Rdx 1.2.0
1 parent 5167220 commit 327fb7b

4 files changed

Lines changed: 57 additions & 13 deletions

File tree

SmartImage.Lib/Engines/Search/RepostSleuthEngine.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics.CodeAnalysis;
2+
using System.Net;
23
using System.Text.Json;
34
using System.Text.Json.Serialization;
45
using System.Text.Json.Serialization.Metadata;
@@ -59,7 +60,7 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
5960
}, cancellationToken: token);
6061

6162
if (response.StatusCode == 530) {
62-
goto ret;
63+
goto ret;
6364
}
6465

6566
var s = await response.GetStringAsync().ConfigureAwait(false);
@@ -98,7 +99,7 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
9899

99100
#region API Objects
100101

101-
private class RepostSleuthMatch
102+
public class RepostSleuthMatch
102103
{
103104

104105
public int hamming_distance;
@@ -119,13 +120,14 @@ public ValueTask<SearchResultItem> ToItem(SearchResult sr)
119120
Site = post.subreddit,
120121
Url = post.url,
121122
Title = post.title,
122-
Time = DateTimeOffset.FromUnixTimeSeconds((long) post.created_at).LocalDateTime
123+
Time = DateTimeOffset.FromUnixTimeSeconds((long) post.created_at).LocalDateTime,
124+
Metadata = this
123125
});
124126
}
125127

126128
}
127129

128-
private class RepostSleuthPost
130+
public class RepostSleuthPost
129131
{
130132

131133
public string post_id;
@@ -142,7 +144,7 @@ private class RepostSleuthPost
142144
}
143145

144146
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
145-
private class RepostSleuthResult
147+
public class RepostSleuthResult
146148
{
147149

148150
public object meme_template;
@@ -155,7 +157,7 @@ private class RepostSleuthResult
155157

156158
}
157159

158-
private class RepostSleuthSearchSettings
160+
public class RepostSleuthSearchSettings
159161
{
160162

161163
public bool filter_crossposts;
@@ -177,7 +179,7 @@ private class RepostSleuthSearchSettings
177179

178180
}
179181

180-
private class RepostSleuthSearchTimes
182+
public class RepostSleuthSearchTimes
181183
{
182184

183185
public double pre_annoy_filter_time;

SmartImage.Rdx/Commands/Search/SearchCommand.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected override void InitConfig(SearchCommandSettings scs)
130130

131131
Client = new SearchClient(Config);
132132

133-
m_mainTable = CommandSettings.Interactive ? Renderables.CreateMainTable() : Renderables.CreateFullResultTable();
133+
m_mainTable = CommandSettings.Interactive ? Renderables.CreateMainTable() : Renderables.CreateFullResultTable();
134134
m_mainTable.Expand = true;
135135
}
136136

@@ -307,6 +307,7 @@ private async Task RunInteractiveAsync(CancellationToken ct = default)
307307
var sri = sel.Item;
308308
var selIdx = sel.Index();
309309
var selIdx2 = sel.Index2();
310+
310311

311312
s_logger.LogDebug("Selected {Item} {Scn} | {Idx1}, {Idx2}", sel.Item, sel.IsScannedItem, selIdx, selIdx2);
312313

@@ -326,7 +327,7 @@ await AnsiConsole.Live(srTable).StartAsync(async (f) =>
326327
if (!scannedOk) {
327328
return;
328329
}
329-
330+
330331
for (int i = 0; i < sri.ScannedItems.Count; i++) {
331332
SearchResultItem scnItm = sri.ScannedItems[i];
332333
scnItm.CalculateSimilarity(Query.Source);
@@ -446,7 +447,7 @@ private void ShowPreview(CanvasImage ci, SearchResultItem sri)
446447
{
447448
var (w, h) = (AnsiConsole.Profile.Width, AC.Profile.Height);
448449

449-
var pnl = new Panel(ci) { Expand = true, Border = BoxBorder.None, Header = new PanelHeader($"{sri.Value}")};
450+
var pnl = new Panel(ci) { Expand = true, Border = BoxBorder.None, Header = new PanelHeader($"{sri.Value}") };
450451
/*var sriLayout = new Layout("Info");
451452
452453
sriLayout.SplitColumns(

SmartImage.Rdx/Shell/Renderables.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public IRenderable[] GetItemRow(int idx, int subIdx)
140140
return
141141
[
142142
new Text($"#{idx}.{subIdx}", style),
143-
new Text(Markup.Escape(sri.Url)),
143+
new Text(Markup.Escape(sri.Url), new Style(link: sri.Url)),
144144
sri.GetSimilarity(),
145145
Elements.Txt_NA,
146146
sri.GetResolution()
@@ -203,7 +203,7 @@ private static SpcTable CreateResultTable()
203203
{
204204
var tb = new SpcTable()
205205
{
206-
Caption = new TableTitle("Results", Elements.Sty_ResultHeader),
206+
// Caption = new TableTitle("Results", Elements.Sty_ResultHeader),
207207
Border = TableBorder.Simple,
208208
ShowHeaders = true,
209209
};

SmartImage.Rdx/Shell/ShellSelection.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public int Index2()
3636
var rg = ItemIdx + Item.Root.Results[..ItemIdx].Sum(x => x.ScannedItems.Count);
3737

3838

39-
var sumIdx = rg + ScanIdx + (IsScannedItem ? ((ScanIdx == 0) ? 1 : 0) : 0);
39+
var sumIdx = rg + ScanIdx + (IsScannedItem ? ((ScanIdx == 0) ? 1 : 0) : 0);
4040
var sumIdx2 = rg + ScanIdx + (IsScannedItem ? ((ScanIdx == 0) ? 1 : 0) : 1);
4141

4242
return sumIdx2;
@@ -133,4 +133,45 @@ public static ShellSelection GetSelectionChoice(SearchResult res)
133133

134134
}
135135

136+
/*public static ShellSelection GetSelectionChoice2(SearchResult sr)
137+
{
138+
var prompt = new SelectionPrompt<SearchResultItem>()
139+
{
140+
Mode = SelectionMode.Independent,
141+
SearchEnabled = true,
142+
Converter = item =>
143+
{
144+
//
145+
return item.Url;
146+
}
147+
};
148+
149+
foreach (var item in sr.Results) {
150+
151+
if (item.HasScannedItems) {
152+
prompt.AddChoiceGroup(item, item.ScannedItems);
153+
154+
}
155+
else {
156+
prompt.AddChoice(item);
157+
158+
}
159+
}
160+
161+
var resp = AnsiConsole.Prompt(prompt);
162+
int itemIdx = 0, scanIdx = 0;
163+
164+
if (resp.IsChild) {
165+
scanIdx = resp.Parent.ScannedItems.IndexOf(resp);
166+
itemIdx = sr.Results.IndexOf(resp.Parent);
167+
}
168+
else {
169+
itemIdx = sr.Results.IndexOf(resp);
170+
171+
}
172+
173+
174+
return new ShellSelection(resp, itemIdx, scanIdx, resp.IsChild);
175+
}*/
176+
136177
}

0 commit comments

Comments
 (0)