diff options
| author | MaxVerevkin <maxxverrr@gmail.com> | 2023-04-02 22:32:52 +0300 |
|---|---|---|
| committer | MaxVerevkin <maxxverrr@gmail.com> | 2023-04-02 22:32:52 +0300 |
| commit | 3b8aafe1018ed626dbb4c19759195a05be93a1bf (patch) | |
| tree | 767261aba4e1466a4bf061f8cbcae33412017d07 /src/status_cmd.rs | |
| parent | a6712690dcfe7dc7c3f2ee8714fa29ad6bbc10ef (diff) | |
| download | i3bar-mango-3b8aafe1018ed626dbb4c19759195a05be93a1bf.tar.gz | |
small changes
Diffstat (limited to 'src/status_cmd.rs')
| -rw-r--r-- | src/status_cmd.rs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/status_cmd.rs b/src/status_cmd.rs index 58ba877..172bee2 100644 --- a/src/status_cmd.rs +++ b/src/status_cmd.rs @@ -40,8 +40,8 @@ impl StatusCmd { }) } - pub fn read(&mut self) -> Result<Option<Vec<Block>>> { - match read(self.output.as_raw_fd(), &mut self.buf) { + pub fn receive_blocks(&mut self) -> Result<Option<Vec<Block>>> { + match read_to_vec(self.output.as_raw_fd(), &mut self.buf) { Ok(0) => bail!("status command exited"), Ok(_n) => (), Err(Errno::EAGAIN) => return Ok(None), @@ -57,7 +57,7 @@ impl StatusCmd { pub fn send_click_event(&mut self, event: &Event) -> Result<()> { if self.protocol.supports_clicks() { - writeln!(self.input, "{}", serde_json::to_string(event).unwrap())?; + writeln!(self.input, "{}", serde_json::to_string(event)?)?; } Ok(()) } @@ -66,7 +66,7 @@ impl StatusCmd { /// Read from a raw file descriptor to the vector. /// /// Appends data at the end of the buffer. Resizes vector as needed. -pub fn read(fd: RawFd, buf: &mut Vec<u8>) -> nix::Result<usize> { +pub fn read_to_vec(fd: RawFd, buf: &mut Vec<u8>) -> nix::Result<usize> { if buf.capacity() - buf.len() < 1024 { buf.reserve(buf.capacity().max(1024)); } @@ -79,12 +79,8 @@ pub fn read(fd: RawFd, buf: &mut Vec<u8>) -> nix::Result<usize> { ) }; - let read = Errno::result(res).map(|r| r as usize)?; - if read > 0 { - unsafe { - buf.set_len(buf.len() + read); - } - } + let read = Errno::result(res)? as usize; + unsafe { buf.set_len(buf.len() + read) }; Ok(read) } |
