Performance improvement

This commit is contained in:
Mbucari 2023-07-02 22:23:29 -06:00
parent 83402028fd
commit db2b10d2a4
3 changed files with 47 additions and 47 deletions

View File

@ -30,7 +30,6 @@ internal class ConsoleProgressBar
} }
} }
private double m_Progress; private double m_Progress;
private TimeSpan m_RemainingTime; private TimeSpan m_RemainingTime;
private int m_LastWriteLength = 0; private int m_LastWriteLength = 0;
@ -71,7 +70,7 @@ internal class ConsoleProgressBar
public void Clear() public void Clear()
=> Output.Write( => Output.Write(
new string('\b', m_LastWriteLength) new string('\b', m_LastWriteLength) +
+ new string(' ', m_LastWriteLength) new string(' ', m_LastWriteLength) +
+ new string('\b', m_LastWriteLength)); new string('\b', m_LastWriteLength));
} }

View File

@ -16,9 +16,7 @@ internal class HelpVerb
/// <summary> /// <summary>
/// Create a base <see cref="HelpText"/> for <see cref="LibationCli"/> /// Create a base <see cref="HelpText"/> for <see cref="LibationCli"/>
/// </summary> /// </summary>
public static HelpText CreateHelpText() public static HelpText CreateHelpText() => new HelpText
{
var auto = new HelpText
{ {
AutoVersion = false, AutoVersion = false,
AutoHelp = false, AutoHelp = false,
@ -26,8 +24,6 @@ internal class HelpVerb
AdditionalNewLineAfterOption = true, AdditionalNewLineAfterOption = true,
MaximumDisplayWidth = 80 MaximumDisplayWidth = 80
}; };
return auto;
}
/// <summary> /// <summary>
/// Get the <see cref="HelpType"/>'s <see cref="HelpText"/> /// Get the <see cref="HelpType"/>'s <see cref="HelpText"/>
@ -43,8 +39,8 @@ internal class HelpVerb
} }
else else
{ {
helpText.AddDashesToOption = true;
helpText.AutoHelp = true; helpText.AutoHelp = true;
helpText.AddDashesToOption = true;
helpText.AddOptions(result); helpText.AddOptions(result);
} }
return helpText; return helpText;

View File

@ -3,10 +3,11 @@ using CommandLine;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace LibationCli.Options namespace LibationCli.Options;
{
[Verb("search", HelpText = "Search for books in your library")] [Verb("search", HelpText = "Search for books in your library")]
internal class SearchOptions : OptionsBase internal class SearchOptions : OptionsBase
{ {
@ -20,20 +21,25 @@ namespace LibationCli.Options
Console.WriteLine($"Found {results.Count} matching results."); Console.WriteLine($"Found {results.Count} matching results.");
const string nextPrompt = "Press any key for the next 10 results or Esc for all results"; const int numResults = 10;
string nextPrompt = "Press any key for the next " + numResults + " results or Esc for all results";
bool waitForNextBatch = true; bool waitForNextBatch = true;
for (int i = 0; i < results.Count; i += 10) for (int i = 0; i < results.Count; i += numResults)
{ {
foreach (var doc in results.Skip(i).Take(10)) var sb = new StringBuilder();
Console.WriteLine(getDocDisplay(doc.Doc)); for (int j = i; j < int.Min(results.Count, i + numResults); j++)
sb.AppendLine(getDocDisplay(results[j].Doc));
Console.Write(sb.ToString());
if (waitForNextBatch) if (waitForNextBatch)
{ {
Console.Write(nextPrompt); Console.Write(nextPrompt);
waitForNextBatch = Console.ReadKey(intercept: true).Key != ConsoleKey.Escape; waitForNextBatch = Console.ReadKey(intercept: true).Key != ConsoleKey.Escape;
ReplaceConsoleText(Console.Out, nextPrompt.Length, ""); ReplaceConsoleText(Console.Out, nextPrompt.Length, "");
Console.SetCursorPosition(0, Console.CursorTop); Console.CursorLeft = 0;
} }
} }
@ -47,4 +53,3 @@ namespace LibationCli.Options
return $"[{id.StringValue}] - {title.StringValue}"; return $"[{id.StringValue}] - {title.StringValue}";
} }
} }
}