Skip to content

Commit 0f7bbac

Browse files
committed
Fix formatting; avoid str_split_once feature.
1 parent 5376c13 commit 0f7bbac

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/common_term.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn get_cursor_position(mut out: &Term) -> io::Result<(u16, u16)> {
4747
// We expect a response of the form "ESC[n;mR", where n and m are the row and column of the cursor.
4848
// n and m are at most 65536, so 4+2*5 bytes should suffice for these purposes.
4949
// TODO: this blocks for user input!
50-
let mut buf = [0u8; 4 + 2*5];
50+
let mut buf = [0u8; 4 + 2 * 5];
5151
let num_read = io::Read::read(&mut out, &mut buf)?;
5252
out.clear_chars(num_read)?;
5353
// FIXME: re-use ANSI code parser instead of rolling my own.
@@ -59,14 +59,19 @@ pub fn get_cursor_position(mut out: &Term) -> io::Result<(u16, u16)> {
5959
Ok(m) => m,
6060
Err(_) => return Err(io::Error::new(io::ErrorKind::Other, format!("invalid terminal response: middle part of the output {:?} must be valid UTF-8", buf))),
6161
};
62-
let (nstr, mstr) = match middle.split_once(';') {
63-
Some((nstr, mstr)) => (nstr, mstr),
64-
None => return Err(io::Error::new(io::ErrorKind::Other, format!("invalid terminal response: middle part of the output should be of the form n;m, got {}", middle))),
62+
let parts = middle.splitn(2, ';').collect::<Vec<_>>();
63+
let (nstr, mstr) =
64+
match &parts[..] {
65+
[a, b] => (a, b),
66+
_ => return Err(io::Error::new(io::ErrorKind::Other, format!("invalid terminal response: middle part of the output should be of the form n;m, got {}", middle))),
6567
};
6668
let (n, m) = (nstr.parse::<u16>().unwrap(), mstr.parse::<u16>().unwrap());
6769
Ok((n, m))
68-
},
69-
_ => return Err(io::Error::new(io::ErrorKind::Other, "invalid terminal response: should be of the form ESC[n;mR")),
70+
}
71+
_ => Err(io::Error::new(
72+
io::ErrorKind::Other,
73+
"invalid terminal response: should be of the form ESC[n;mR",
74+
)),
7075
}
7176
}
7277

src/term.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,10 @@ impl Term {
457457
let (current_row, _) = get_cursor_position(self)?;
458458
if usize::from(current_row) < n {
459459
// We cannot move up n lines, only current_row ones.
460-
return Err(io::Error::new(io::ErrorKind::Other, format!("can only move up {} lines, not {}", current_row, n)));
460+
return Err(io::Error::new(
461+
io::ErrorKind::Other,
462+
format!("can only move up {} lines, not {}", current_row, n),
463+
));
461464
}
462465
}
463466
self.move_cursor_up(n)?;

0 commit comments

Comments
 (0)