mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:27:34 +00:00
Shell: Fix job control and backgrounding
This patchset makes the shell capable of lazily resolving and executing sequences of commands, to allow for putting logical sequences in the background. In particular, it enables And/Or/Sequence nodes to be run in the background, and consequently unmarks them as `would_execute`. Doing so also fixes job control to an extent, as jobs are now capable of having 'tails', so sequences can be put in the background while preserving their following sequences.
This commit is contained in:
parent
a2a54f459f
commit
715e11f692
10 changed files with 180 additions and 151 deletions
25
Shell/AST.h
25
Shell/AST.h
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "Forward.h"
|
||||
#include "Job.h"
|
||||
#include <AK/InlineLinkedList.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/RefPtr.h>
|
||||
|
@ -174,13 +175,30 @@ public:
|
|||
pid_t pgid { -1 };
|
||||
};
|
||||
|
||||
struct NodeWithAction {
|
||||
mutable NonnullRefPtr<Node> node;
|
||||
enum Action {
|
||||
And,
|
||||
Or,
|
||||
Sequence,
|
||||
} action;
|
||||
|
||||
NodeWithAction(Node& node, Action action)
|
||||
: node(node)
|
||||
, action(action)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct Command {
|
||||
Vector<String> argv;
|
||||
NonnullRefPtrVector<Redirection> redirections;
|
||||
mutable RefPtr<Pipeline> pipeline;
|
||||
bool should_wait { true };
|
||||
bool is_pipe_source { false };
|
||||
bool should_notify_if_in_background { true };
|
||||
|
||||
mutable RefPtr<Pipeline> pipeline;
|
||||
Vector<NodeWithAction> next_chain;
|
||||
};
|
||||
|
||||
struct HitTestResult {
|
||||
|
@ -215,7 +233,7 @@ public:
|
|||
}
|
||||
|
||||
CommandValue(Vector<String> argv)
|
||||
: m_command({ move(argv), {}, {}, true, false, true })
|
||||
: m_command({ move(argv), {}, true, false, true, nullptr, {} })
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -424,7 +442,6 @@ private:
|
|||
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
|
||||
virtual HitTestResult hit_test_position(size_t) override;
|
||||
virtual String class_name() const override { return "And"; }
|
||||
virtual bool would_execute() const override { return true; }
|
||||
|
||||
RefPtr<Node> m_left;
|
||||
RefPtr<Node> m_right;
|
||||
|
@ -458,7 +475,6 @@ private:
|
|||
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
|
||||
virtual HitTestResult hit_test_position(size_t) override;
|
||||
virtual String class_name() const override { return "Background"; }
|
||||
virtual bool would_execute() const override { return m_command->would_execute(); }
|
||||
|
||||
RefPtr<Node> m_command;
|
||||
};
|
||||
|
@ -725,7 +741,6 @@ private:
|
|||
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
|
||||
virtual HitTestResult hit_test_position(size_t) override;
|
||||
virtual String class_name() const override { return "Or"; }
|
||||
virtual bool would_execute() const override { return true; }
|
||||
|
||||
RefPtr<Node> m_left;
|
||||
RefPtr<Node> m_right;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue