Skip to content

Commit 680c84a

Browse files
committed
Improvements; UI; colors; misc;
1 parent a75f004 commit 680c84a

File tree

8 files changed

+118
-73
lines changed

8 files changed

+118
-73
lines changed

SmartImage/Core/Info.cs

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
using System.Drawing;
55
using System.IO;
66
using System.Reflection;
7+
using System.Text;
78
using JetBrains.Annotations;
89
using Novus;
910
using Novus.Runtime;
1011
using Novus.Win32;
1112
using SimpleCore.Cli;
13+
using SimpleCore.Utilities;
1214
using SmartImage.Utilities;
15+
using static SmartImage.Core.Interface;
1316

1417
// ReSharper disable UnusedMember.Global
1518

@@ -103,78 +106,78 @@ public static void Setup()
103106

104107
internal static void ShowInfo()
105108
{
106-
107109
Console.Clear();
108110

109-
Console.WriteLine(Info.NAME_BANNER);
111+
NConsole.Resize(ConsoleWindowWidth, 30);
112+
113+
var sb = new StringBuilder();
114+
sb.AppendColor(ColorPrimary, NAME_BANNER);
115+
sb.AppendLine();
110116

117+
111118
/*
112119
* Author info
113120
*/
114121

115-
NConsole.OverrideForegroundColor = Interface.ColorMain;
116122

117-
NConsole.WriteInfo("Author: {0}", Author);
118-
NConsole.WriteInfo("Repo: {0}", Repo);
119-
NConsole.WriteInfo("Readme: {0}", Readme);
120123

121-
NConsole.NewLine();
124+
sb.AppendLabelWithColor(ColorPrimary, "Author", ColorMisc2, Author).AppendLine();
125+
sb.AppendLabelWithColor(ColorPrimary, "Repo", ColorMisc2, Repo).AppendLine();
126+
sb.AppendLabelWithColor(ColorPrimary, "Readme", ColorMisc2, Readme).AppendLine();
122127

123-
NConsole.ResetOverrideColors();
128+
sb.AppendLine();
124129

125130
/*
126131
* Config
127132
*/
128133

129-
NConsole.OverrideForegroundColor = Interface.ColorConfig;
134+
sb.Append(SearchConfig.Config);
130135

131-
NConsole.WriteInfo(SearchConfig.Config);
132-
133-
NConsole.ResetOverrideColors();
134136

135137

136138
/*
137139
* Version info
138140
*/
139141

140-
NConsole.OverrideForegroundColor = Interface.ColorVersion;
142+
sb.AppendLine();
141143

142144
var versionsInfo = UpdateInfo.GetUpdateInfo();
143145

144-
NConsole.WriteInfo("Current version: {0}", versionsInfo.Current);
145-
NConsole.WriteInfo("Latest version: {0}", versionsInfo.Latest.Version);
146-
NConsole.WriteInfo("Version status: {0}", versionsInfo.Status);
147-
148-
NConsole.NewLine();
149-
150-
NConsole.ResetOverrideColors();
146+
sb.AppendLabelWithColor(ColorVersion,"Current version", ColorMisc2, versionsInfo.Current).AppendLine();
147+
sb.AppendLabelWithColor(ColorVersion,"Latest version", ColorMisc2, versionsInfo.Latest.Version).AppendLine();
148+
sb.AppendLabelWithColor(ColorVersion,"Version status", ColorMisc2, versionsInfo.Status).AppendLine();
149+
151150

152151
/*
153152
* Runtime info
154153
*/
155154

156-
NConsole.OverrideForegroundColor = Interface.ColorUtility;
157-
158-
NConsole.WriteInfo("Application folder: {0}", AppFolder);
159-
NConsole.WriteInfo("Executable location: {0}", ExeLocation);
160-
NConsole.WriteInfo("Context menu integrated: {0}", Integration.IsContextMenuAdded);
161-
NConsole.WriteInfo("In path: {0}\n", IsAppFolderInPath);
155+
sb.AppendLine();
156+
157+
string appFolderName = new DirectoryInfo(AppFolder).Name;
158+
var exeFolderName = new DirectoryInfo(ExeLocation).Name;
162159

163-
NConsole.ResetOverrideColors();
160+
sb.AppendLabelWithColor(ColorUtility,"Application folder", ColorMisc2, appFolderName).AppendLine();
161+
sb.AppendLabelWithColor(ColorUtility,"Executable location", ColorMisc2, exeFolderName).AppendLine();
162+
sb.AppendLabelWithColor(ColorUtility,"Context menu integrated", ColorMisc2, Integration.IsContextMenuAdded).AppendLine();
163+
sb.AppendLabelWithColor(ColorUtility, "In path", ColorMisc2, IsAppFolderInPath).AppendLine();
164164

165165

166+
166167

167168
/*
168169
* Dependencies
169170
*/
170171

171-
NConsole.WriteInfo("Dependencies:");
172-
173-
var dependencies = RuntimeInfo.DumpDependencies();
172+
// sb.AppendLine("Dependencies:");
173+
//
174+
// var dependencies = RuntimeInfo.DumpDependencies();
175+
//
176+
// foreach (var name in dependencies) {
177+
// sb.AppendColor(ColorMisc,$"{name.Name!} ({name.Version!})").AppendLine();
178+
// }
174179

175-
foreach (var name in dependencies) {
176-
NConsole.WriteInfo("{0} ({1})", name.Name!, name.Version!);
177-
}
180+
NConsole.Write(sb);
178181
}
179182
}
180183
}

SmartImage/Core/Interface.cs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Drawing;
34
using System.IO;
45
using System.Linq;
@@ -61,9 +62,19 @@ private static NConsoleOption[] AllOptions
6162
internal static void Run() => NConsole.ReadOptions(MainMenu);
6263

6364

65+
/// <summary>
66+
/// Misc color
67+
/// </summary>
68+
internal static readonly Color ColorMisc2 = Color.White;
69+
6470
/// <summary>
6571
/// Primary color
6672
/// </summary>
73+
internal static readonly Color ColorPrimary = Color.Red;
74+
75+
/// <summary>
76+
/// Main color
77+
/// </summary>
6778
internal static readonly Color ColorMain = Color.Yellow;
6879

6980
/// <summary>
@@ -137,8 +148,12 @@ private static NConsoleOption[] AllOptions
137148
Color = ColorConfig,
138149
Function = () =>
139150
{
140-
SearchConfig.Config.SearchEngines = ReadSearchEngineOptions();
141-
SearchConfig.Config.EnsureConfig();
151+
if (ReadSearchEngineOptions(out var newValues)) {
152+
SearchConfig.Config.SearchEngines = newValues;
153+
SearchConfig.Config.EnsureConfig();
154+
155+
}
156+
142157
NConsole.WriteSuccess(SearchConfig.Config.SearchEngines);
143158
NConsole.WaitForSecond();
144159
return null;
@@ -152,23 +167,34 @@ private static NConsoleOption[] AllOptions
152167
Color = ColorConfig,
153168
Function = () =>
154169
{
155-
SearchConfig.Config.PriorityEngines = ReadSearchEngineOptions();
156-
SearchConfig.Config.EnsureConfig();
170+
if (ReadSearchEngineOptions(out var newValues)) {
171+
SearchConfig.Config.PriorityEngines = newValues;
172+
SearchConfig.Config.EnsureConfig();
173+
174+
}
175+
157176
NConsole.WriteSuccess(SearchConfig.Config.PriorityEngines);
158177
NConsole.WaitForSecond();
159178
return null;
160179
}
161180
};
162181

163182

164-
private static SearchEngineOptions ReadSearchEngineOptions()
183+
private static bool ReadSearchEngineOptions(out SearchEngineOptions newValues)
165184
{
166185
var rgEnum = NConsoleOption.FromEnum<SearchEngineOptions>();
167186
var values = NConsole.ReadOptions(rgEnum, true);
168187

169-
var newValues = Enums.ReadFromSet<SearchEngineOptions>(values);
188+
if (!values.Any()) {
189+
newValues = default;
190+
return false;
191+
}
192+
193+
newValues = Enums.ReadFromSet<SearchEngineOptions>(values);
194+
195+
Debug.WriteLine($"{values.Count} -> {newValues}");
170196

171-
return newValues;
197+
return true;
172198
}
173199

174200

@@ -357,7 +383,7 @@ private static string GetContextMenuString(bool added) =>
357383
//var cd2 = cd.Parent.Parent.Parent.Parent.ToString();
358384
//var cd2 = cd.GetParentLevel(4).ToString();
359385

360-
string? cd2 = FileSystem.GetParentLevel(Environment.CurrentDirectory, 4);
386+
string? cd2 = FileSystem.GetRelativeParent(Environment.CurrentDirectory, 4);
361387

362388
var rgOption = NConsoleOption.FromArray(TestImages, s => s);
363389

SmartImage/Core/SearchConfig.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using SmartImage.Engines.SauceNao;
1313
using SmartImage.Searching;
1414
using SmartImage.Utilities;
15+
using static SmartImage.Core.Interface;
1516

1617
#pragma warning disable HAA0502, HAA0302, HAA0505, HAA0601, HAA0301, HAA0501, HAA0101, HAA0102, RCS1036
1718

@@ -95,6 +96,8 @@ private SearchConfig()
9596
/// </summary>
9697
public string Image { get; set; }
9798

99+
public bool HasImage => !string.IsNullOrWhiteSpace(Image);
100+
98101
/// <summary>
99102
/// Location of config file
100103
/// </summary>
@@ -169,44 +172,49 @@ public override string ToString()
169172
var sb = new StringBuilder();
170173

171174

172-
var keyColor = Color.Red;
173-
var white = Color.White;
174-
var cadetBlue = Color.CadetBlue;
175-
176-
177-
if (!String.IsNullOrWhiteSpace(Image)) {
175+
if (HasImage) {
178176
// Image may be null if not specified (error) or viewed in other UIs
179177
// if so, omit it
180-
181-
Append(keyColor, "Image", white, Image);
178+
var fi = new FileInfo(Image).Name;
179+
sb.AppendLabelWithColor(ColorPrimary, "Image", ColorMain, fi).AppendLine().AppendLine();
182180
}
183181

184182

185-
Append(keyColor, "Search engines", cadetBlue, SearchEngines);
186-
Append(keyColor, "Priority engines", cadetBlue, PriorityEngines);
183+
sb.AppendLabelWithColor(ColorConfig, "Search engines", ColorMisc2, SearchEngines)
184+
.AppendLine();
185+
186+
sb.AppendLabelWithColor(ColorConfig, "Priority engines", ColorMisc2, PriorityEngines)
187+
.AppendLine();
187188

188189

189190
string snAuth = Config.SauceNaoAuth;
190191
bool snNull = String.IsNullOrWhiteSpace(snAuth);
191192

192193
if (!snNull) {
193-
Append(keyColor, "SauceNao authentication", white, snAuth);
194+
sb.AppendLabelWithColor(ColorConfig, "SauceNao authentication", ColorMisc2,
195+
snAuth).AppendLine();
194196
}
195197

196198
string imgurAuth = Config.ImgurAuth;
197199
bool imgurNull = String.IsNullOrWhiteSpace(imgurAuth);
198200

199201
if (!imgurNull) {
200-
Append(keyColor, "Imgur authentication", white, imgurAuth);
202+
sb.AppendLabelWithColor(ColorConfig, "Imgur authentication", ColorMisc2,
203+
imgurAuth).AppendLine();
201204
}
202205

203-
Append(keyColor, "Auto filtering", white, FilterResults);
204-
Append(keyColor, "Image upload service", white, imgurNull ? "ImgOps" : "Imgur");
205-
Append(keyColor, "Config location", white, ConfigLocation);
206+
sb.AppendLabelWithColor(ColorConfig, "Auto filtering", ColorMisc2, FilterResults)
207+
.AppendLine();
208+
209+
sb.AppendLabelWithColor(ColorConfig, "Image upload service", ColorMisc2,
210+
imgurNull ? "ImgOps" : "Imgur").AppendLine();
211+
212+
var cfgDirectoryName = new FileInfo(ConfigLocation).Directory.Name;
213+
206214

215+
sb.AppendLabelWithColor(ColorConfig, "Config location", ColorMisc2, cfgDirectoryName)
216+
.AppendLine();
207217

208-
void Append(Color ck, string s, Color cv, object o) =>
209-
sb.AppendKeyValueWithColor(ck, s, cv, o).AppendLine();
210218

211219
return sb.ToString();
212220
}

SmartImage/Engines/Other/IqdbEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private BasicSearchResult ParseResult(HtmlNodeCollection tr)
8282
return i;
8383
}
8484

85-
85+
[DebuggerHidden]
8686
public override FullSearchResult GetResult(string url)
8787
{
8888
var sr = base.GetResult(url);

SmartImage/Engines/Other/TidderEngine.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public override FullSearchResult GetResult(string url)
4444
var findings = documentNode.SelectNodes("//*[contains(@class, 'findings-row')]");
4545

4646
if (findings == null || !findings.Any()) {
47+
sr.Filter = true;
4748
return sr;
4849
}
4950

SmartImage/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private static void Main(string[] args)
9696

9797

9898
// Exit if no image is given
99-
if (String.IsNullOrWhiteSpace(SearchConfig.Config.Image)) {
99+
if (!SearchConfig.Config.HasImage) {
100100
return;
101101
}
102102

SmartImage/Searching/FullSearchResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ private void AppendResultInfo(StringBuilder sb, string name, string? value, bool
316316
}
317317

318318
string? valueStr = value.AddColor(newColor);
319-
sb.Append($"\t{NConsole.ANSI_RESET}{name}: {valueStr}{NConsole.ANSI_RESET}\n");
319+
sb.Append($"\t{Formatting.ANSI_RESET}{name}: {valueStr}{Formatting.ANSI_RESET}\n");
320+
320321
}
321322
}
322323

0 commit comments

Comments
 (0)