2012-05-03 11:25:13 +04:00
|
|
|
#ifndef shell_manager_hh_INCLUDED
|
|
|
|
#define shell_manager_hh_INCLUDED
|
|
|
|
|
2015-03-09 16:48:41 +03:00
|
|
|
#include "array_view.hh"
|
2014-04-08 00:25:44 +04:00
|
|
|
#include "env_vars.hh"
|
2015-09-03 15:53:17 +03:00
|
|
|
#include "string.hh"
|
|
|
|
#include "utils.hh"
|
2016-04-17 21:21:43 +03:00
|
|
|
#include "completion.hh"
|
2012-05-03 11:25:13 +04:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2014-01-28 00:28:38 +04:00
|
|
|
class Context;
|
2014-11-13 00:27:07 +03:00
|
|
|
|
2015-10-22 15:48:57 +03:00
|
|
|
struct ShellContext
|
|
|
|
{
|
|
|
|
ConstArrayView<String> params;
|
|
|
|
EnvVarMap env_vars;
|
|
|
|
};
|
|
|
|
|
2018-02-18 06:52:29 +03:00
|
|
|
|
|
|
|
struct EnvVarDesc
|
|
|
|
{
|
|
|
|
using Retriever = String (*)(StringView name, const Context&);
|
|
|
|
|
|
|
|
StringView str;
|
|
|
|
bool prefix;
|
|
|
|
Retriever func;
|
|
|
|
};
|
|
|
|
|
2012-05-03 11:25:13 +04:00
|
|
|
class ShellManager : public Singleton<ShellManager>
|
|
|
|
{
|
|
|
|
public:
|
2018-02-18 06:52:29 +03:00
|
|
|
ShellManager(ConstArrayView<EnvVarDesc> builtin_env_vars);
|
2012-05-03 11:25:13 +04:00
|
|
|
|
2015-06-08 15:34:08 +03:00
|
|
|
enum class Flags
|
|
|
|
{
|
|
|
|
None = 0,
|
2015-06-09 00:42:51 +03:00
|
|
|
WaitForStdout = 1
|
2015-06-08 15:34:08 +03:00
|
|
|
};
|
2017-03-15 20:55:34 +03:00
|
|
|
friend constexpr bool with_bit_ops(Meta::Type<Flags>) { return true; }
|
2015-06-08 15:34:08 +03:00
|
|
|
|
2015-03-13 16:39:18 +03:00
|
|
|
std::pair<String, int> eval(StringView cmdline, const Context& context,
|
|
|
|
StringView input = {},
|
2015-06-09 00:42:51 +03:00
|
|
|
Flags flags = Flags::WaitForStdout,
|
2015-10-22 15:48:57 +03:00
|
|
|
const ShellContext& shell_context = {});
|
2012-05-29 14:39:03 +04:00
|
|
|
|
2014-06-18 22:28:48 +04:00
|
|
|
String get_val(StringView name, const Context& context) const;
|
2012-05-03 11:25:13 +04:00
|
|
|
|
2016-04-17 21:21:43 +03:00
|
|
|
CandidateList complete_env_var(StringView prefix, ByteCount cursor_pos) const;
|
|
|
|
|
2012-05-03 11:25:13 +04:00
|
|
|
private:
|
2016-12-16 02:04:53 +03:00
|
|
|
String m_shell;
|
|
|
|
|
2018-02-18 06:52:29 +03:00
|
|
|
ConstArrayView<EnvVarDesc> m_env_vars;
|
2012-05-03 11:25:13 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // shell_manager_hh_INCLUDED
|