dropshell release 2025.0518.1355
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
This commit is contained in:
@ -60,6 +60,56 @@ namespace dropshell
|
||||
// execute_local_command
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
|
||||
class fancypinter
|
||||
{
|
||||
public:
|
||||
fancypinter(sColour startColour) : startColour_(startColour), currentColour_(startColour) {}
|
||||
|
||||
void print_chunk(std::string chunk)
|
||||
{
|
||||
if (chunk.empty())
|
||||
return;
|
||||
|
||||
if (newline_)
|
||||
{
|
||||
// sniff the mode... if the string starts with warning or warning: then set mode to WARNING. etc.
|
||||
if (chunk.find("warning") == 0)
|
||||
currentColour_ = sColour::WARNING;
|
||||
else if (chunk.find("error") == 0)
|
||||
currentColour_ = sColour::ERROR;
|
||||
else if (chunk.find("debug") == 0)
|
||||
currentColour_ = sColour::DEBUG;
|
||||
else if (chunk.find("info") == 0)
|
||||
currentColour_ = sColour::INFO;
|
||||
else
|
||||
currentColour_ = startColour_;
|
||||
}
|
||||
colourstream(currentColour_) << chunk;
|
||||
newline_ = (chunk[chunk.size()-1] == '\n');
|
||||
}
|
||||
|
||||
void print(const std::string& buffer) {
|
||||
size_t start = 0;
|
||||
while (start < buffer.size()) {
|
||||
size_t newline_pos = buffer.find('\n', start);
|
||||
if (newline_pos == std::string::npos) {
|
||||
if (start < buffer.size()) {
|
||||
print_chunk(buffer.substr(start));
|
||||
}
|
||||
break;
|
||||
}
|
||||
print_chunk(buffer.substr(start, newline_pos - start + 1)); // include the newline
|
||||
start = newline_pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool newline_ = true;
|
||||
sColour startColour_;
|
||||
sColour currentColour_;
|
||||
};
|
||||
|
||||
|
||||
bool execute_local_command(std::string directory_to_run_in, std::string command_to_run, const std::map<std::string, std::string> &env_vars, std::string *output, cMode mode)
|
||||
{
|
||||
sCommand command(directory_to_run_in, command_to_run, env_vars);
|
||||
@ -86,15 +136,14 @@ namespace dropshell
|
||||
return false;
|
||||
}
|
||||
char buffer[128];
|
||||
fancypinter fancyprint(sColour::DEBUG);
|
||||
while (fgets(buffer, sizeof(buffer), pipe) != nullptr)
|
||||
{
|
||||
if (output != nullptr)
|
||||
(*output) += buffer;
|
||||
|
||||
if (!silent)
|
||||
{
|
||||
std::cerr << buffer;
|
||||
}
|
||||
fancyprint.print(buffer);
|
||||
}
|
||||
int ret = pclose(pipe);
|
||||
return EXITSTATUSCHECK(ret);
|
||||
|
Reference in New Issue
Block a user