8000 Working fix for #108 by FelixSelter · Pull Request #173 · console-rs/console · GitHub
[go: up one dir, main page]

Skip to content

Working fix for #108 #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added support to read a single line from the input source
  • Loading branch information
FelixSelter committed May 27, 2023
commit 596a1426e2f80fe75138d4538ec2eed9e06288bf
26 changes: 24 additions & 2 deletions src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,31 @@ impl TermTarget {
io::stdin().read(buf)
}
}

/// Reads chars until Key::Enter was found
/// This may cause an infinite loop if the line is not terminated
///
/// # Panics
/// If the input source is a custom ReadWritePair and any keys other than Char, Enter or BackSpace are encountered
///
/// # Returns error
/// If there was an error reading from the input source
///
/// # Returns ok
/// The length of the modified buffer string
fn read_line(&self, buf: &mut String) -> io::Result<usize> {
if let TermTarget::ReadWritePair(pair) = self {
todo!()
if let TermTarget::ReadWritePair(_) = self {
let mut keys = Vec::new();
loop {
let key = self.read_single_key()?;
if key == Key::Enter {
break;
}
keys.push(key);
4E54 }
buf.clear();
buf.push_str(&keys_to_utf8(&keys));
Ok(buf.len())
} else {
io::stdin().read_line(buf)
}
Expand Down
0