2024-03-10 06:05:50 +00:00
|
|
|
#pragma once
|
|
|
|
/// @file
|
|
|
|
|
|
|
|
#include "finally.hh"
|
|
|
|
#include "types.hh"
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
/** Provides the completion hooks for the repl, without exposing its complete
|
|
|
|
* internals. */
|
|
|
|
struct ReplCompleterMixin {
|
|
|
|
virtual StringSet completePrefix(const std::string & prefix) = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class ReplPromptType {
|
|
|
|
ReplPrompt,
|
|
|
|
ContinuationPrompt,
|
|
|
|
};
|
|
|
|
|
|
|
|
class ReplInteracter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using Guard = Finally<std::function<void()>>;
|
|
|
|
|
|
|
|
virtual Guard init(detail::ReplCompleterMixin * repl) = 0;
|
|
|
|
/** Returns a boolean of whether the interacter got EOF */
|
2024-03-10 06:05:50 +00:00
|
|
|
virtual bool getLine(std::string & input, ReplPromptType promptType) = 0;
|
2024-03-10 06:05:50 +00:00
|
|
|
virtual ~ReplInteracter(){};
|
|
|
|
};
|
|
|
|
|
|
|
|
class ReadlineLikeInteracter : public virtual ReplInteracter
|
|
|
|
{
|
|
|
|
std::string historyFile;
|
|
|
|
public:
|
|
|
|
ReadlineLikeInteracter(std::string historyFile)
|
|
|
|
: historyFile(historyFile)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual Guard init(detail::ReplCompleterMixin * repl) override;
|
2024-03-10 06:05:50 +00:00
|
|
|
virtual bool getLine(std::string & input, ReplPromptType promptType) override;
|
2024-03-10 06:05:50 +00:00
|
|
|
virtual ~ReadlineLikeInteracter() override;
|
|
|
|
};
|
|
|
|
|
2024-03-10 07:59:50 +00:00
|
|
|
class AutomationInteracter : public virtual ReplInteracter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutomationInteracter() = default;
|
|
|
|
virtual Guard init(detail::ReplCompleterMixin * repl) override;
|
|
|
|
virtual bool getLine(std::string & input, ReplPromptType promptType) override;
|
|
|
|
virtual ~AutomationInteracter() override = default;
|
|
|
|
};
|
|
|
|
|
2024-03-10 06:05:50 +00:00
|
|
|
};
|