mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-04 10:18:51 +00:00
Shell: Implement AK::Formatter::format() for AST::Command
...and use that to display jobs.
This commit is contained in:
parent
05ff75c321
commit
8de70e8ce7
Notes:
sideshowbarker
2024-07-19 01:42:44 +09:00
Author: https://github.com/alimpfard
Commit: 8de70e8ce7
Pull-request: https://github.com/SerenityOS/serenity/pull/3852
Reviewed-by: https://github.com/asynts
3 changed files with 65 additions and 3 deletions
|
@ -37,6 +37,50 @@
|
||||||
|
|
||||||
//#define EXECUTE_DEBUG
|
//#define EXECUTE_DEBUG
|
||||||
|
|
||||||
|
void AK::Formatter<Shell::AST::Command>::format(TypeErasedFormatParams&, FormatBuilder& builder, const Shell::AST::Command& value)
|
||||||
|
{
|
||||||
|
if (m_sign_mode != FormatBuilder::SignMode::Default)
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
if (m_alternative_form)
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
if (m_zero_pad)
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
if (m_mode != Mode::Default && m_mode != Mode::String)
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
if (m_width != value_not_set && m_precision != value_not_set)
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
|
||||||
|
bool first = true;
|
||||||
|
for (auto& arg : value.argv) {
|
||||||
|
if (!first)
|
||||||
|
builder.put_literal(" ");
|
||||||
|
first = false;
|
||||||
|
builder.put_literal(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!value.next_chain.is_empty()) {
|
||||||
|
for (auto& command : value.next_chain) {
|
||||||
|
switch (command.action) {
|
||||||
|
case Shell::AST::NodeWithAction::And:
|
||||||
|
builder.put_literal(" && ");
|
||||||
|
break;
|
||||||
|
case Shell::AST::NodeWithAction::Or:
|
||||||
|
builder.put_literal(" || ");
|
||||||
|
break;
|
||||||
|
case Shell::AST::NodeWithAction::Sequence:
|
||||||
|
builder.put_literal("; ");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.put_literal("(");
|
||||||
|
builder.put_literal(command.node->class_name());
|
||||||
|
builder.put_literal("...)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!value.should_wait)
|
||||||
|
builder.put_literal("&");
|
||||||
|
}
|
||||||
|
|
||||||
namespace Shell::AST {
|
namespace Shell::AST {
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
|
|
16
Shell/AST.h
16
Shell/AST.h
|
@ -29,6 +29,7 @@
|
||||||
#include "Forward.h"
|
#include "Forward.h"
|
||||||
#include "Job.h"
|
#include "Job.h"
|
||||||
#include "NodeVisitor.h"
|
#include "NodeVisitor.h"
|
||||||
|
#include <AK/Format.h>
|
||||||
#include <AK/InlineLinkedList.h>
|
#include <AK/InlineLinkedList.h>
|
||||||
#include <AK/NonnullRefPtr.h>
|
#include <AK/NonnullRefPtr.h>
|
||||||
#include <AK/RefCounted.h>
|
#include <AK/RefCounted.h>
|
||||||
|
@ -1256,3 +1257,18 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace AK {
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Formatter<Shell::AST::Command> : StandardFormatter {
|
||||||
|
Formatter() { }
|
||||||
|
explicit Formatter(StandardFormatter formatter)
|
||||||
|
: StandardFormatter(formatter)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void format(TypeErasedFormatParams&, FormatBuilder&, const Shell::AST::Command& value);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -59,15 +59,17 @@ bool Job::print_status(PrintStatusMode mode)
|
||||||
if (is_running_in_background())
|
if (is_running_in_background())
|
||||||
background_indicator = '+';
|
background_indicator = '+';
|
||||||
|
|
||||||
|
const AST::Command& command = *m_command;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case PrintStatusMode::Basic:
|
case PrintStatusMode::Basic:
|
||||||
printf("[%" PRIu64 "] %c %s %s\n", m_job_id, background_indicator, status, m_cmd.characters());
|
outln("[{}] {} {} {}", m_job_id, background_indicator, status, command);
|
||||||
break;
|
break;
|
||||||
case PrintStatusMode::OnlyPID:
|
case PrintStatusMode::OnlyPID:
|
||||||
printf("[%" PRIu64 "] %c %d %s %s\n", m_job_id, background_indicator, m_pid, status, m_cmd.characters());
|
outln("[{}] {} {} {} {}", m_job_id, background_indicator, m_pid, status, command);
|
||||||
break;
|
break;
|
||||||
case PrintStatusMode::ListAll:
|
case PrintStatusMode::ListAll:
|
||||||
printf("[%" PRIu64 "] %c %d %d %s %s\n", m_job_id, background_indicator, m_pid, m_pgid, status, m_cmd.characters());
|
outln("[{}] {} {} {} {} {}", m_job_id, background_indicator, m_pid, m_pgid, status, command);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue