forked from lix-project/lix
jade
be2b87ed4d
This is definitely not a stable thing, but it does feel slightly crimes
to put it as an experimental feature. Shrug, up for bikeshedding.
Change-Id: I6ef176e3dee6fb1cac9c0a7a60d553a2c63ea728
58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
#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 */
|
|
virtual bool getLine(std::string & input, ReplPromptType promptType) = 0;
|
|
virtual ~ReplInteracter(){};
|
|
};
|
|
|
|
class ReadlineLikeInteracter : public virtual ReplInteracter
|
|
{
|
|
std::string historyFile;
|
|
public:
|
|
ReadlineLikeInteracter(std::string historyFile)
|
|
: historyFile(historyFile)
|
|
{
|
|
}
|
|
virtual Guard init(detail::ReplCompleterMixin * repl) override;
|
|
virtual bool getLine(std::string & input, ReplPromptType promptType) override;
|
|
virtual ~ReadlineLikeInteracter() override;
|
|
};
|
|
|
|
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;
|
|
};
|
|
|
|
};
|