Skip to content

Commit 29bb947

Browse files
committed
1.9.2
1 parent 5ff94bc commit 29bb947

File tree

5 files changed

+76
-17
lines changed

5 files changed

+76
-17
lines changed

SmartImage/Commands.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,16 @@ public static void ShowInfo()
181181
CliOutput.WriteInfo("Author: {0}", RuntimeInfo.Author);
182182
}
183183

184+
private const char CLI_CHAR = '*';
185+
184186
/// <summary>
185187
/// Handles user input
186188
/// </summary>
187189
/// <param name="rg"><see cref="ConsoleOption"/></param>
188190
public static void HandleConsoleOptions(ConsoleOption[] rg)
189191
{
192+
193+
190194
ConsoleKeyInfo cki;
191195

192196
do {
@@ -207,7 +211,10 @@ public static void HandleConsoleOptions(ConsoleOption[] rg)
207211
sb.AppendLine();
208212
}
209213

210-
Console.Write(sb);
214+
var s = CliOutput.Prepare(CLI_CHAR,sb.ToString());
215+
Console.Write(s);
216+
217+
//CliOutput.WriteInfo(sb);
211218
}
212219

213220
Console.WriteLine();

SmartImage/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ private static void Main(string[] args)
8080
{
8181
Console.Title = RuntimeInfo.NAME;
8282
Console.SetWindowSize(Console.WindowWidth, Console.WindowHeight + 5);
83+
Console.Clear();
8384

8485
RuntimeInfo.Setup();
8586
SearchConfig.ReadSearchConfigArgs(args);

SmartImage/Searching/Search.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Diagnostics;
66
using System.IO;
77
using System.Linq;
8-
using System.Threading.Tasks;
8+
using System.Text;
99
using SimpleCore.Utilities;
1010
using SmartImage.Engines;
1111
using SmartImage.Engines.Imgur;
@@ -54,7 +54,7 @@ private static ISearchEngine[] GetAvailableEngines()
5454

5555

5656
new KarmaDecay(),
57-
new TraceMoe(),
57+
new TraceMoe()
5858
};
5959

6060
engines.AddRange(others);
@@ -68,7 +68,7 @@ public static bool RunSearch(string img, ref SearchResult[] res)
6868
* Run
6969
*/
7070

71-
var auth = SearchConfig.Config.ImgurAuth;
71+
string auth = SearchConfig.Config.ImgurAuth;
7272
bool useImgur = !String.IsNullOrWhiteSpace(auth);
7373

7474
var engines = SearchConfig.Config.Engines;
@@ -137,23 +137,38 @@ private static bool StartSearches(string imgUrl, SearchEngines engines, ref Sear
137137
Console.Write(wait);
138138
});
139139

140+
var sw = Stopwatch.StartNew();
140141

141142
// Run search
142143
var result = currentEngine.GetResult(imgUrl);
143144

145+
sw.Stop();
146+
144147
if (result != null) {
145148
string url = result.Url;
146149

150+
var sb = new StringBuilder();
151+
double t = sw.Elapsed.TotalSeconds;
152+
double t2 = Math.Round(t, 3);
153+
sb.AppendFormat("{0}: Done ({1:F3} sec)\n", result.Name, t2);
154+
155+
156+
//todo
157+
158+
bool ok = url != null;
159+
160+
string sz = sb.ToString();
161+
147162

148-
if (url != null) {
149-
CliOutput.OnCurrentLine(ConsoleColor.Green, "{0}: Done\n", result.Name);
163+
if (ok) {
164+
CliOutput.OnCurrentLine(ConsoleColor.Green, sz);
150165

151166
if (SearchConfig.Config.PriorityEngines.HasFlag(currentEngine.Engine)) {
152167
WebAgent.OpenUrl(result.Url);
153168
}
154169
}
155170
else {
156-
CliOutput.OnCurrentLine(ConsoleColor.Yellow, "{0}: Done (url is null!)\n", result.Name);
171+
CliOutput.OnCurrentLine(ConsoleColor.Yellow, sz);
157172
}
158173

159174
res[i] = result;

SmartImage/SmartImage.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
3232
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
3333
<PackageReference Include="RestSharp" Version="106.11.4" />
34-
<PackageReference Include="SimpleCore" Version="1.0.9" />
34+
<PackageReference Include="SimpleCore" Version="1.1.2" />
3535
<PackageReference Include="System.Json" Version="4.7.1" />
3636

3737

@@ -43,7 +43,7 @@
4343

4444
<PropertyGroup>
4545
<PackageId>SmartImage</PackageId>
46-
<Version>1.9.1</Version>
46+
<Version>1.9.2</Version>
4747
<Authors>Read Stanton (Decimation)</Authors>
4848
<PackageTags>Image reverse search identification source sauce</PackageTags>
4949
<RepositoryUrl>https://github.com/Decimation/SmartImage</RepositoryUrl>

SmartImage/Utilities.cs

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,54 @@ namespace SmartImage
99
{
1010
public static class Utilities
1111
{
12+
public static string Prettify(string s)
13+
{
14+
char c = '*';
15+
var ELLIPSES = "...";
16+
int lim = Console.BufferWidth - (10 + ELLIPSES.Length);
17+
18+
var srg = s.Split('\n');
19+
20+
for (int i = 0; i < srg.Length; i++) {
21+
var y = " " + srg[i];
22+
23+
string x;
24+
25+
26+
if (string.IsNullOrWhiteSpace(y)) {
27+
x = string.Empty;
28+
}
29+
else {
30+
x = c + y;
31+
}
32+
33+
var x2 = x.Truncate(lim);
34+
35+
if (x2.Length < x.Length) {
36+
x2 += ELLIPSES;
37+
}
38+
39+
40+
srg[i] = x2;
41+
42+
43+
}
44+
45+
var s2 = string.Join('\n', srg);
46+
47+
return s2;
48+
}
49+
1250
public static T Read<T>(string rawValue)
1351
{
14-
if (typeof(T).IsEnum)
15-
{
16-
Enum.TryParse(typeof(T), (string)rawValue, out var e);
17-
return (T)e;
52+
if (typeof(T).IsEnum) {
53+
Enum.TryParse(typeof(T), (string) rawValue, out var e);
54+
return (T) e;
1855
}
1956

20-
if (typeof(T) == typeof(bool))
21-
{
57+
if (typeof(T) == typeof(bool)) {
2258
Boolean.TryParse(rawValue, out var b);
23-
return (T)(object)b;
59+
return (T) (object) b;
2460
}
2561

2662
return (T) (object) rawValue;
@@ -33,4 +69,4 @@ internal static string CleanString(String s)
3369
return s;
3470
}
3571
}
36-
}
72+
}

0 commit comments

Comments
 (0)