mirror of
https://github.com/rad4day/Waybar.git
synced 2025-07-12 06:02:30 +02:00
refactor: format code
This commit is contained in:
@ -1,25 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/wait.h>
|
||||
#include <giomm.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace waybar::util::command {
|
||||
|
||||
struct res {
|
||||
int exit_code;
|
||||
int exit_code;
|
||||
std::string out;
|
||||
};
|
||||
|
||||
inline struct res exec(const std::string cmd)
|
||||
{
|
||||
inline struct res exec(const std::string cmd) {
|
||||
FILE* fp(popen(cmd.c_str(), "r"));
|
||||
if (!fp) {
|
||||
return { -1, "" };
|
||||
return {-1, ""};
|
||||
}
|
||||
|
||||
std::array<char, 128> buffer = {0};
|
||||
std::string output;
|
||||
std::string output;
|
||||
while (feof(fp) == 0) {
|
||||
if (fgets(buffer.data(), 128, fp) != nullptr) {
|
||||
output += buffer.data();
|
||||
@ -27,8 +26,8 @@ inline struct res exec(const std::string cmd)
|
||||
}
|
||||
|
||||
// Remove last newline
|
||||
if (!output.empty() && output[output.length()-1] == '\n') {
|
||||
output.erase(output.length()-1);
|
||||
if (!output.empty() && output[output.length() - 1] == '\n') {
|
||||
output.erase(output.length() - 1);
|
||||
}
|
||||
int exit_code = WEXITSTATUS(pclose(fp));
|
||||
return {exit_code, output};
|
||||
|
Reference in New Issue
Block a user