diff --git a/README.md b/README.md index 24b5e186..130db1e8 100644 --- a/README.md +++ b/README.md @@ -905,7 +905,12 @@ See [the bspwm module](#user-content-dependencies) for details on `label-dimmed` exec = count=$(sudo pacman -Syup --noprogressbar 2>/dev/null | sed '/Starting full/,~1!d;/Starting full/d' | wc -l); [ $count -gt 0 ] && echo "Updates available: $count" ;exec = count=$(echo n | sudo xbps-install -Su >/dev/null 2>&1; sudo xbps-install -Sun | wc -l); [ $count -gt 0 ] && echo "Updates available: $count" + ; Should we keep listening for output from the command? + ;tail = false + ; Seconds to sleep between updates + ; Will be ignored if `tail = true` + ; Default: 1 interval = 90 ~~~ @@ -940,8 +945,8 @@ See [the bspwm module](#user-content-dependencies) for details on `label-dimmed` ~~~ ini [module/xtitle] type = custom/script - exec = xtitle - interval = 0.25 + exec = xtitle -s + tail = true ~~~ ### Module `custom/text` diff --git a/include/modules/script.hpp b/include/modules/script.hpp index de55ad52..0d2041f6 100644 --- a/include/modules/script.hpp +++ b/include/modules/script.hpp @@ -12,6 +12,8 @@ namespace modules std::unique_ptr builder; std::string exec; + bool tail = false; + std::string click_left; std::string click_middle; std::string click_right; diff --git a/src/modules/script.cpp b/src/modules/script.cpp index b33a9f3d..7ea60308 100644 --- a/src/modules/script.cpp +++ b/src/modules/script.cpp @@ -9,10 +9,12 @@ using namespace modules; ScriptModule::ScriptModule(const std::string& name_) : TimerModule(name_, 1s), builder(std::make_unique(true)), counter(0) { + // Load configuration values {{{ this->exec = config::get(name(), "exec"); + this->tail = config::get(name(), "tail", this->tail); - this->interval = std::chrono::duration( - config::get(name(), "interval", 1)); + if (!this->tail) + this->interval = std::chrono::duration(config::get(name(), "interval", 1)); this->click_left = config::get(name(), "click-left", ""); this->click_middle = config::get(name(), "click-middle", ""); @@ -20,8 +22,11 @@ ScriptModule::ScriptModule(const std::string& name_) this->scroll_up = config::get(name(), "scroll-up", ""); this->scroll_down = config::get(name(), "scroll-down", ""); + // }}} + // Add formats and elements {{{ this->formatter->add(DEFAULT_FORMAT, TAG_OUTPUT, { TAG_OUTPUT }); + // }}} } bool ScriptModule::update() @@ -37,8 +42,13 @@ bool ScriptModule::update() command->exec(false); - while (!(buf = io::readline(command->get_stdout(PIPE_READ))).empty()) { + while (!(buf = io::readline(command->get_stdout(PIPE_READ))).empty() || (this->tail && this->enabled())) { this->output.append(buf + "\n"); + + if (this->tail) { + this->broadcast(); + this->output.clear(); + } } command->wait();