Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
bytes encoded the protocol origin (panic in debug, wrap to 65535
in release). Affects `parse_csi_normal_mouse`, `parse_csi_rxvt_mouse`,
`parse_csi_sgr_mouse`, and `parse_csi_cursor_position`.
- Fix integer underflow on the Windows legacy-console cursor path when the
requested count exceeded the current row or column (panic in debug, wrap
to 65535 in release). `MoveUp`, `MoveLeft`, and `MoveToPreviousLine` now
clamp at the first row / column, matching the ANSI path.
- Fix `Colors::from(Colored::UnderlineColor(_))` setting the background
color. `Colors` has no underline field, so the color is now dropped
instead of being applied to the background.
Expand Down
24 changes: 21 additions & 3 deletions src/cursor/sys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub(crate) fn move_to(column: u16, row: u16) -> std::io::Result<()> {

pub(crate) fn move_up(count: u16) -> std::io::Result<()> {
let (column, row) = position()?;
move_to(column, row - count)?;
move_to(column, row.saturating_sub(count))?;
Ok(())
}

Expand All @@ -74,7 +74,7 @@ pub(crate) fn move_down(count: u16) -> std::io::Result<()> {

pub(crate) fn move_left(count: u16) -> std::io::Result<()> {
let (column, row) = position()?;
move_to(column - count, row)?;
move_to(column.saturating_sub(count), row)?;
Ok(())
}

Expand All @@ -98,7 +98,7 @@ pub(crate) fn move_to_next_line(count: u16) -> std::io::Result<()> {

pub(crate) fn move_to_previous_line(count: u16) -> std::io::Result<()> {
let (_, row) = position()?;
move_to(0, row - count)?;
move_to(0, row.saturating_sub(count))?;
Ok(())
}

Expand Down Expand Up @@ -248,6 +248,12 @@ mod tests {
move_left(2).unwrap();

assert_eq!(position().unwrap(), (0, 0));

move_to(2, 0).unwrap();

move_left(5).unwrap();

assert_eq!(position().unwrap(), (0, 0));
}

#[test]
Expand All @@ -260,6 +266,12 @@ mod tests {
move_up(2).unwrap();

assert_eq!(position().unwrap(), (0, 0));

move_to(0, 2).unwrap();

move_up(5).unwrap();

assert_eq!(position().unwrap(), (0, 0));
}

#[test]
Expand All @@ -284,6 +296,12 @@ mod tests {
move_to_previous_line(2).unwrap();

assert_eq!(position().unwrap(), (0, 0));

move_to(0, 2).unwrap();

move_to_previous_line(5).unwrap();

assert_eq!(position().unwrap(), (0, 0));
}

#[test]
Expand Down