Skip to content

Commit 4a26bda

Browse files
committed
Update Kantan usage for refactor
1 parent 17f3205 commit 4a26bda

File tree

9 files changed

+76
-60
lines changed

9 files changed

+76
-60
lines changed

SmartImage.Lib/Engines/Impl/IqdbEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static ImageResult ParseResult(IHtmlCollection<IElement> tr)
6565
if (tr.Length >= 4) {
6666
var res = tr[3];
6767

68-
string[] wh = res.TextContent.Split(StringConstants.MUL_SIGN);
68+
string[] wh = res.TextContent.Split(Strings.Constants.MUL_SIGN);
6969

7070
string wStr = wh[0].SelectOnlyDigits();
7171
w = Int32.Parse(wStr);

SmartImage.Lib/Engines/Impl/SauceNaoEngine.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,11 @@ private static ImageResult ConvertToImageResult(SauceNaoDataResult sn)
318318
{
319319
Url = String.IsNullOrWhiteSpace(url) ? default : new Uri(url),
320320
Similarity = MathF.Round(sn.Similarity, 2),
321-
Description = Strings.NullIfNullOrWhiteSpace(sn.WebsiteTitle),
322-
Artist = Strings.NullIfNullOrWhiteSpace(sn.Creator),
323-
Source = Strings.NullIfNullOrWhiteSpace(sn.Material),
324-
Characters = Strings.NullIfNullOrWhiteSpace(sn.Character),
325-
Site = Strings.NullIfNullOrWhiteSpace(siteName)
321+
Description = Strings.NormalizeNull(sn.WebsiteTitle),
322+
Artist = Strings.NormalizeNull(sn.Creator),
323+
Source = Strings.NormalizeNull(sn.Material),
324+
Characters = Strings.NormalizeNull(sn.Character),
325+
Site = Strings.NormalizeNull(siteName)
326326
};
327327

328328
return imageResult;

SmartImage.Lib/Engines/Impl/YandexEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static ImageResult Parse(INode siz)
9292

9393
private static (int? w, int? h) ParseResolution(string resText)
9494
{
95-
string[] resFull = resText.Split(StringConstants.MUL_SIGN);
95+
string[] resFull = resText.Split(Strings.Constants.MUL_SIGN);
9696

9797
int? w = null, h = null;
9898

SmartImage/Core/AppInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static void Setup()
126126
/*Console.WriteLine("Non-Romance language detected!");
127127
Console.WriteLine("If English is not the main IME, things may not work properly!");
128128
129-
NConsole.WaitForInput();*/
129+
ConsoleManager.WaitForInput();*/
130130

131131
Trace.WriteLine($"Languages: {languages.QuickJoin()}");
132132
}

SmartImage/Core/AppIntegration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static bool HandleContextMenu(bool option)
5858
}
5959
catch (Exception ex) {
6060
Trace.WriteLine($"{ex.Message}");
61-
NConsole.WaitForInput();
61+
ConsoleManager.WaitForInput();
6262
return false;
6363
}
6464
finally {

SmartImage/Program.cs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
using Windows.Networking.Connectivity;
3232
using Windows.UI.Notifications;
3333
using Kantan.Cli;
34+
using Kantan.Cli.Controls;
3435
using Kantan.Diagnostics;
3536
using Kantan.Net;
37+
using Kantan.Text;
3638
using Kantan.Utilities;
3739
using Microsoft.Toolkit.Uwp.Notifications;
3840
using Novus.Win32;
@@ -78,9 +80,9 @@ public static class Program
7880
/// <summary>
7981
/// Console UI for search results
8082
/// </summary>
81-
private static readonly NConsoleDialog ResultDialog = new()
83+
private static readonly ConsoleDialog ResultDialog = new()
8284
{
83-
Options = new List<NConsoleOption>(),
85+
Options = new List<ConsoleOption>(),
8486

8587
Description = "Press the result number to open in browser\n" +
8688
"Ctrl: Load direct | Alt: Show other | Shift: Open raw | Alt+Ctrl: Download\n" +
@@ -103,13 +105,13 @@ public static class Program
103105

104106
ResultDialog.Options.Add(_orig);
105107

106-
foreach (NConsoleOption option in buffer.Select(NConsoleFactory.CreateResultOption)) {
108+
foreach (ConsoleOption option in buffer.Select(NConsoleFactory.CreateResultOption)) {
107109
ResultDialog.Options.Add(option);
108110
}
109111

110112
_isFilteredShown = !_isFilteredShown;
111113

112-
NConsole.Refresh();
114+
ConsoleManager.Refresh();
113115
},
114116
[ConsoleKey.F2] = async () =>
115117
{
@@ -123,11 +125,11 @@ public static class Program
123125
await Client.RefineSearchAsync();
124126
}
125127
catch (Exception e) {
126-
Console.WriteLine("Error: {0}",e.Message);
127-
NConsole.WaitForSecond();
128+
Console.WriteLine("Error: {0}", e.Message);
129+
ConsoleManager.WaitForSecond();
128130
}
129131

130-
NConsole.Refresh();
132+
ConsoleManager.Refresh();
131133
},
132134
}
133135
};
@@ -147,15 +149,14 @@ private static async Task Main(string[] args)
147149

148150
ToastNotificationManagerCompat.OnActivated += AppInterface.OnToastActivated;
149151

150-
//...
151-
Native.SetConsoleOutputCP(Native.CP_IBM437);
152-
152+
Console.OutputEncoding = Encoding.Unicode;
153+
153154
Console.Title = $"{AppInfo.NAME}";
154155

155156
//120,30
156157
//Console.WindowHeight = 60;
157158

158-
NConsole.Init();
159+
ConsoleManager.Init();
159160
Console.Clear();
160161

161162
Console.CancelKeyPress += (sender, eventArgs) => { };
@@ -200,7 +201,7 @@ private static async Task Main(string[] args)
200201
}
201202
};
202203

203-
NConsoleProgress.Queue(_cancellationToken);
204+
ConsoleProgressIndicator.Queue(_cancellationToken);
204205

205206
// Show results
206207
var searchTask = Client.RunSearchAsync();
@@ -211,7 +212,6 @@ private static async Task Main(string[] args)
211212
// Add original image
212213
ResultDialog.Options.Add(_orig);
213214

214-
215215
await ResultDialog.ReadAsync();
216216

217217
await searchTask;
@@ -227,14 +227,17 @@ private static async Task<bool> HandleArguments()
227227
if (!args.Any()) {
228228
var options = await AppInterface.MainMenuDialog.ReadAsync();
229229

230-
if (!options.Any()) {
231-
return false;
232-
}
230+
var file = options.DragAndDrop;
233231

234-
if (options.First() is string file) {
232+
if (file != null) {
235233
Debug.WriteLine($"Drag and drop: {file}");
236234
Console.WriteLine($">> {file}".AddColor(AppInterface.Elements.ColorMain));
237235
Config.Query = file;
236+
return true;
237+
}
238+
239+
if (!options.Output.Any()) {
240+
return false;
238241
}
239242
}
240243
else {
@@ -264,7 +267,7 @@ private static async Task<bool> HandleArguments()
264267

265268
private static bool _isFilteredShown;
266269

267-
private static NConsoleOption _orig;
270+
private static ConsoleOption _orig;
268271

269272
#region Event handlers
270273

@@ -278,7 +281,7 @@ private static void OnSearchCompleted(object sender, SearchCompletedEventArgs ev
278281
cts.Dispose();
279282

280283
SystemSounds.Exclamation.Play();
281-
NConsole.Refresh();
284+
ConsoleManager.Refresh();
282285

283286
if (Config.PriorityEngines == SearchEngineOptions.Auto) {
284287
var m = Client.Results.OrderByDescending(x => x.PrimaryResult.Similarity);

SmartImage/UI/AppInterface.Elements.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Drawing;
4+
using System.Text;
45
using JetBrains.Annotations;
56
using Kantan.Text;
67
using Kantan.Utilities;
8+
using Novus.Win32;
79
using SmartImage.Lib.Engines;
810

911
namespace SmartImage.UI
@@ -33,16 +35,26 @@ internal static class Elements
3335
{ SearchEngineOptions.TinEye, Color.CornflowerBlue },
3436
};
3537

36-
private static readonly string Enabled = StringConstants.CHECK_MARK.ToString().AddColor(ColorYes);
38+
/*
39+
* Note: Weird encoding nuance
40+
*/
3741

38-
private static readonly string Disabled = StringConstants.MUL_SIGN.ToString().AddColor(ColorNo);
42+
43+
private static readonly Encoding CodePage437 = CodePagesEncodingProvider.Instance.GetEncoding(Native.CP_IBM437);
44+
45+
internal static readonly string CheckMark =
46+
Strings.EncodingConvert(Encoding.Unicode, CodePage437, Strings.Constants.CHECK_MARK.ToString());
47+
48+
private static readonly string Enabled = CheckMark.AddColor(ColorYes);
49+
50+
private static readonly string Disabled = Strings.Constants.MUL_SIGN.ToString().AddColor(ColorNo);
3951

4052
[UsedImplicitly]
4153
internal static string GetName(string s, bool added) => $"{s} ({(ToToggleString(added))})";
4254

43-
public const string ARG_KEY_ACTION = "action";
55+
internal const string ARG_KEY_ACTION = "action";
4456

45-
public const string ARG_VALUE_DISMISS = "dismiss";
57+
internal const string ARG_VALUE_DISMISS = "dismiss";
4658

4759
internal static string ToToggleString(bool b) => b ? Enabled : Disabled;
4860

SmartImage/UI/AppInterface.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Linq;
77
using Kantan.Cli;
8+
using Kantan.Cli.Controls;
89
using Kantan.Net;
910
using Kantan.Text;
1011
using Kantan.Utilities;
@@ -35,15 +36,15 @@ namespace SmartImage.UI
3536
/// </summary>
3637
internal static partial class AppInterface
3738
{
38-
internal static readonly NConsoleOption[] MainMenuOptions =
39+
internal static readonly ConsoleOption[] MainMenuOptions =
3940
{
4041
new()
4142
{
4243
Name = ">>> Run <<<",
4344
Color = Elements.ColorMain,
4445
Function = () =>
4546
{
46-
ImageQuery query = NConsole.ReadLine("Image file or direct URL", x =>
47+
ImageQuery query = ConsoleManager.ReadLine("Image file or direct URL", x =>
4748
{
4849
x = x.CleanString();
4950

@@ -63,8 +64,7 @@ internal static partial class AppInterface
6364
CreateConfigOption(nameof(Config.NotificationImage), "Notification image", 5),
6465

6566
CreateConfigOption(propertyof(() => AppIntegration.IsContextMenuAdded), "Context menu", 6,
66-
added => AppIntegration.HandleContextMenu(
67-
added ? false : true)),
67+
added => AppIntegration.HandleContextMenu(!added)),
6868

6969
new()
7070
{
@@ -74,7 +74,7 @@ internal static partial class AppInterface
7474
//Console.Clear();
7575

7676
Console.WriteLine(Config);
77-
NConsole.WaitForInput();
77+
ConsoleManager.WaitForInput();
7878

7979
return null;
8080
}
@@ -99,22 +99,22 @@ internal static partial class AppInterface
9999
Console.WriteLine($"In path: {AppInfo.IsAppFolderInPath}");
100100

101101
Console.WriteLine();
102-
Console.WriteLine(StringConstants.Separator);
102+
Console.WriteLine(Strings.Constants.Separator);
103103

104104
foreach (var utility in ImageHelper.UtilitiesMap) {
105105
Console.WriteLine(utility);
106106
}
107107

108108
Console.WriteLine();
109-
Console.WriteLine(StringConstants.Separator);
109+
Console.WriteLine(Strings.Constants.Separator);
110110

111111
var dependencies = ReflectionHelper.DumpDependencies();
112112

113113
foreach (var name in dependencies) {
114114
Console.WriteLine($"{name.Name} ({name.Version})");
115115
}
116116

117-
NConsole.WaitForInput();
117+
ConsoleManager.WaitForInput();
118118

119119
return null;
120120
}
@@ -153,7 +153,7 @@ internal static partial class AppInterface
153153

154154
};
155155

156-
internal static readonly NConsoleDialog MainMenuDialog = new()
156+
internal static readonly ConsoleDialog MainMenuDialog = new()
157157
{
158158
Options = MainMenuOptions,
159159
Header = AppInfo.NAME_BANNER,

0 commit comments

Comments
 (0)