Skip to content

Commit efa96f1

Browse files
committed
v3.0.3 RC 2
1 parent 4f6cbf5 commit efa96f1

File tree

4 files changed

+124
-24
lines changed

4 files changed

+124
-24
lines changed

SmartImage 3/Mode/Shell/Assets/UI.Styles.cs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@ namespace SmartImage.Mode.Shell.Assets;
1616
// todo: possible overkill with caching
1717
internal static partial class UI
1818
{
19-
internal static readonly Attribute Atr_Green_Black = Attribute.Make(Color.Green, Color.Black);
20-
internal static readonly Attribute Atr_BrightGreen_White = Attribute.Make(Color.BrightGreen, Color.White);
21-
internal static readonly Attribute Atr_BrightGreen_Gray = Attribute.Make(Color.BrightGreen, Color.Gray);
22-
internal static readonly Attribute Atr_BrightRed_White = Attribute.Make(Color.BrightRed, Color.White);
23-
internal static readonly Attribute Atr_BrightRed_Gray = Attribute.Make(Color.BrightRed, Color.Gray);
24-
internal static readonly Attribute Atr_Brown_White = Attribute.Make(Color.Brown, Color.White);
25-
internal static readonly Attribute Atr_Red_Black = Attribute.Make(Color.Red, Color.Black);
26-
internal static readonly Attribute Atr_Red_White = Attribute.Make(Color.Red, Color.White);
27-
internal static readonly Attribute Atr_Red_DarkGray = Attribute.Make(Color.Red, Color.DarkGray);
28-
internal static readonly Attribute Atr_BrightYellow_Black = Attribute.Make(Color.BrightYellow, Color.Black);
19+
internal static readonly Attribute Atr_Green_Black = Attribute.Make(Color.Green, Color.Black);
20+
internal static readonly Attribute Atr_Green_White = Attribute.Make(Color.Green, Color.White);
21+
internal static readonly Attribute Atr_Green_Gray = Attribute.Make(Color.Green, Color.Gray);
22+
internal static readonly Attribute Atr_Green_DarkGray = Attribute.Make(Color.Green, Color.DarkGray);
23+
internal static readonly Attribute Atr_BrightGreen_White = Attribute.Make(Color.BrightGreen, Color.White);
24+
internal static readonly Attribute Atr_BrightGreen_Gray = Attribute.Make(Color.BrightGreen, Color.Gray);
25+
internal static readonly Attribute Atr_BrightRed_White = Attribute.Make(Color.BrightRed, Color.White);
26+
internal static readonly Attribute Atr_BrightRed_Gray = Attribute.Make(Color.BrightRed, Color.Gray);
27+
internal static readonly Attribute Atr_Brown_White = Attribute.Make(Color.Brown, Color.White);
28+
internal static readonly Attribute Atr_Red_Black = Attribute.Make(Color.Red, Color.Black);
29+
internal static readonly Attribute Atr_Red_White = Attribute.Make(Color.Red, Color.White);
30+
internal static readonly Attribute Atr_Red_DarkGray = Attribute.Make(Color.Red, Color.DarkGray);
31+
internal static readonly Attribute Atr_BrightYellow_Black = Attribute.Make(Color.BrightYellow, Color.Black);
32+
2933
internal static readonly Attribute Atr_White_Black = Attribute.Make(Color.White, Color.Black);
3034
internal static readonly Attribute Atr_White_Blue = Attribute.Make(Color.White, Color.Blue);
3135
internal static readonly Attribute Atr_White_Cyan = Attribute.Make(Color.White, Color.Cyan);
@@ -78,13 +82,20 @@ internal static partial class UI
7882

7983
internal static readonly ColorScheme Cs_Btn2 = new()
8084
{
81-
Normal = Atr_Blue_White,
85+
Normal = Atr_BrightGreen_White,
8286
Disabled = Atr_DarkGray_White,
83-
HotNormal = Atr_Blue_White,
84-
HotFocus = Atr_BrightBlue_Gray,
85-
Focus = Atr_BrightBlue_Gray
87+
HotNormal = Atr_BrightGreen_White,
88+
HotFocus = Atr_BrightGreen_Gray,
89+
Focus = Atr_BrightGreen_Gray
90+
};
91+
internal static readonly ColorScheme Cs_Btn2x = new()
92+
{
93+
Normal = Atr_Green_White,
94+
Disabled = Atr_DarkGray_White,
95+
HotNormal = Atr_Green_White,
96+
HotFocus = Atr_Green_Gray,
97+
Focus = Atr_Green_Gray
8698
};
87-
8899
internal static readonly ColorScheme Cs_Btn3 = new()
89100
{
90101
Normal = Atr_Black_DarkGray,

SmartImage 3/Mode/Shell/Assets/UI.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Kantan.Net.Utilities;
1111
using SmartImage.Lib.Engines;
1212
using Terminal.Gui;
13+
using Attribute = Terminal.Gui.Attribute;
1314

1415
#endregion
1516

@@ -193,4 +194,10 @@ internal static void OnEngineSelected(ListView lv, ListViewItemEventArgs lvie, r
193194
lv.SetNeedsDisplay();
194195
Debug.WriteLine($"{val} {args.Item} -> {e} {isMarked}", nameof(OnEngineSelected));
195196
}*/
197+
public static ColorScheme NormalizeHot(this ColorScheme cs)
198+
{
199+
cs.HotFocus = cs.Focus;
200+
cs.HotNormal = cs.Normal;
201+
return cs;
202+
}
196203
}

SmartImage 3/Mode/Shell/ShellMode.Handlers.cs

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
using Clipboard = Novus.Win32.Clipboard;
1919
using Microsoft.VisualBasic.FileIO;
2020
using Novus.Win32.Structures.User32;
21+
using SmartImage.Lib.Engines;
2122
using SmartImage.Lib.Utilities;
23+
using Attribute = Terminal.Gui.Attribute;
2224
using FileSystem = Novus.OS.FileSystem;
2325

2426
namespace SmartImage.Mode.Shell;
@@ -229,7 +231,7 @@ private void Cancel_Clicked()
229231
m_token.Cancel();
230232
m_tokenu.Cancel();
231233
Lbl_Status2.ColorScheme = UI.Cs_Lbl4;
232-
Lbl_Status2.Text = R2.Inf_Cancel;
234+
Lbl_Status2.Text = R2.Inf_Cancel;
233235
Lbl_Status2.SetNeedsDisplay();
234236
Btn_Restart.Enabled = true;
235237
Application.MainLoop.RemoveIdle(m_runIdleTok);
@@ -306,4 +308,70 @@ private void NextQueue()
306308
SetInputText(n);
307309
}
308310
}
311+
312+
private static readonly Dictionary<BaseSearchEngine, ColorScheme> Colors = new()
313+
{
314+
};
315+
316+
private ColorScheme? Results_RowColor(TableView.RowColorGetterArgs r)
317+
{
318+
// var eng=args.Table.Rows[args.RowIndex]["Engine"];
319+
320+
ColorScheme? cs = null;
321+
322+
var ar = r.Table.Rows[r.RowIndex].ItemArray;
323+
324+
var eng = ar[0];
325+
326+
if (eng == null) {
327+
goto ret;
328+
}
329+
330+
var eng2 = Client.Engines.FirstOrDefault(f => eng.ToString().Contains(f.Name));
331+
332+
if (eng2 == null) {
333+
goto ret;
334+
}
335+
if (!Colors.ContainsKey(eng2)) {
336+
var colors = Enum.GetValues<Color>();
337+
338+
var cc = colors[Array.IndexOf(UI.EngineOptions, eng2.EngineOption) % UI.EngineOptions.Length];
339+
340+
Color cc2;
341+
342+
switch (cc) {
343+
case Color.Cyan:
344+
cc2 = Color.BrightCyan;
345+
break;
346+
default:
347+
cc2 = cc;
348+
break;
349+
}
350+
351+
cs = new ColorScheme()
352+
{
353+
Normal = Attribute.Make(cc, Color.Black),
354+
Focus = Attribute.Make(cc2, Color.DarkGray),
355+
356+
};
357+
cs = cs.NormalizeHot();
358+
359+
Colors.Add(eng2, cs);
360+
}
361+
else {
362+
cs = Colors[eng2];
363+
}
364+
365+
ret:
366+
return cs;
367+
}
368+
369+
private async void Reload_Clicked()
370+
{
371+
var q = Query;
372+
Cancel_Clicked();
373+
Restart_Clicked(true);
374+
// Query = q;
375+
// SetQuery(q.Uni.Value.ToString());
376+
}
309377
}

SmartImage 3/Mode/Shell/ShellMode.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static ShellMode() { }
130130
X = Pos.Right(Btn_Cancel),
131131
Y = Pos.Y(Btn_Cancel),
132132
Enabled = true,
133-
ColorScheme = UI.Cs_Btn2,
133+
ColorScheme = UI.Cs_Btn2x,
134134
};
135135

136136
private static readonly Label Lbl_InputInfo = new()
@@ -243,6 +243,16 @@ static ShellMode() { }
243243
Enabled = false
244244
};
245245

246+
private static readonly Button Btn_Reload = new("Reload")
247+
{
248+
X = Pos.X(Btn_Restart),
249+
Y = Pos.Bottom(Btn_Restart),
250+
251+
Height = Dim.Height(Btn_Cancel),
252+
ColorScheme = UI.Cs_Btn_Cancel,
253+
Enabled = false
254+
};
255+
246256
#endregion
247257

248258
#region Static
@@ -391,11 +401,7 @@ public ShellMode(string[] args)
391401
ShowHorizontalScrollIndicators = true,
392402
AlwaysShowHeaders = true,
393403

394-
RowColorGetter = args =>
395-
{
396-
// var eng=args.Table.Rows[args.RowIndex]["Engine"];
397-
return null;
398-
},
404+
RowColorGetter = Results_RowColor,
399405

400406
ShowHorizontalHeaderUnderline = true,
401407
ShowHorizontalHeaderOverline = true,
@@ -420,6 +426,7 @@ public ShellMode(string[] args)
420426
Cb_Queue.Toggled += Queue_Checked;
421427
Btn_Queue.Clicked += Queue_Dialog;
422428
Btn_Next.Clicked += Next_Clicked;
429+
// Btn_Reload.Clicked += Reload_Clicked;
423430

424431
Lbl_QueryUpload.Clicked += () =>
425432
{
@@ -612,6 +619,8 @@ internal void SetInputText(ustring s)
612619

613620
private async Task<bool> SetQuery(ustring text)
614621
{
622+
// TODO: IMPROVE
623+
615624
// Btn_Run.Enabled = false;
616625

617626
if (IsQueryReady() && Query.Uni.Value as string == text) {
@@ -645,6 +654,8 @@ private async Task<bool> SetQuery(ustring text)
645654

646655
Lbl_InputInfo.Text = $"Error: {e.Message}";
647656
Lbl_Status2.Text = ustring.Empty;
657+
Btn_Reload.Enabled = false;
658+
648659
}
649660

650661
UI.SetLabelStatus(Lbl_InputOk, null);
@@ -661,8 +672,8 @@ private async Task<bool> SetQuery(ustring text)
661672
};*/
662673

663674
using CancellationTokenSource cts = new();
664-
665-
Lbl_Status2.Text = $"Uploading...";
675+
676+
Lbl_Status2.Text = $"Uploading...";
666677

667678
UI.QueueProgress(cts, Pbr_Status);
668679

@@ -681,6 +692,7 @@ private async Task<bool> SetQuery(ustring text)
681692
Lbl_InputInfo.Text = $"Error: {e.Message}";
682693
Lbl_Status2.Text = ustring.Empty;
683694
// Btn_Run.Enabled = false;
695+
Btn_Reload.Enabled = false;
684696

685697
}
686698

@@ -694,6 +706,7 @@ private async Task<bool> SetQuery(ustring text)
694706
Pbr_Status.Fraction = 0;
695707
Lbl_Status2.Text = ustring.Empty;
696708
Btn_Delete.Enabled = false;
709+
Btn_Reload.Enabled = false;
697710

698711
return false;
699712
}
@@ -715,6 +728,7 @@ private async Task<bool> SetQuery(ustring text)
715728

716729
Tf_Input.ReadOnly = true;
717730
Btn_Delete.Enabled = true;
731+
Btn_Reload.Enabled = true;
718732

719733
return true;
720734
}

0 commit comments

Comments
 (0)