fix(script): Receiving multiple lines rapidly only displays first line (#3119)

Fixes #3117
This commit is contained in:
Isak05 2024-04-28 21:10:12 +02:00 committed by GitHub
parent ab583b08cd
commit 81ea16931e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 3 deletions

View File

@ -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)

View File

@ -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
@ -129,7 +129,6 @@ namespace modules {
m_builder->control(tags::controltag::R);
m_cache += m_builder->flush();
}
m_changed = false;
}
return m_cache;
}

View File

@ -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);

View File

@ -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) {

View File

@ -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
*/