Skip to content

Commit e9230ab

Browse files
committed
New features; fixes
1 parent 3ea082e commit e9230ab

File tree

5 files changed

+61
-15
lines changed

5 files changed

+61
-15
lines changed

SmartImage.Lib/Engines/Impl/YandexEngine.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,24 @@ protected override SearchResult Process(object obj, SearchResult sr)
208208
images = images.OrderByDescending(r => r.PixelResolution).ToList();
209209

210210
//
211-
var best = images[0];
212-
sr.PrimaryResult.UpdateFrom(best);
211+
212+
if (images.Count > 0) {
213+
var best = images[0];
214+
sr.PrimaryResult.UpdateFrom(best);
213215

214216

215-
if (looksLike != null) {
216-
//todo
217+
if (looksLike != null)
218+
{
219+
//todo
217220

218-
// sr.PrimaryResult.Description = Encoding.UTF8.GetString(
219-
// Encoding.Convert(Encoding.Unicode, Encoding.UTF8, Encoding.Unicode.GetBytes(looksLike)));
220-
sr.PrimaryResult.Description = looksLike;
221-
}
221+
// sr.PrimaryResult.Description = Encoding.UTF8.GetString(
222+
// Encoding.Convert(Encoding.Unicode, Encoding.UTF8, Encoding.Unicode.GetBytes(looksLike)));
223+
sr.PrimaryResult.Description = looksLike;
224+
}
222225

223-
sr.OtherResults.AddRange(images);
226+
sr.OtherResults.AddRange(images);
227+
}
228+
224229

225230
const string NO_MATCHING = "No matching images found";
226231

SmartImage.Lib/SearchClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ public void Reload()
9393
public void Reset()
9494
{
9595
Results.Clear();
96+
FilteredResults.Clear();
9697
IsComplete = false;
98+
Reload();
9799
}
98100

99101
#region Primary operations

SmartImage.Lib/Searching/SearchResult.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ public bool IsSuccessful
105105

106106
case ResultStatus.Success:
107107
case ResultStatus.NoResults:
108+
case ResultStatus.Cooldown:
108109
case ResultStatus.Extraneous:
109110
return true;
110111

112+
113+
111114
default:
112115
throw new ArgumentOutOfRangeException();
113116
}

SmartImage/Program.cs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,42 @@ public static class Program
7373
public static readonly NConsoleDialog ResultDialog = new()
7474
{
7575
Options = new List<NConsoleOption>(),
76-
Description = Elements.Description
76+
77+
Description = "Press the result number to open in browser\n" +
78+
"Ctrl: Load direct | Alt: Show other | Shift: Open raw | Alt+Ctrl: Download\n" +
79+
"F1: Show filtered results | F5: Refresh",
80+
81+
Functions = new Action[]
82+
{
83+
() =>
84+
{
85+
// F1 : Show filtered
86+
87+
88+
ResultDialog!.Options.Clear();
89+
90+
var buffer = new List<SearchResult>();
91+
92+
buffer.AddRange(Client.Results);
93+
94+
if (!_isFilteredShown) {
95+
buffer.AddRange(Client.FilteredResults);
96+
}
97+
98+
foreach (NConsoleOption? option in buffer.Select(NConsoleFactory.CreateResultOption)) {
99+
Program.ResultDialog.Options.Add(option);
100+
}
101+
102+
_isFilteredShown = !_isFilteredShown;
103+
104+
NConsole.Refresh();
105+
},
106+
107+
}
77108
};
78109

110+
private static bool _isFilteredShown = false;
111+
79112
#endregion
80113

81114
/// <summary>
@@ -129,6 +162,12 @@ private static async Task Main(string[] args)
129162
$"| PE: {Config.PriorityEngines} " +
130163
$"| Filtering: {Config.Filtering.ToToggleString()}";
131164

165+
await Run();
166+
}
167+
168+
private static async Task Run()
169+
{
170+
132171
CancellationTokenSource cts = new();
133172

134173
// Run search
@@ -139,7 +178,8 @@ private static async Task Main(string[] args)
139178
{
140179
OnSearchCompleted(obj, eventArgs, cts);
141180

142-
if (Config.Notification) {
181+
if (Config.Notification)
182+
{
143183
AppInterface.ShowToast(obj, eventArgs);
144184
}
145185
};
@@ -157,7 +197,6 @@ private static async Task Main(string[] args)
157197
ResultDialog.Read();
158198

159199
await searchTask;
160-
161200
}
162201

163202
private static bool HandleArguments()

SmartImage/UI/Elements.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ internal static class Elements
2727
{SearchEngineOptions.TinEye, Color.CornflowerBlue},
2828
};
2929

30-
internal const string Description = "Press the result number to open in browser\n" +
31-
"Ctrl: Load direct | Alt: Show other | Shift: Open raw | Alt+Ctrl: Download";
32-
3330
private static readonly string Enabled = StringConstants.CHECK_MARK.ToString().AddColor(ColorYes);
3431

3532
private static readonly string Disabled = StringConstants.MUL_SIGN.ToString().AddColor(ColorNo);

0 commit comments

Comments
 (0)