<commit_before>/*
 * Modified for opendatacon to have a timeout in the blocking console I/O
 */

/*
 *
 * TinyCon - A tiny console library, written for C++
 * https://sourceforge.net/projects/tinycon/
 * ------------------------------------------------------
 * License:  BSD
 * Author:   Unix-Ninja | chris (at) unix-ninja (dot) com
 *
 * Terminal Console
 * Usage: tinyConsole tc("prompt>");
 *        tc.run();
 * 
 * When a command is entered, it will be passed to the trigger method for
 * processing. This is a blocking function.
 *
 * tinyConsole::trigger can be over-ridden in a derivative class to
 * change its functionality.
 *
 * Additionally, a check to the 'hotkeys' method is called for each
 * keypress, which can also be over-ridden in a dirivative class.
 *
 */

#include "tinycon.h"
#include <opendatacon/util.h>

#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32)
#include <termios.h>
#include <thread>
#include <unistd.h>
#include <utility>
int GetCharTimeout (const uint8_t timeout_tenths_of_seconds)
{
	static const size_t secinaday = 10*60*60*24;
	static size_t err_backoff = timeout_tenths_of_seconds;
	static const auto err = [](const std::string& msg)
	{
		if(auto log = odc::spdlog_get("ConsoleUI"))
			log->error("{}. Sleeping for {} ms", msg, 100*err_backoff);
		std::this_thread::sleep_for(std::chrono::milliseconds(100*err_backoff));

		if(err_backoff < secinaday)
			err_backoff *= 2;
		else if(err_backoff > secinaday)
			err_backoff = secinaday;
	};

	struct termios oldt{}, newt{};
	int ch = 0;
<commit_msg>console was blocking shutdown if it couldn't get terminal attributes<commit_after>/*
 * Modified for opendatacon to have a timeout in the blocking console I/O
 */

/*
 *
 * TinyCon - A tiny console library, written for C++
 * https://sourceforge.net/projects/tinycon/
 * ------------------------------------------------------
 * License:  BSD
 * Author:   Unix-Ninja | chris (at) unix-ninja (dot) com
 *
 * Terminal Console
 * Usage: tinyConsole tc("prompt>");
 *        tc.run();
 * 
 * When a command is entered, it will be passed to the trigger method for
 * processing. This is a blocking function.
 *
 * tinyConsole::trigger can be over-ridden in a derivative class to
 * change its functionality.
 *
 * Additionally, a check to the 'hotkeys' method is called for each
 * keypress, which can also be over-ridden in a dirivative class.
 *
 */

#include "tinycon.h"
#include <opendatacon/util.h>

#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32)
#include <termios.h>
#include <thread>
#include <unistd.h>
#include <utility>
int GetCharTimeout (const uint8_t timeout_tenths_of_seconds)
{
	static const size_t secinaday = 10*60*60*24;
	static size_t err_backoff = timeout_tenths_of_seconds;
	static auto last_error_time = odc::msSinceEpoch();
	static const auto err = [timeout_tenths_of_seconds](const std::string& msg)
	{
		auto now = odc::msSinceEpoch();
		if(now >= last_error_time+100*err_backoff)
		{
			if(auto log = odc::spdlog_get("ConsoleUI"))
				log->error("{}. Supressing next error for {} ms", msg, 100*err_backoff);
			if(err_backoff < secinaday)
				err_backoff *= 2;
			else if(err_backoff > secinaday)
				err_backoff = secinaday;
		}
		std::this_thread::sleep_for(std::chrono::milliseconds(100*timeout_tenths_of_seconds));
	};

	struct termios oldt{}, newt{};
	int ch = 0;

{'fraction_non_alphanumeric': 0.15281501340482573, 'fraction_numerical': 0.01459636580280012, 'mean_word_length': 3.6638888888888888, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 20, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '3353930', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1118, 'n_words': 326}