forked from mirrors/jj
ui: simplify stripping logic and get rid of warning
This commit is contained in:
parent
a524f1f996
commit
7b8df5d8fd
1 changed files with 4 additions and 5 deletions
|
@ -566,8 +566,6 @@ impl Ui {
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unknown_lints)] // XXX FIXME (aseipp): nightly bogons; re-test this occasionally
|
|
||||||
#[allow(clippy::assigning_clones)]
|
|
||||||
pub fn prompt(&self, prompt: &str) -> io::Result<String> {
|
pub fn prompt(&self, prompt: &str) -> io::Result<String> {
|
||||||
if !Self::can_prompt() {
|
if !Self::can_prompt() {
|
||||||
return Err(io::Error::new(
|
return Err(io::Error::new(
|
||||||
|
@ -580,15 +578,16 @@ impl Ui {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
io::stdin().read_line(&mut buf)?;
|
io::stdin().read_line(&mut buf)?;
|
||||||
|
|
||||||
if let Some(trimmed) = buf.strip_suffix('\n') {
|
if buf.is_empty() {
|
||||||
buf = trimmed.to_owned();
|
|
||||||
} else if buf.is_empty() {
|
|
||||||
return Err(io::Error::new(
|
return Err(io::Error::new(
|
||||||
io::ErrorKind::UnexpectedEof,
|
io::ErrorKind::UnexpectedEof,
|
||||||
"Prompt cancelled by EOF",
|
"Prompt cancelled by EOF",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(trimmed) = buf.strip_suffix('\n') {
|
||||||
|
buf.truncate(trimmed.len());
|
||||||
|
}
|
||||||
Ok(buf)
|
Ok(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue