-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
284 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
local-repository-listing/ResultLister/ConsoleOutputLister.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using LocalRepositoryListing.Searcher; | ||
using R3; | ||
namespace LocalRepositoryListing.ResultProcessor; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ConsoleOutputLister"/> class with the specified search pattern. | ||
/// </summary> | ||
/// <param name="searcher">The <see cref="ISearcher"/> object representing the searcher.</param> | ||
/// <param name="searchPattern">The search pattern to match against the full names of the directories.</param> | ||
public class ConsoleOutputLister(ISearcher searcher, string searchPattern) : IResultLister | ||
{ | ||
/// <summary> | ||
/// The search pattern to match against the full names of the directories. | ||
/// </summary> | ||
private readonly string _searchPattern = searchPattern; | ||
private readonly ISearcher _searcher = searcher; | ||
|
||
public async ValueTask<int> ExecuteListing(CancellationToken cancellationToken) | ||
{ | ||
using var searchSubscription = _searcher.SearchResults.Subscribe(d => | ||
{ | ||
var fullName = d.FullName.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); | ||
|
||
if (string.IsNullOrEmpty(fullName) || (!string.IsNullOrEmpty(_searchPattern) && !fullName.Contains(_searchPattern))) | ||
{ | ||
return; | ||
} | ||
|
||
Console.WriteLine(fullName); | ||
}); | ||
|
||
cancellationToken.Register(searchSubscription.Dispose); | ||
|
||
try | ||
{ | ||
var searchTask = _searcher.Search(cancellationToken); | ||
|
||
while ( | ||
!cancellationToken.IsCancellationRequested | ||
&& !searchTask.IsCompleted | ||
&& !searchTask.IsFaulted | ||
&& !searchTask.IsCanceled | ||
) | ||
{ | ||
await Task.Delay(100, cancellationToken); | ||
} | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
searchSubscription.Dispose(); | ||
Console.Error.WriteLine("Search was cancelled."); | ||
return 1; | ||
} | ||
searchSubscription.Dispose(); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
local-repository-listing/ResultLister/FuzzyFinderListerBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Diagnostics; | ||
using LocalRepositoryListing.Searcher; | ||
using R3; | ||
|
||
namespace LocalRepositoryListing.ResultProcessor; | ||
|
||
/// <summary> | ||
/// Represents the base class for a fuzzy finder process. | ||
/// </summary> | ||
public abstract class FuzzyFinderListerBase : IResultLister | ||
{ | ||
/// <summary> | ||
/// Gets the name of the fuzzy finder. | ||
/// </summary> | ||
public abstract string FuzzyFinderName { get; } | ||
|
||
/// <summary> | ||
/// Gets the arguments for the processor. | ||
/// </summary> | ||
public ReadOnlyCollection<string> Arguments => _arguments.AsReadOnly(); | ||
private readonly string[] _arguments = []; | ||
|
||
private readonly ProcessStartInfo _processStartInfo; | ||
private readonly ISearcher _searcher; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FuzzyFinderListerBase"/> class. | ||
/// </summary> | ||
/// <param name="searcher">The <see cref="ISearcher"/> object representing the searcher.</param> | ||
/// <param name="arguments">The arguments for the processor.</param> | ||
public FuzzyFinderListerBase(ISearcher searcher, string[] arguments) | ||
{ | ||
_arguments = arguments; | ||
_processStartInfo = new ProcessStartInfo(FuzzyFinderName) | ||
{ | ||
// UseShellExecute is set to false to start the child process without using a shell | ||
UseShellExecute = false, | ||
RedirectStandardInput = true, | ||
// For Non-ASCII characters | ||
StandardInputEncoding = System.Text.Encoding.UTF8, | ||
Arguments = string.Join(" ", arguments), | ||
}; | ||
|
||
_searcher = searcher; | ||
} | ||
|
||
public ValueTask<int> ExecuteListing(CancellationToken cancellationToken) | ||
{ | ||
using var process = Process.Start(_processStartInfo); | ||
if (process == null) | ||
{ | ||
Console.Error.WriteLine($"Failed to start {FuzzyFinderName}"); | ||
return ValueTask.FromResult(1); | ||
} | ||
|
||
using var input = TextWriter.Synchronized(process.StandardInput); | ||
if (input == null) | ||
{ | ||
Console.Error.WriteLine($"Failed to get StandardInput of {FuzzyFinderName}"); | ||
return ValueTask.FromResult(1); | ||
} | ||
|
||
using var searchSubscription = _searcher.SearchResults.Subscribe(d => input.WriteLine(d.FullName.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar))); | ||
|
||
_ = _searcher.Search(cancellationToken); | ||
|
||
process.WaitForExit(); | ||
|
||
return ValueTask.FromResult(process.ExitCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace LocalRepositoryListing.ResultProcessor; | ||
|
||
public interface IResultLister | ||
{ | ||
/// <summary> | ||
/// Executes the listing operation. | ||
/// </summary> | ||
/// <param name="cancellationToken">The cancellation token.</param> | ||
/// <returns>A <see cref="ValueTask{TResult}"/> representing the asynchronous operation, yielding the result of the listing operation.</returns> | ||
public ValueTask<int> ExecuteListing(CancellationToken cancellationToken); | ||
} |
60 changes: 0 additions & 60 deletions
60
local-repository-listing/ResultProcessor/ConsoleOutputProcessor.cs
This file was deleted.
Oops, something went wrong.
82 changes: 0 additions & 82 deletions
82
local-repository-listing/ResultProcessor/FuzzyFinderProcessorBase.cs
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
local-repository-listing/ResultProcessor/ISearchResultProcessor.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.