protected override async Task <Boolean> RunAsync(IConsoleRule <T> rule, IReaderMessage <T> message)
        {
            if (message.Count > 0 && Rules.TryGetValue(message[0], out ICommandRule <T> nrule))
            {
                return(await nrule.ExecuteAsync(message).ConfigureAwait(false));
            }

            if (DefaultHandler is null)
            {
                return(false);
            }

            return(await DefaultHandler.Invoke(this, message).ConfigureAwait(false));
        }
Exemple #2
0
        protected sealed override async Task <Boolean> RunAsync(IConsoleRule <ConsoleKeyInfo> rule, IReaderMessage <ConsoleKeyInfo> message)
        {
            if (_active is not null)
            {
                if (message.Value.Key != ConsoleKey.Escape)
                {
                    return(await _active.ExecuteAsync(message).ConfigureAwait(false));
                }

                _active = null;
                return(true);
            }

            if (Rules.Count < 1)
            {
                return(true);
            }

            Action action = message.Value.Key switch
            {
                ConsoleKey.Enter => Enter,
                ConsoleKey.UpArrow => RuleUp,
                ConsoleKey.DownArrow => RuleDown,
                _ => null
            };

            if (action is null)
            {
                return(true);
            }

            action.Invoke();
            await RefreshAsync().ConfigureAwait(false);

            return(true);
        }
 protected override Task <Boolean> DefaultHandlerAsync(IConsoleRule <String> rule, IReaderMessage <String> message)
 {
     return(TaskUtils.True);
 }
Exemple #4
0
 protected virtual Task <Boolean> RunAsync(IConsoleRule <T> rule, IReaderMessage <T> message)
 {
     return(TaskUtils.False);
 }