mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
AppTests
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Govor.ConsoleClient.Commands;
|
||||
using Govor.ConsoleClient.Services.Interfaces;
|
||||
|
||||
namespace Govor.ConsoleClient.Services.Implementations;
|
||||
|
||||
public class InputPipeline : IInputPipeline
|
||||
{
|
||||
private readonly ICommandDispatcher _dispatcher;
|
||||
private readonly ILogger _logger;
|
||||
private IInteractiveCommand? _activeCommand;
|
||||
|
||||
public InputPipeline(ICommandDispatcher dispatcher, ILogger logger)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task ProcessInputAsync(string input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input)) return;
|
||||
|
||||
if (input.StartsWith("/"))
|
||||
{
|
||||
_activeCommand = null;
|
||||
|
||||
var commandInput = input[1..];
|
||||
var result = await _dispatcher.DispatchAsync(commandInput);
|
||||
|
||||
// If the command supports interactivity, save it as active
|
||||
if (result is IInteractiveCommand interactiveCommand && !interactiveCommand.IsCompleted)
|
||||
{
|
||||
_activeCommand = interactiveCommand;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_activeCommand != null)
|
||||
{
|
||||
await _activeCommand.HandleInputAsync(input);
|
||||
|
||||
if (_activeCommand.IsCompleted)
|
||||
_activeCommand = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Info($"Введите /help, чтобы узнать доступные команды!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user