Skip to content

Commit

Permalink
Document behavior of read_line with respect to reported signals
Browse files Browse the repository at this point in the history
  • Loading branch information
murarth committed Jun 27, 2018
1 parent 923498d commit 2965083
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
9 changes: 6 additions & 3 deletions examples/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,15 @@ fn main() -> io::Result<()> {
}
}
}
_ => ()
_ => println!("read input: {:?}", line)
}
}
ReadResult::Signal(sig) => {
println!();
println!("signal received: {:?}", sig);
if sig == Signal::Interrupt {
interface.cancel_read_line()?;
}

let _ = writeln!(interface, "signal received: {:?}", sig);
}
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,18 @@ impl<Term: Terminal> Interface<Term> {
impl<Term: Terminal> Interface<Term> {
/// Interactively reads a line from the terminal device.
///
/// If the user issues an end-of-file, `ReadResult::Eof` is returned.
/// User input is collected until one of the following conditions is met:
///
/// If a reported signal (see [`set_report_signal`]) is received,
/// it is returned as `ReadResult::Signal(_)`.
///
/// Otherwise, user input is collected until a newline is entered.
/// The resulting input (not containing a trailing newline character)
/// is returned as `ReadResult::Input(_)`.
/// * If the user issues an end-of-file, `ReadResult::Eof` is returned.
/// * When the user inputs a newline (`'\n'`), the resulting input
/// (not containing a trailing newline character) is returned as
/// `ReadResult::Input(_)`.
/// * When a reported signal (see [`set_report_signal`]) is received,
/// it is returned as `ReadResult::Signal(_)`. The `read_line` operation may
/// then be either resumed with another call to `read_line` or ended by
/// calling [`cancel_read_line`].
///
/// [`cancel_read_line`]: #method.cancel_read_line
/// [`set_report_signal`]: #method.set_report_signal
pub fn read_line(&self) -> io::Result<ReadResult> {
self.lock_reader().read_line()
Expand Down
17 changes: 10 additions & 7 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,18 @@ impl<'a, Term: 'a + Terminal> Reader<'a, Term> {

/// Interactively reads a line from the terminal device.
///
/// If the user issues an end-of-file, `ReadResult::Eof` is returned.
/// User input is collected until one of the following conditions is met:
///
/// If a reported signal (see [`set_report_signal`]) is received,
/// it is returned as `ReadResult::Signal(_)`.
///
/// Otherwise, user input is collected until a newline is entered.
/// The resulting input (not containing a trailing newline character)
/// is returned as `ReadResult::Input(_)`.
/// * If the user issues an end-of-file, `ReadResult::Eof` is returned.
/// * When the user inputs a newline (`'\n'`), the resulting input
/// (not containing a trailing newline character) is returned as
/// `ReadResult::Input(_)`.
/// * When a reported signal (see [`set_report_signal`]) is received,
/// it is returned as `ReadResult::Signal(_)`. The `read_line` operation may
/// then be either resumed with another call to `read_line` or ended by
/// calling [`cancel_read_line`].
///
/// [`cancel_read_line`]: #method.cancel_read_line
/// [`set_report_signal`]: #method.set_report_signal
pub fn read_line(&mut self) -> io::Result<ReadResult> {
loop {
Expand Down

0 comments on commit 2965083

Please sign in to comment.