Performance improvement
This commit is contained in:
parent
83402028fd
commit
db2b10d2a4
@ -30,7 +30,6 @@ internal class ConsoleProgressBar
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private double m_Progress;
|
||||
private TimeSpan m_RemainingTime;
|
||||
private int m_LastWriteLength = 0;
|
||||
@ -71,7 +70,7 @@ internal class ConsoleProgressBar
|
||||
|
||||
public void Clear()
|
||||
=> Output.Write(
|
||||
new string('\b', m_LastWriteLength)
|
||||
+ new string(' ', m_LastWriteLength)
|
||||
+ new string('\b', m_LastWriteLength));
|
||||
new string('\b', m_LastWriteLength) +
|
||||
new string(' ', m_LastWriteLength) +
|
||||
new string('\b', m_LastWriteLength));
|
||||
}
|
||||
|
||||
@ -16,9 +16,7 @@ internal class HelpVerb
|
||||
/// <summary>
|
||||
/// Create a base <see cref="HelpText"/> for <see cref="LibationCli"/>
|
||||
/// </summary>
|
||||
public static HelpText CreateHelpText()
|
||||
{
|
||||
var auto = new HelpText
|
||||
public static HelpText CreateHelpText() => new HelpText
|
||||
{
|
||||
AutoVersion = false,
|
||||
AutoHelp = false,
|
||||
@ -26,8 +24,6 @@ internal class HelpVerb
|
||||
AdditionalNewLineAfterOption = true,
|
||||
MaximumDisplayWidth = 80
|
||||
};
|
||||
return auto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the <see cref="HelpType"/>'s <see cref="HelpText"/>
|
||||
@ -43,8 +39,8 @@ internal class HelpVerb
|
||||
}
|
||||
else
|
||||
{
|
||||
helpText.AddDashesToOption = true;
|
||||
helpText.AutoHelp = true;
|
||||
helpText.AddDashesToOption = true;
|
||||
helpText.AddOptions(result);
|
||||
}
|
||||
return helpText;
|
||||
|
||||
@ -3,10 +3,11 @@ using CommandLine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LibationCli.Options
|
||||
{
|
||||
namespace LibationCli.Options;
|
||||
|
||||
[Verb("search", HelpText = "Search for books in your library")]
|
||||
internal class SearchOptions : OptionsBase
|
||||
{
|
||||
@ -20,20 +21,25 @@ namespace LibationCli.Options
|
||||
|
||||
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;
|
||||
|
||||
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))
|
||||
Console.WriteLine(getDocDisplay(doc.Doc));
|
||||
var sb = new StringBuilder();
|
||||
for (int j = i; j < int.Min(results.Count, i + numResults); j++)
|
||||
sb.AppendLine(getDocDisplay(results[j].Doc));
|
||||
|
||||
Console.Write(sb.ToString());
|
||||
|
||||
if (waitForNextBatch)
|
||||
{
|
||||
Console.Write(nextPrompt);
|
||||
waitForNextBatch = Console.ReadKey(intercept: true).Key != ConsoleKey.Escape;
|
||||
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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user