Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
repl-interacter.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include "
nix/util/file-descriptor.hh
"
5
#include "
nix/util/finally.hh
"
6
#include "
nix/util/fun.hh
"
7
#include "
nix/util/terminal.hh
"
8
#include "
nix/util/types.hh
"
9
#include <filesystem>
10
#include <functional>
11
#include <string>
12
13
namespace
nix {
14
15
namespace
detail {
18
struct
ReplCompleterMixin
19
{
20
virtual
StringSet
completePrefix(
const
std::string & prefix) = 0;
21
virtual
~ReplCompleterMixin
() =
default
;
22
};
23
};
// namespace detail
24
25
enum class
ReplPromptType {
26
ReplPrompt,
27
ContinuationPrompt,
28
};
29
30
class
ReplInteracter
31
{
32
public
:
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
41
class
ReadlineLikeInteracter :
public
virtual
ReplInteracter
42
{
43
std::filesystem::path historyFile;
44
bool
isInteractive =
nix::isTTY
(
getStandardInput
());
45
46
public
:
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
nix::Finally
Definition
finally.hh:15
nix::ReadlineLikeInteracter::getLine
virtual bool getLine(std::string &input, ReplPromptType promptType) override
Definition
repl-interacter.cc:181
nix::ReplInteracter
Definition
repl-interacter.hh:31
nix::ReplInteracter::getLine
virtual bool getLine(std::string &input, ReplPromptType promptType)=0
nix::fun
Definition
fun.hh:19
file-descriptor.hh
File descriptor operations for almost arbitrary file descriptors.
nix::getStandardInput
Descriptor getStandardInput()
Definition
file-descriptor.hh:226
finally.hh
fun.hh
nix::detail::ReplCompleterMixin
Definition
repl-interacter.hh:19
terminal.hh
nix::isTTY
bool isTTY(Descriptor fd)
Definition
terminal.cc:68
types.hh
nix::StringSet
std::set< std::string, std::less<> > StringSet
Definition
types.hh:45
libcmd
include
nix
cmd
repl-interacter.hh
Generated by
1.18.0