Skip to content

Commit beda4a1

Browse files
committed
docs: Clean up
1 parent cc67a84 commit beda4a1

File tree

3 files changed

+107
-80
lines changed

3 files changed

+107
-80
lines changed

src/process.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::os::unix::process::CommandExt;
1818
use std::process::Command;
1919
use std::{thread, time};
2020

21-
/// Start a process in a forked tty so you can interact with it the same as you would
21+
/// Start a process in a forked tty to interact with it like you would
2222
/// within a terminal
2323
///
2424
/// The process and pty session are killed upon dropping `PtyProcess`
@@ -144,17 +144,18 @@ impl PtyProcess {
144144
Ok(fd.into())
145145
}
146146

147-
/// At the drop of `PtyProcess` the running process is killed. This is blocking forever if
148-
/// the process does not react to a normal kill. If `kill_timeout` is set the process is
149-
/// `kill -9`ed after duration
147+
/// At the drop of `PtyProcess` the running process is killed (blocking).
148+
///
149+
/// This is blocking forever if the process does not react to a normal kill.
150+
/// If `kill_timeout` is set the process is `kill -9`ed after duration.
150151
pub fn set_kill_timeout(&mut self, timeout_ms: Option<u64>) {
151152
self.kill_timeout = timeout_ms.map(time::Duration::from_millis);
152153
}
153154

154-
/// Get status of child process, non-blocking.
155+
/// Get status of child process (non-blocking).
155156
///
156-
/// This method runs waitpid on the process.
157-
/// This means: If you ran `exit()` before or `status()` this method will
157+
/// This method runs waitpid on the process:
158+
/// if you ran `exit()` before or `status()` this method will
158159
/// return `None`
159160
///
160161
/// # Example
@@ -176,29 +177,34 @@ impl PtyProcess {
176177
wait::waitpid(self.child_pid, Some(wait::WaitPidFlag::WNOHANG)).ok()
177178
}
178179

179-
/// Wait until process has exited. This is a blocking call.
180+
/// Wait until process has exited (non-blocking).
181+
///
180182
/// If the process doesn't terminate this will block forever.
181183
pub fn wait(&self) -> Result<wait::WaitStatus, Error> {
182184
wait::waitpid(self.child_pid, None).map_err(Error::from)
183185
}
184186

185-
/// Regularly exit the process, this method is blocking until the process is dead
187+
/// Regularly exit the process (blocking).
188+
///
189+
/// This method is blocking until the process is dead
186190
pub fn exit(&mut self) -> Result<wait::WaitStatus, Error> {
187191
self.kill(signal::SIGTERM)
188192
}
189193

190-
/// Non-blocking variant of `kill()` (doesn't wait for process to be killed)
194+
/// Kill the process with a specific signal (non-blocking).
191195
pub fn signal(&mut self, sig: signal::Signal) -> Result<(), Error> {
192196
signal::kill(self.child_pid, sig).map_err(Error::from)
193197
}
194198

195-
/// Kill the process with a specific signal. This method blocks, until the process is dead
199+
/// Kill the process with a specific signal (blocking).
200+
///
201+
/// This method blocks until the process is dead
196202
///
197-
/// repeatedly sends SIGTERM to the process until it died,
203+
/// This repeatedly sends SIGTERM to the process until it died,
198204
/// the pty session is closed upon dropping `PtyMaster`,
199205
/// so we don't need to explicitly do that here.
200206
///
201-
/// if `kill_timeout` is set and a repeated sending of signal does not result in the process
207+
/// If `kill_timeout` is set and a repeated sending of signal does not result in the process
202208
/// being killed, then `kill -9` is sent after the `kill_timeout` duration has elapsed.
203209
pub fn kill(&mut self, sig: signal::Signal) -> Result<wait::WaitStatus, Error> {
204210
let start = time::Instant::now();

src/reader.rs

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ use std::sync::mpsc::{Receiver, channel};
88
use std::thread;
99
use std::{fmt, time};
1010

11-
/// Options for `NBReader`
12-
///
13-
/// - timeout:
14-
/// + `None`: `read_until` is blocking forever. This is probably not what you want
15-
/// + `Some(millis)`: after millis milliseconds a timeout error is raised
16-
/// - `strip_ansi_escape_codes`: Whether to filter out escape codes, such as colors.
11+
/// Options for [`NBReader`]
1712
#[derive(Default)]
1813
pub struct Options {
14+
/// `None`: `read_until` is blocking forever. This is probably not what you want
15+
///
16+
/// `Some(millis)`: after millis milliseconds a timeout error is raised
1917
pub timeout_ms: Option<u64>,
18+
/// Whether to filter out escape codes, such as colors.
2019
pub strip_ansi_escape_codes: bool,
2120
}
2221

@@ -35,10 +34,10 @@ pub struct NBReader {
3534
impl NBReader {
3635
/// Create a new reader instance
3736
///
38-
/// # Arguments:
37+
/// # Arguments
3938
///
40-
/// - f: file like object
41-
/// - options: see `Options`
39+
/// - `f`: file like object
40+
/// - `options`: see [`Options`]
4241
pub fn new<R: Read + Send + 'static>(f: R, options: Options) -> NBReader {
4342
let (tx, rx) = channel();
4443

@@ -87,7 +86,7 @@ impl NBReader {
8786
}
8887
}
8988

90-
/// reads all available chars from the read channel and stores them in self.buffer
89+
/// Reads all available chars from the read channel and stores them in [`Self::buffer`]
9190
fn read_into_buffer(&mut self) -> Result<(), Error> {
9291
if self.eof {
9392
return Ok(());
@@ -109,24 +108,13 @@ impl NBReader {
109108
Ok(())
110109
}
111110

112-
/// Read until needle is found (blocking!) and return tuple with:
113-
/// 1. yet unread string until and without needle
114-
/// 2. matched needle
111+
/// Read until needle is found (blocking!)
115112
///
116113
/// This methods loops (while reading from the Cursor) until the needle is found.
117114
///
118-
/// There are different modes:
119-
///
120-
/// - `ReadUntil::String` searches for string (use '\n'.`to_string()` to search for newline).
121-
/// Returns not yet read data in first String, and needle in second String
122-
/// - `ReadUntil::Regex` searches for regex
123-
/// Returns not yet read data in first String and matched regex in second String
124-
/// - `ReadUntil::NBytes` reads maximum n bytes
125-
/// Returns n bytes in second String, first String is left empty
126-
/// - `ReadUntil::EOF` reads until end of file is reached
127-
/// Returns all bytes in second String, first is left empty
128-
///
129-
/// Note that when used with a tty the lines end with \r\n
115+
/// Returns a tuple with:
116+
/// 1. yet unread string until and without needle
117+
/// 2. matched needle
130118
///
131119
/// Returns error if EOF is reached before the needle could be found.
132120
///
@@ -193,8 +181,9 @@ impl NBReader {
193181
}
194182
}
195183

196-
/// Try to read one char from internal buffer. Returns None if
197-
/// no char is ready, Some(char) otherwise. This is non-blocking
184+
/// Try to read one char from internal buffer (non-blocking).
185+
///
186+
/// Returns `None` if no char is ready `Some(char)` otherwise.
198187
pub fn try_read(&mut self) -> Option<char> {
199188
// discard eventual errors, EOF will be handled in read_until correctly
200189
let _ = self.read_into_buffer();
@@ -207,10 +196,24 @@ impl NBReader {
207196
}
208197

209198
/// See [`NBReader::read_until`]
199+
///
200+
/// Note that when used with a tty the lines end with \r\n
210201
pub enum ReadUntil {
202+
/// Searches for string (use '\n'.`to_string()` to search for newline).
203+
///
204+
/// Returns not yet read data in first String, and needle in second String
211205
String(String),
206+
/// `ReadUntil::Regex` searches for regex
207+
///
208+
/// Returns not yet read data in first String and matched regex in second String
212209
Regex(Regex),
210+
/// `ReadUntil::NBytes` reads maximum n bytes
211+
///
212+
/// Returns n bytes in second String, first String is left empty
213213
NBytes(usize),
214+
/// `ReadUntil::EOF` reads until end of file is reached
215+
///
216+
/// Returns all bytes in second String, first is left empty
214217
EOF,
215218
Any(Vec<ReadUntil>),
216219
}
@@ -237,12 +240,12 @@ impl fmt::Display for ReadUntil {
237240
}
238241
}
239242

240-
/// find first occurrence of needle within buffer
243+
/// Find first occurrence of needle within buffer
241244
///
242245
/// # Arguments:
243246
///
244-
/// - buffer: the currently read buffer from a process which will still grow in the future
245-
/// - eof: if the process already sent an EOF or a HUP
247+
/// - `buffer`: the currently read buffer from a process which will still grow in the future
248+
/// - `eof`: if the process already sent an EOF or a HUP
246249
///
247250
/// # Return
248251
///

0 commit comments

Comments
 (0)