Skip to content

Commit

Permalink
fix(script): Receiving multiple lines rapidly only displays first line (
Browse files Browse the repository at this point in the history
#3119)

Fixes #3117
  • Loading branch information
Isak05 committed Apr 28, 2024
1 parent ab583b0 commit 81ea169
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Fixed
- `custom/script`: When a script with `tail = true` received multiple lines quickly, only the first would get displayed ([`#3117`](https://github.com/polybar/polybar/issues/3117), [`#3119`](https://github.com/polybar/polybar/pull/3119)) by [@Isak05](https://github.com/Isak05)
- Token min-length calculations would behave differently when non-ASCII characters appear in the token ([`#3074`](https://github.com/polybar/polybar/issues/3074), [`#3087`](https://github.com/polybar/polybar/pull/3087)) by [@nklloyd](https://github.com/nklloyd)
- i3: Fix duplicated rendering for non-full-width bars ([`#3091`](https://github.com/polybar/polybar/pull/3091), [`#3060`](https://github.com/polybar/polybar/issues/3060))
- `internal/backlight`: Module could display the literal `%percentage%` token if the backlight reports a value of 0 at startup ([`#3081`](https://github.com/polybar/polybar/pull/3081)) by [@unclechu](https://github.com/unclechu)
Expand Down
3 changes: 1 addition & 2 deletions include/modules/meta/base.inl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace modules {

template <typename Impl>
string module<Impl>::contents() {
if (m_changed) {
if (m_changed.exchange(false)) {
m_log.info("%s: Rebuilding cache", name());
m_cache = CAST_MOD(Impl)->get_output();
// Make sure builder is really empty
Expand All @@ -129,7 +129,6 @@ namespace modules {
m_builder->control(tags::controltag::R);
m_cache += m_builder->flush();
}
m_changed = false;
}
return m_cache;
}
Expand Down
1 change: 1 addition & 0 deletions include/utils/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class command<output_policy::REDIRECTED> : private command<output_policy::IGNORE

void tail(std::function<void(string)> cb);
string readline();
bool wait_for_data(int timeout_ms);

int get_stdout(int c);
int get_stdin(int c);
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/script_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ script_runner::interval script_runner::run_tail() {
assert(fd != -1);

while (!m_stopping && cmd.is_running() && !io_util::poll(fd, POLLHUP, 0)) {
if (io_util::poll_read(fd, 250)) {
if (cmd.wait_for_data(250)) {
auto changed = set_output(cmd.readline());

if (changed) {
Expand Down
8 changes: 8 additions & 0 deletions src/utils/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ string command<output_policy::REDIRECTED>::readline() {
return s;
}

/**
* Wait until there is data in the output stream or until timeout_ms milliseconds
*/
bool command<output_policy::REDIRECTED>::wait_for_data(int timeout_ms) {
return (m_stdout_reader && m_stdout_reader->rdbuf()->in_avail() > 0) ||
io_util::poll_read(get_stdout(PIPE_READ), timeout_ms);
}

/**
* Get command output channel
*/
Expand Down

0 comments on commit 81ea169

Please sign in to comment.