diff --git a/Shell/AST.cpp b/Shell/AST.cpp index 89e5309f3c..32942fdb24 100644 --- a/Shell/AST.cpp +++ b/Shell/AST.cpp @@ -37,6 +37,50 @@ //#define EXECUTE_DEBUG +void AK::Formatter::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 { template diff --git a/Shell/AST.h b/Shell/AST.h index 178bd12c9a..a10e8ed7f6 100644 --- a/Shell/AST.h +++ b/Shell/AST.h @@ -29,6 +29,7 @@ #include "Forward.h" #include "Job.h" #include "NodeVisitor.h" +#include #include #include #include @@ -1256,3 +1257,18 @@ private: }; } + +namespace AK { + +template<> +struct Formatter : StandardFormatter { + Formatter() { } + explicit Formatter(StandardFormatter formatter) + : StandardFormatter(formatter) + { + } + + void format(TypeErasedFormatParams&, FormatBuilder&, const Shell::AST::Command& value); +}; + +} diff --git a/Shell/Job.cpp b/Shell/Job.cpp index 91b5c07b8c..6402a3d5f9 100644 --- a/Shell/Job.cpp +++ b/Shell/Job.cpp @@ -59,15 +59,17 @@ bool Job::print_status(PrintStatusMode mode) if (is_running_in_background()) background_indicator = '+'; + const AST::Command& command = *m_command; + switch (mode) { 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; 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; 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; }