2016-05-04 19:24:41 +02:00
|
|
|
/*****************************************************************************
|
2023-01-01 04:58:01 -06:00
|
|
|
* Copyright (c) 2014-2023 OpenRCT2 developers
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-05-04 19:24:41 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-03-11 18:15:44 +00:00
|
|
|
#pragma once
|
2015-05-19 03:53:37 +01:00
|
|
|
|
2018-06-22 22:59:46 +02:00
|
|
|
#include "../common.h"
|
|
|
|
|
#include "../localisation/FormatCodes.h"
|
|
|
|
|
|
2022-01-07 16:37:41 +01:00
|
|
|
#include <atomic>
|
2018-03-11 18:15:44 +00:00
|
|
|
#include <future>
|
2020-02-23 12:55:48 +00:00
|
|
|
#include <queue>
|
2018-03-11 18:15:44 +00:00
|
|
|
#include <string>
|
2015-05-19 03:53:37 +01:00
|
|
|
|
2018-03-13 13:14:02 +01:00
|
|
|
struct rct_drawpixelinfo;
|
2018-03-11 21:12:22 +00:00
|
|
|
struct TextInputSession;
|
2018-03-13 13:14:02 +01:00
|
|
|
|
2020-10-01 03:31:03 -06:00
|
|
|
enum class ConsoleInput : uint8_t
|
2017-06-10 16:10:23 +01:00
|
|
|
{
|
2020-10-01 03:31:03 -06:00
|
|
|
None,
|
|
|
|
|
LineClear,
|
|
|
|
|
LineExecute,
|
|
|
|
|
HistoryPrevious,
|
|
|
|
|
HistoryNext,
|
|
|
|
|
ScrollPrevious,
|
|
|
|
|
ScrollNext,
|
2018-02-14 09:42:26 +01:00
|
|
|
};
|
2017-06-10 16:10:23 +01:00
|
|
|
|
2018-03-11 19:46:03 +00:00
|
|
|
class InteractiveConsole
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-06-22 22:59:46 +02:00
|
|
|
virtual ~InteractiveConsole()
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-03-11 19:46:03 +00:00
|
|
|
|
2018-06-22 22:59:46 +02:00
|
|
|
void Execute(const std::string& s);
|
|
|
|
|
void WriteLine(const std::string& s);
|
|
|
|
|
void WriteLineError(const std::string& s);
|
|
|
|
|
void WriteLineWarning(const std::string& s);
|
|
|
|
|
void WriteFormatLine(const char* format, ...);
|
2018-03-11 19:46:03 +00:00
|
|
|
|
|
|
|
|
virtual void Clear() abstract;
|
|
|
|
|
virtual void Close() abstract;
|
2018-03-22 20:29:41 +00:00
|
|
|
virtual void Hide() abstract;
|
2020-10-16 00:13:52 +01:00
|
|
|
virtual void WriteLine(const std::string& s, FormatToken colourFormat) abstract;
|
2018-03-11 19:46:03 +00:00
|
|
|
};
|
|
|
|
|
|
2018-03-12 17:39:58 +00:00
|
|
|
class StdInOutConsole final : public InteractiveConsole
|
2018-03-11 19:46:03 +00:00
|
|
|
{
|
2020-02-23 12:55:48 +00:00
|
|
|
private:
|
|
|
|
|
std::queue<std::tuple<std::promise<void>, std::string>> _evalQueue;
|
2022-01-07 16:37:41 +01:00
|
|
|
std::atomic<bool> _isPromptShowing{};
|
2020-02-23 12:55:48 +00:00
|
|
|
|
2018-03-11 19:46:03 +00:00
|
|
|
public:
|
|
|
|
|
void Start();
|
2018-06-22 22:59:46 +02:00
|
|
|
std::future<void> Eval(const std::string& s);
|
2020-02-23 12:55:48 +00:00
|
|
|
void ProcessEvalQueue();
|
2018-03-11 19:46:03 +00:00
|
|
|
|
|
|
|
|
void Clear() override;
|
|
|
|
|
void Close() override;
|
2018-06-22 22:59:46 +02:00
|
|
|
void Hide() override
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
void WriteLine(const std::string& s)
|
|
|
|
|
{
|
|
|
|
|
InteractiveConsole::WriteLine(s);
|
|
|
|
|
}
|
2020-10-16 00:13:52 +01:00
|
|
|
void WriteLine(const std::string& s, FormatToken colourFormat) override;
|
2018-03-11 19:46:03 +00:00
|
|
|
};
|