diff options
| author | Jason Felice <jason.m.felice@gmail.com> | 2019-06-06 17:21:30 -0400 |
|---|---|---|
| committer | Jason Felice <jason.m.felice@gmail.com> | 2019-06-11 10:11:28 -0400 |
| commit | 0642058b3eb0cdee90adaf405f5aac2b6c00965b (patch) | |
| tree | 0fb27d4b99734460418949f93a2a904057989a61 /src/buffer_utils.cc | |
| parent | 09e1ec97a9d7925c9d4411f4f274919aeea1bf75 (diff) | |
Fix emission of BufReadFifo events
The hook parameter should not be adjusted for the prevention of
scrolling. Also, ensure that the last BufReadFifo is triggered if we
encounter an error or EOF after appending some data to the buffer.
Closes #2946
Diffstat (limited to 'src/buffer_utils.cc')
| -rw-r--r-- | src/buffer_utils.cc | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc index bb0669ff..66f5436c 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -129,17 +129,18 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll // iteration number allows us to go back go back to the event loop and // handle other events sources (such as input) constexpr size_t max_loop = 16; + bool closed = false; size_t loop = 0; char data[buffer_size]; - BufferCoord insert_coord; + BufferCoord insert_coord = buffer->back_coord(); const int fifo = watcher.fd(); do { const ssize_t count = ::read(fifo, data, buffer_size); if (count <= 0) { - buffer->values().erase(fifo_watcher_id); // will delete this - return; + closed = true; + break; } auto pos = buffer->back_coord(); @@ -147,8 +148,6 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll if (prevent_scrolling) pos = buffer->next(pos); - if (loop == 0) - insert_coord = pos; buffer->insert(pos, StringView(data, data+count)); if (prevent_scrolling) @@ -162,8 +161,14 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll } while (++loop < max_loop and fd_readable(fifo)); - buffer->run_hook_in_own_context(Hook::BufReadFifo, - selection_to_string({insert_coord, buffer->back_coord()})); + if (insert_coord != buffer->back_coord()) + { + buffer->run_hook_in_own_context(Hook::BufReadFifo, + selection_to_string({insert_coord, buffer->back_coord()})); + } + + if (closed) + buffer->values().erase(fifo_watcher_id); // will delete this }), std::move(watcher_deleter)); buffer->values()[fifo_watcher_id] = Value(std::move(watcher)); |
