<commit_before>﻿#region --- License & Copyright Notice ---
/*
ConsoleFx CLI Library Suite
Copyright 2015-2018 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleFx.ConsoleExtensions
{
    public static partial class ConsoleEx
    {
        /// <summary>
        ///     Waits for the user to press the ENTER (RETURN) key
        /// </summary>
        public static void WaitForEnter()
        {
            WaitForKeys(ConsoleKey.Enter);
        }

        /// <summary>
        ///     Waits for the user to press any key on the keyboard. Displays the character representing
        ///     the pressed key in the console window.
        /// </summary>
        /// <returns>Information about the pressed key</returns>
        public static ConsoleKeyInfo WaitForAnyKey()
        {
            return Console.ReadKey(intercept: true);
        }

        /// <summary>
        ///     Waits for any of a specified set of keys to be pressed by the user.
        /// </summary>
        /// <param name="keys">An array of characters representing the allowed set of characters.</param>
        /// <returns>The character pressed by the user</returns>
        public static char WaitForKeys(params char[] keys)
        {
            char key;
            do
            {
                key = Console.ReadKey(intercept: true).KeyChar;
            } while (Array.IndexOf(keys, key) < 0);
            return key;
        }

        /// <summary>
        ///     Waits for any of a specified set of keys to be pressed by the user.
        /// </summary>
        /// <param name="keys">An array of characters representing the allowed set of characters.</param>
        /// <returns>The character pressed by the user</returns>
        public static char WaitForKeys(bool ignoreCase, params char[] keys)
        {
            char[] casedKeys = ignoreCase ? keys.Select(k => char.ToUpperInvariant(k)).ToArray() : keys;
            int keyIndex;
            do
            {
                char key = char.ToUpperInvariant(Console.ReadKey(intercept: true).KeyChar);
                keyIndex = Array.IndexOf(casedKeys, key);
            } while (keyIndex < 0);
            return keys[keyIndex];
        }

        /// <summary>
        ///     Waits for any of a specified set of keys to be pressed by the user.
        /// </summary>
        /// <param name="keys">An array of ConsoleKey objects representing the allowed set of keys.</param>
        /// <returns>The key pressed by the user</returns>
        public static ConsoleKey WaitForKeys(params ConsoleKey[] keys)
        {
            ConsoleKey key;
            do
            {
                key = Console.ReadKey(true).Key;
            } while (Array.IndexOf(keys, key) < 0);
            return key;
        }

        public static void WaitForKeysLoop(IEnumerable<KeyHandler> handlers,
            Action<ConsoleKey> postKeyPress = null, IEnumerable<ConsoleKey> escapeKeys = null)
        {
            if (handlers == null)
                throw new ArgumentNullException(nameof(handlers));
            if (!handlers.Any())
                throw new ArgumentException("Specify at least one handler.", nameof(handlers));

            if (escapeKeys == null)
                escapeKeys = new[] {ConsoleKey.Escape};

            if (handlers.Any(h => escapeKeys.Any(k => k == h.Key)))<commit_msg>Added more comments<commit_after>﻿#region --- License & Copyright Notice ---
/*
ConsoleFx CLI Library Suite
Copyright 2015-2018 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleFx.ConsoleExtensions
{
    public static partial class ConsoleEx
    {
        /// <summary>
        ///     Waits for the user to press the ENTER (RETURN) key
        /// </summary>
        public static void WaitForEnter()
        {
            WaitForKeys(ConsoleKey.Enter);
        }

        /// <summary>
        ///     Waits for the user to press any key on the keyboard. Displays the character representing
        ///     the pressed key in the console window.
        /// </summary>
        /// <returns>Information about the pressed key</returns>
        public static ConsoleKeyInfo WaitForAnyKey()
        {
            return Console.ReadKey(intercept: true);
        }

        /// <summary>
        ///     Waits for any of a specified set of keys to be pressed by the user.
        /// </summary>
        /// <param name="keys">An array of characters representing the allowed set of characters.</param>
        /// <returns>The character pressed by the user</returns>
        public static char WaitForKeys(params char[] keys)
        {
            char key;
            do
            {
                key = Console.ReadKey(intercept: true).KeyChar;
            } while (Array.IndexOf(keys, key) < 0);
            return key;
        }

        /// <summary>
        ///     Waits for any of a specified set of keys to be pressed by the user.
        /// </summary>
        /// <param name="keys">An array of characters representing the allowed set of characters.</param>
        /// <returns>The character pressed by the user</returns>
        public static char WaitForKeys(bool ignoreCase, params char[] keys)
        {
            char[] casedKeys = ignoreCase ? keys.Select(k => char.ToUpperInvariant(k)).ToArray() : keys;
            int keyIndex;
            do
            {
                char key = char.ToUpperInvariant(Console.ReadKey(intercept: true).KeyChar);
                keyIndex = Array.IndexOf(casedKeys, key);
            } while (keyIndex < 0);
            return keys[keyIndex];
        }

        /// <summary>
        ///     Waits for any of a specified set of keys to be pressed by the user.
        /// </summary>
        /// <param name="keys">An array of ConsoleKey objects representing the allowed set of keys.</param>
        /// <returns>The key pressed by the user</returns>
        public static ConsoleKey WaitForKeys(params ConsoleKey[] keys)
        {
            ConsoleKey key;
            do
            {
                key = Console.ReadKey(true).Key;
            } while (Array.IndexOf(keys, key) < 0);
            return key;
        }

        /// <summary>
        /// <para>Repeatedly prompts the user for a key press, until any of the specified escape keys are pressed.</para>
        /// <para>If the pressed key if available in the specified handlers, the corresponding handler is called. If not, it is ignored and the loop continues.</para>
        /// </summary>
        /// <param name="handlers">Collection of keys to handle and their handlers.</param>
        /// <param name="postKeyPress">Optional action to run after any key press, not counting the ignored keys and escape keys.</param>
        /// <param name="escapeKeys">The keys that will break the loop. If not specified, defaults to the escape key.</param>
        public static void WaitForKeysLoop(IEnumerable<KeyHandler> handlers,
            Action<ConsoleKey> postKeyPress = null, IEnumerable<ConsoleKey> escapeKeys = null)
        {
            if (handlers == null)
                throw new ArgumentNullException(nameof(handlers));
            if (!handlers.Any())
                throw new ArgumentException("Specify at least one handler.", nameof(handlers));

            // If the escapeKeys parameter is not specified, default it to the Escape key.
            if (escapeKeys == null)
                escapeKeys = new[] {ConsoleKey.Escape};

            // Ensure that none of the escape keys are specified in the handlers.
            if (handlers.Any(h => escapeKeys.Any(k => k == h.Key)))
{'fraction_non_alphanumeric': 0.09607236917439597, 'fraction_numerical': 0.0034352456200618343, 'mean_word_length': 2.036856745479833, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2228423', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2142, 'n_words': 833}