Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
repl-interacter.hh
Go to the documentation of this file.
1#pragma once
3
5#include "nix/util/finally.hh"
6#include "nix/util/fun.hh"
8#include "nix/util/types.hh"
9#include <filesystem>
10#include <functional>
11#include <string>
12
13namespace nix {
14
15namespace detail {
19{
20 virtual StringSet completePrefix(const std::string & prefix) = 0;
21 virtual ~ReplCompleterMixin() = default;
22};
23}; // namespace detail
24
25enum class ReplPromptType {
26 ReplPrompt,
27 ContinuationPrompt,
28};
29
31{
32public:
33 using Guard = Finally<fun<void()>>;
34
35 virtual Guard init(detail::ReplCompleterMixin * repl) = 0;
37 virtual bool getLine(std::string & input, ReplPromptType promptType) = 0;
38 virtual ~ReplInteracter() {};
39};
40
41class ReadlineLikeInteracter : public virtual ReplInteracter
42{
43 std::filesystem::path historyFile;
44 bool isInteractive = nix::isTTY(getStandardInput());
45
46public:
47 ReadlineLikeInteracter(std::filesystem::path historyFile)
48 : historyFile(std::move(historyFile))
49 {
50 }
51
52 virtual Guard init(detail::ReplCompleterMixin * repl) override;
53 virtual bool getLine(std::string & input, ReplPromptType promptType) override;
54 virtual ~ReadlineLikeInteracter() override;
55};
56
57}; // namespace nix
Definition finally.hh:15
virtual bool getLine(std::string &input, ReplPromptType promptType) override
Definition repl-interacter.cc:181
Definition repl-interacter.hh:31
virtual bool getLine(std::string &input, ReplPromptType promptType)=0
Definition fun.hh:19
File descriptor operations for almost arbitrary file descriptors.
Descriptor getStandardInput()
Definition file-descriptor.hh:226
Definition repl-interacter.hh:19
bool isTTY(Descriptor fd)
Definition terminal.cc:68
std::set< std::string, std::less<> > StringSet
Definition types.hh:45