@@ -60,6 +60,22 @@ public static partial class Program
6060 /// </summary>
6161 internal static SearchClient Client { get ; private set ; } = new ( Config ) ;
6262
63+ private static Dictionary < string , string > desc = new ( )
64+ {
65+ [ "Ctrl" ] = "Load direct" ,
66+ [ "Alt" ] = "Show other" ,
67+ [ "Shift" ] = "Open raw" ,
68+ [ "Alt+Ctrl" ] = "Download" ,
69+
70+ } ;
71+
72+ private static Dictionary < string , string > desc2 = new ( )
73+ {
74+
75+ [ "F1" ] = "Show filtered results" ,
76+ [ "F2" ] = "Refine" ,
77+ [ "F5" ] = "Refresh"
78+ } ;
6379
6480 /// <summary>
6581 /// Console UI for search results
@@ -68,14 +84,9 @@ public static partial class Program
6884 {
6985 Options = new List < ConsoleOption > ( ) ,
7086
71- Description = "Press the result number to open in browser\n " . AddColor ( Elements . ColorOther ) +
72- $ "{ "Ctrl:" . AddColor ( Elements . ColorKey ) } Load direct | " +
73- $ "{ "Alt:" . AddColor ( Elements . ColorKey ) } Show other | " +
74- $ "{ "Shift:" . AddColor ( Elements . ColorKey ) } Open raw | " +
75- $ "{ "Alt+Ctrl:" . AddColor ( Elements . ColorKey ) } Download\n " +
76- $ "{ "F1:" . AddColor ( Elements . ColorKey ) } Show filtered results | " +
77- $ "{ "F2:" . AddColor ( Elements . ColorKey ) } Refine | " +
78- $ "{ "F5:" . AddColor ( Elements . ColorKey ) } Refresh",
87+ Description = "Press the result number to open in browser\n " . AddColor ( Elements . ColorOther )
88+ + Elements . GetMapString ( desc , Elements . ColorKey ) + '\n '
89+ + Elements . GetMapString ( desc2 , Elements . ColorKey ) ,
7990
8091 Functions = new ( )
8192 {
@@ -116,7 +127,12 @@ public static partial class Program
116127 await Client . RefineSearchAsync ( ) ;
117128 }
118129 catch ( Exception e ) {
119- qmsg ( $ "Error: { e . Message . AddColor ( Elements . ColorError ) } ") ;
130+ string s = $ "Error: { e . Message . AddColor ( Elements . ColorError ) } ";
131+
132+ Console . WriteLine (
133+ $ "\n { Strings . Constants . CHEVRON } { s } ") ;
134+
135+ ConsoleManager . WaitForTimeSpan ( TimeSpan . FromSeconds ( 2 ) ) ;
120136
121137 ResultDialog . Options . Clear ( ) ;
122138
@@ -131,14 +147,6 @@ public static partial class Program
131147 }
132148 } ;
133149
134- private static void qmsg ( string s )
135- {
136- Console . WriteLine (
137- $ "\n { Strings . Constants . CHEVRON } { s } ") ;
138-
139- ConsoleManager . WaitForTimeSpan ( TimeSpan . FromSeconds ( 2 ) ) ;
140- }
141-
142150 #endregion
143151
144152
@@ -182,9 +190,14 @@ private static async Task Main(string[] args)
182190 if ( ! await Cli . HandleArguments ( ) )
183191 return ;
184192
185- ResultDialog . Subtitle = $ "SE: { Config . SearchEngines } " +
186- $ "| PE: { Config . PriorityEngines } " +
187- $ "| Filtering: { Elements . ToToggleString ( Config . Filtering ) } ";
193+ var map = new Dictionary < string , string > ( )
194+ {
195+ [ "SE" ] = Config . SearchEngines . ToString ( ) ,
196+ [ "PE" ] = Config . PriorityEngines . ToString ( ) ,
197+ [ "Filtering" ] = Elements . GetToggleString ( Config . Filtering )
198+ } ;
199+
200+ ResultDialog . Subtitle = Elements . GetMapString ( map ) ;
188201
189202
190203 _ctsSearch = new ( ) ;
@@ -202,7 +215,6 @@ private static async Task Main(string[] args)
202215
203216 ConsoleManager . UI . ProgressIndicator . Instance . Start ( _ctsProgress ) ;
204217
205-
206218 // Show results
207219 _searchTask = Client . RunSearchAsync ( _ctsSearch . Token ) ;
208220 _continueTask = Client . RunContinueAsync ( _ctsContinue . Token ) ;
@@ -213,9 +225,7 @@ private static async Task Main(string[] args)
213225 ResultDialog . Options . Add ( _originalResult ) ;
214226
215227 await ResultDialog . ReadInputAsync ( _ctsReadInput . Token ) ;
216-
217228
218- // if (!Config.OutputOnly) { }
219229
220230 await _searchTask ;
221231
@@ -226,75 +236,23 @@ private static async Task Main(string[] args)
226236 //ignored
227237 }
228238
229-
230239 /*Client.Dispose();
231240 Client.Reset();
232241 */
233242
234- //todo
235- Debug . WriteLine ( "done" ) ;
236-
237- // ResultDialog.Display(false);
238-
239- // if (Config.OutputOnly) { }
240-
241-
242243 }
243244
244245
245246 #region Event handlers
246247
247- private static void OnCancel ( object o , ConsoleCancelEventArgs eventArgs )
248+ private static void OnCancel ( object sender , ConsoleCancelEventArgs eventArgs )
248249 {
249- /*ResultDialog.Options.Clear();
250- ResultDialog.Options.Add(_originalResult);*/
251-
252-
253- // ResultDialog.Options.Clear();
254- // ResultDialog.Refresh();
255250 _ctsSearch . Cancel ( ) ;
256251 _ctsContinue . Cancel ( ) ;
257252 // _ctsReadInput.Cancel();
258253
259254 eventArgs . Cancel = true ;
260-
261- // _cancellationTokenSource = new();
262-
263- // ResultDialog.Refresh();
264- // await ResultDialog.ReadInputAsync();
265-
266255 SystemSounds . Hand . Play ( ) ;
267-
268- // var x = cd.ReadInputAsync();
269- // x.Wait();
270- // Debug.WriteLine($"{ResultDialog.Options.Count}|{Client.AllResults.Count}");
271- // ResultDialog = cd;
272-
273- var results = Client . Results ;
274-
275- var options = results . Select ( x =>
276- {
277- return x . GetConsoleOption ( ) ;
278- } ) . ToArray ( ) ;
279-
280- var cd = new ConsoleDialog ( )
281- {
282- Description = ResultDialog . Description ,
283- Header = ResultDialog . Header ,
284- Options = options ,
285- Subtitle = ResultDialog . Subtitle ,
286- } ;
287- // cd.ReadInput();
288-
289- /*ResultDialog.Options.Clear();
290-
291- foreach (ConsoleOption t in options) {
292- ResultDialog.Options.Add(t);
293- }*/
294- // await cd.ReadInputAsync();
295- // ResultDialog.Display(true);
296- qmsg ( "Cancelled" ) ;
297-
298256 }
299257
300258 private static void OnResultUpdated ( object sender , EventArgs result )
@@ -345,28 +303,41 @@ private static void OnResultCompleted(object sender, ResultCompletedEventArgs ev
345303 option . Function ( ) ;
346304 }
347305
348- var status = $ "Results: { Client . Results . Count } ";
306+ var map = new Dictionary < string , string > ( )
307+ {
308+ [ "Results" ] = Client . Results . Count . ToString ( ) ,
309+ } ;
349310
350311 if ( Config . Filtering ) {
351- status += $ " | Filtered: { Client . FilteredResults . Count } " ;
312+ map . Add ( " Filtered" , Client . FilteredResults . Count . ToString ( ) ) ;
352313 }
353314
354- status += $ " | Pending: { Client . PendingCount } " ;
315+ map . Add ( " Pending" , Client . PendingCount . ToString ( ) ) ;
355316
356- ResultDialog . Status = status ;
317+ string s ;
318+
319+ if ( _ctsSearch . IsCancellationRequested ) {
320+ s = "Cancelled" ;
321+ }
322+ else if ( Client . IsComplete ) {
323+ s = "Complete" ;
324+ }
325+ else {
326+ s = "Searching" ;
327+ }
357328
358- /*GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
359- GC.Collect();*/
329+ map . Add ( "Status" , s ) ;
360330
331+ var status = Elements . GetMapString ( map ) ;
332+
333+ ResultDialog . Status = status ;
361334 }
362335
363336 #endregion
364- private static CancellationTokenSource _ctsProgress ;
365337
338+ private static CancellationTokenSource _ctsProgress ;
366339 private static CancellationTokenSource _ctsReadInput ;
367-
368340 private static CancellationTokenSource _ctsContinue ;
369-
370341 private static CancellationTokenSource _ctsSearch ;
371342
372343 private static bool _isFilteredShown ;
0 commit comments