summaryrefslogtreecommitdiff
path: root/src/shell_manager.hh
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2023-11-07 18:01:54 +1100
committerMaxime Coste <mawww@kakoune.org>2023-11-14 21:39:03 +1100
commit11f0ace9b6bf7cf618a42de7e37d9608d2d86d99 (patch)
tree5ad940ddb9c8286a33dbd86514c6d129df346758 /src/shell_manager.hh
parent719512b308f1d5165037775cb314094f1bb870ad (diff)
Make shell-script-candidates completer run in the background
Read output from the script as it comes and update the candidate list progressively. Disable updating of the list when a completion has been explicitely selected.
Diffstat (limited to 'src/shell_manager.hh')
-rw-r--r--src/shell_manager.hh23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/shell_manager.hh b/src/shell_manager.hh
index 7dc00f83..6b45961a 100644
--- a/src/shell_manager.hh
+++ b/src/shell_manager.hh
@@ -5,8 +5,13 @@
#include "env_vars.hh"
#include "string.hh"
#include "utils.hh"
+#include "unique_descriptor.hh"
#include "completion.hh"
+#include <signal.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
namespace Kakoune
{
@@ -27,6 +32,19 @@ struct EnvVarDesc
Retriever func;
};
+inline void closepid(int pid){ kill(pid, SIGTERM); int status = 0; waitpid(pid, &status, 0); }
+
+using UniqueFd = UniqueDescriptor<::close>;
+using UniquePid = UniqueDescriptor<closepid>;
+
+struct Shell
+{
+ UniquePid pid;
+ UniqueFd in;
+ UniqueFd out;
+ UniqueFd err;
+};
+
class ShellManager : public Singleton<ShellManager>
{
public:
@@ -44,6 +62,11 @@ public:
Flags flags = Flags::WaitForStdout,
const ShellContext& shell_context = {});
+ Shell spawn(StringView cmdline,
+ const Context& context,
+ bool open_stdin,
+ const ShellContext& shell_complete = {});
+
Vector<String> get_val(StringView name, const Context& context) const;
CandidateList complete_env_var(StringView prefix, ByteCount cursor_pos) const;