feat(script): Option to tail script output
This commit is contained in:
parent
552c0b58a5
commit
f7734de26a
@ -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=$(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"
|
;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
|
; Seconds to sleep between updates
|
||||||
|
; Will be ignored if `tail = true`
|
||||||
|
; Default: 1
|
||||||
interval = 90
|
interval = 90
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
@ -940,8 +945,8 @@ See [the bspwm module](#user-content-dependencies) for details on `label-dimmed`
|
|||||||
~~~ ini
|
~~~ ini
|
||||||
[module/xtitle]
|
[module/xtitle]
|
||||||
type = custom/script
|
type = custom/script
|
||||||
exec = xtitle
|
exec = xtitle -s
|
||||||
interval = 0.25
|
tail = true
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
### Module `custom/text`
|
### Module `custom/text`
|
||||||
|
@ -12,6 +12,8 @@ namespace modules
|
|||||||
std::unique_ptr<Builder> builder;
|
std::unique_ptr<Builder> builder;
|
||||||
|
|
||||||
std::string exec;
|
std::string exec;
|
||||||
|
bool tail = false;
|
||||||
|
|
||||||
std::string click_left;
|
std::string click_left;
|
||||||
std::string click_middle;
|
std::string click_middle;
|
||||||
std::string click_right;
|
std::string click_right;
|
||||||
|
@ -9,10 +9,12 @@ using namespace modules;
|
|||||||
ScriptModule::ScriptModule(const std::string& name_)
|
ScriptModule::ScriptModule(const std::string& name_)
|
||||||
: TimerModule(name_, 1s), builder(std::make_unique<Builder>(true)), counter(0)
|
: TimerModule(name_, 1s), builder(std::make_unique<Builder>(true)), counter(0)
|
||||||
{
|
{
|
||||||
|
// Load configuration values {{{
|
||||||
this->exec = config::get<std::string>(name(), "exec");
|
this->exec = config::get<std::string>(name(), "exec");
|
||||||
|
this->tail = config::get<bool>(name(), "tail", this->tail);
|
||||||
|
|
||||||
this->interval = std::chrono::duration<double>(
|
if (!this->tail)
|
||||||
config::get<float>(name(), "interval", 1));
|
this->interval = std::chrono::duration<double>(config::get<float>(name(), "interval", 1));
|
||||||
|
|
||||||
this->click_left = config::get<std::string>(name(), "click-left", "");
|
this->click_left = config::get<std::string>(name(), "click-left", "");
|
||||||
this->click_middle = config::get<std::string>(name(), "click-middle", "");
|
this->click_middle = config::get<std::string>(name(), "click-middle", "");
|
||||||
@ -20,8 +22,11 @@ ScriptModule::ScriptModule(const std::string& name_)
|
|||||||
|
|
||||||
this->scroll_up = config::get<std::string>(name(), "scroll-up", "");
|
this->scroll_up = config::get<std::string>(name(), "scroll-up", "");
|
||||||
this->scroll_down = config::get<std::string>(name(), "scroll-down", "");
|
this->scroll_down = config::get<std::string>(name(), "scroll-down", "");
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
// Add formats and elements {{{
|
||||||
this->formatter->add(DEFAULT_FORMAT, TAG_OUTPUT, { TAG_OUTPUT });
|
this->formatter->add(DEFAULT_FORMAT, TAG_OUTPUT, { TAG_OUTPUT });
|
||||||
|
// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptModule::update()
|
bool ScriptModule::update()
|
||||||
@ -37,8 +42,13 @@ bool ScriptModule::update()
|
|||||||
|
|
||||||
command->exec(false);
|
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");
|
this->output.append(buf + "\n");
|
||||||
|
|
||||||
|
if (this->tail) {
|
||||||
|
this->broadcast();
|
||||||
|
this->output.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
command->wait();
|
command->wait();
|
||||||
|
Loading…
Reference in New Issue
Block a user