diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-10-29 12:40:41 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-10-29 12:40:41 -0400 |
commit | e525fddb572614f4c6d6a7d71ed44e9dfe7af350 (patch) | |
tree | 673d83f4e040080fd9040ea4d711546d18dd1bd6 | |
parent | 0cd015222e80497c823fc0eadc8f55c45860bade (diff) | |
download | vt100-rust-e525fddb572614f4c6d6a7d71ed44e9dfe7af350.tar.gz vt100-rust-e525fddb572614f4c6d6a7d71ed44e9dfe7af350.zip |
rustfmt
-rw-r--r-- | .rustfmt.toml | 1 | ||||
-rw-r--r-- | build.rs | 26 | ||||
-rw-r--r-- | src/cell.rs | 2 | ||||
-rw-r--r-- | src/color.rs | 2 | ||||
-rw-r--r-- | src/ffi.rs | 90 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/screen.rs | 167 | ||||
-rw-r--r-- | tests/attr.rs | 180 | ||||
-rw-r--r-- | tests/control.rs | 25 | ||||
-rw-r--r-- | tests/csi.rs | 167 | ||||
-rw-r--r-- | tests/escape.rs | 35 | ||||
-rw-r--r-- | tests/init.rs | 10 | ||||
-rw-r--r-- | tests/mode.rs | 10 | ||||
-rw-r--r-- | tests/text.rs | 40 |
14 files changed, 523 insertions, 234 deletions
diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..bcad605 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1 @@ +max_width = 78 @@ -3,40 +3,40 @@ extern crate pkg_config; fn libvt100() { let dir = std::env::current_dir() - .unwrap_or_else(|e| { panic!("couldn't get cwd: {}", e) });; + .unwrap_or_else(|e| panic!("couldn't get cwd: {}", e));; std::env::set_current_dir("libvt100") - .unwrap_or_else(|e| { panic!("failed to chdir: {}", e) }); + .unwrap_or_else(|e| panic!("failed to chdir: {}", e)); let absdir = std::env::current_dir() - .unwrap_or_else(|e| { panic!("couldn't get cwd: {}", e) });; + .unwrap_or_else(|e| panic!("couldn't get cwd: {}", e));; let out = std::process::Command::new("make") .arg("static") .output() - .unwrap_or_else(|e| { panic!("failed to exec: {}", e) }); + .unwrap_or_else(|e| panic!("failed to exec: {}", e)); std::env::set_current_dir(dir) - .unwrap_or_else(|e| { panic!("failed to chdir: {}", e) }); + .unwrap_or_else(|e| panic!("failed to chdir: {}", e)); if !out.status.success() { println!("{}", std::string::String::from_utf8_lossy(&out.stderr)); std::process::exit(out.status.code().unwrap_or(255)); } - println!("cargo:rustc-link-search=native={}", absdir.to_str().unwrap()); + println!( + "cargo:rustc-link-search=native={}", + absdir.to_str().unwrap() + ); println!("cargo:rustc-link-lib=static=vt100"); } fn glib() { - let lib_def = pkg_config::probe_library("glib-2.0") - .unwrap_or_else(|e| { - panic!("Couldn't find required dependency glib-2.0: {}", e); - }); + let lib_def = pkg_config::probe_library("glib-2.0").unwrap_or_else(|e| { + panic!("Couldn't find required dependency glib-2.0: {}", e); + }); for dir in lib_def.link_paths { println!("cargo:rustc-link-search=native={}", dir.to_str().unwrap()); } } fn libvt100_wrappers() { - cc::Build::new() - .file("src/ffi.c") - .compile("vt100wrappers"); + cc::Build::new().file("src/ffi.c").compile("vt100wrappers"); } fn main() { diff --git a/src/cell.rs b/src/cell.rs index bf50817..40b7fad 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -25,7 +25,7 @@ impl Cell { let contents: &[u8] = unsafe { std::slice::from_raw_parts( &(*prefix).contents as *const i8 as *const u8, - (*prefix).len + (*prefix).len, ) }; std::str::from_utf8(contents).unwrap() diff --git a/src/color.rs b/src/color.rs index 52d9d61..76f8ab3 100644 --- a/src/color.rs +++ b/src/color.rs @@ -2,7 +2,7 @@ use std; use types; -#[derive(Eq,PartialEq,Debug)] +#[derive(Eq, PartialEq, Debug)] pub enum Color { ColorDefault, ColorIdx(u8), @@ -5,7 +5,7 @@ use types; extern "C" { pub fn vt100_screen_new( rows: libc::c_int, - cols: libc::c_int + cols: libc::c_int, ) -> *mut types::ScreenImpl; pub fn vt100_screen_delete(screen: *mut types::ScreenImpl); @@ -47,29 +47,73 @@ extern "C" { // XXX: these wrappers (and all of ffi.c) only exist because rust can't // handle bitfields yet - once it can, these should be removed - pub fn vt100_wrapper_screen_hide_cursor(screen: *mut types::ScreenImpl) -> libc::c_int; - pub fn vt100_wrapper_screen_application_keypad(screen: *mut types::ScreenImpl) -> libc::c_int; - pub fn vt100_wrapper_screen_application_cursor(screen: *mut types::ScreenImpl) -> libc::c_int; - pub fn vt100_wrapper_screen_mouse_reporting_press(screen: *mut types::ScreenImpl) -> libc::c_int; - pub fn vt100_wrapper_screen_mouse_reporting_press_release(screen: *mut types::ScreenImpl) -> libc::c_int; - pub fn vt100_wrapper_screen_mouse_reporting_button_motion(screen: *mut types::ScreenImpl) -> libc::c_int; - pub fn vt100_wrapper_screen_mouse_reporting_mode(screen: *mut types::ScreenImpl) -> libc::c_uchar; - pub fn vt100_wrapper_screen_bracketed_paste(screen: *mut types::ScreenImpl) -> libc::c_int; - pub fn vt100_wrapper_screen_visual_bell(screen: *mut types::ScreenImpl) -> libc::c_int; - pub fn vt100_wrapper_screen_audible_bell(screen: *mut types::ScreenImpl) -> libc::c_int; - pub fn vt100_wrapper_screen_update_title(screen: *mut types::ScreenImpl) -> libc::c_int; - pub fn vt100_wrapper_screen_update_icon_name(screen: *mut types::ScreenImpl) -> libc::c_int; - pub fn vt100_wrapper_screen_dirty(screen: *mut types::ScreenImpl) -> libc::c_int; - pub fn vt100_wrapper_screen_clear_visual_bell(screen: *mut types::ScreenImpl); - pub fn vt100_wrapper_screen_clear_audible_bell(screen: *mut types::ScreenImpl); - pub fn vt100_wrapper_screen_clear_update_title(screen: *mut types::ScreenImpl); - pub fn vt100_wrapper_screen_clear_update_icon_name(screen: *mut types::ScreenImpl); + pub fn vt100_wrapper_screen_hide_cursor( + screen: *mut types::ScreenImpl, + ) -> libc::c_int; + pub fn vt100_wrapper_screen_application_keypad( + screen: *mut types::ScreenImpl, + ) -> libc::c_int; + pub fn vt100_wrapper_screen_application_cursor( + screen: *mut types::ScreenImpl, + ) -> libc::c_int; + pub fn vt100_wrapper_screen_mouse_reporting_press( + screen: *mut types::ScreenImpl, + ) -> libc::c_int; + pub fn vt100_wrapper_screen_mouse_reporting_press_release( + screen: *mut types::ScreenImpl, + ) -> libc::c_int; + pub fn vt100_wrapper_screen_mouse_reporting_button_motion( + screen: *mut types::ScreenImpl, + ) -> libc::c_int; + pub fn vt100_wrapper_screen_mouse_reporting_mode( + screen: *mut types::ScreenImpl, + ) -> libc::c_uchar; + pub fn vt100_wrapper_screen_bracketed_paste( + screen: *mut types::ScreenImpl, + ) -> libc::c_int; + pub fn vt100_wrapper_screen_visual_bell( + screen: *mut types::ScreenImpl, + ) -> libc::c_int; + pub fn vt100_wrapper_screen_audible_bell( + screen: *mut types::ScreenImpl, + ) -> libc::c_int; + pub fn vt100_wrapper_screen_update_title( + screen: *mut types::ScreenImpl, + ) -> libc::c_int; + pub fn vt100_wrapper_screen_update_icon_name( + screen: *mut types::ScreenImpl, + ) -> libc::c_int; + pub fn vt100_wrapper_screen_dirty( + screen: *mut types::ScreenImpl, + ) -> libc::c_int; + pub fn vt100_wrapper_screen_clear_visual_bell( + screen: *mut types::ScreenImpl, + ); + pub fn vt100_wrapper_screen_clear_audible_bell( + screen: *mut types::ScreenImpl, + ); + pub fn vt100_wrapper_screen_clear_update_title( + screen: *mut types::ScreenImpl, + ); + pub fn vt100_wrapper_screen_clear_update_icon_name( + screen: *mut types::ScreenImpl, + ); pub fn vt100_wrapper_screen_clear_dirty(screen: *mut types::ScreenImpl); - pub fn vt100_wrapper_cell_is_wide(cell: *mut types::CellImpl) -> libc::c_int; - pub fn vt100_wrapper_cell_attrs_bold(cell: *mut types::CellAttrs) -> libc::c_int; - pub fn vt100_wrapper_cell_attrs_italic(cell: *mut types::CellAttrs) -> libc::c_int; - pub fn vt100_wrapper_cell_attrs_underline(cell: *mut types::CellAttrs) -> libc::c_int; - pub fn vt100_wrapper_cell_attrs_inverse(cell: *mut types::CellAttrs) -> libc::c_int; + pub fn vt100_wrapper_cell_is_wide( + cell: *mut types::CellImpl, + ) -> libc::c_int; + pub fn vt100_wrapper_cell_attrs_bold( + cell: *mut types::CellAttrs, + ) -> libc::c_int; + pub fn vt100_wrapper_cell_attrs_italic( + cell: *mut types::CellAttrs, + ) -> libc::c_int; + pub fn vt100_wrapper_cell_attrs_underline( + cell: *mut types::CellAttrs, + ) -> libc::c_int; + pub fn vt100_wrapper_cell_attrs_inverse( + cell: *mut types::CellAttrs, + ) -> libc::c_int; } #[cfg(test)] @@ -12,6 +12,6 @@ mod ffi; mod screen; mod types; -pub use screen::Screen; pub use cell::Cell; pub use color::Color; +pub use screen::Screen; diff --git a/src/screen.rs b/src/screen.rs index 58986c7..041af0d 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -75,16 +75,17 @@ impl Screen { ffi::vt100_screen_process_string( screen_impl, s.as_ptr() as *const libc::c_char, - s.len() + s.len(), ) as u64 } } - pub fn window_contents(&self, + pub fn window_contents( + &self, row_start: i32, col_start: i32, row_end: i32, - col_end: i32 + col_end: i32, ) -> String { let Screen(screen_impl) = *self; let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix; @@ -94,27 +95,30 @@ impl Screen { let grid_max_row = unsafe { (*(*prefix).grid).max.row }; let row_count = unsafe { (*(*prefix).grid).row_count }; - let row_start = std::cmp::min( - std::cmp::max(row_start, 0), - self.rows() - 1 - ) + row_count - grid_max_row; - let col_start = std::cmp::min( - std::cmp::max(col_start, 0), - self.cols() - 1 - ); - let row_end = std::cmp::min( - std::cmp::max(row_end, 0), - self.rows() - 1 - ) + row_count - grid_max_row; - let col_end = std::cmp::min( - std::cmp::max(col_end, 0), - self.cols() - 1 - ); - - let start_loc = types::Loc { row: row_start, col: col_start }; - let end_loc = types::Loc { row: row_end, col: col_end }; - - let mut plaintext: *mut libc::c_char = unsafe { std::mem::uninitialized() }; + let row_start = + std::cmp::min(std::cmp::max(row_start, 0), self.rows() - 1) + + row_count + - grid_max_row; + let col_start = + std::cmp::min(std::cmp::max(col_start, 0), self.cols() - 1); + let row_end = + std::cmp::min(std::cmp::max(row_end, 0), self.rows() - 1) + + row_count + - grid_max_row; + let col_end = + std::cmp::min(std::cmp::max(col_end, 0), self.cols() - 1); + + let start_loc = types::Loc { + row: row_start, + col: col_start, + }; + let end_loc = types::Loc { + row: row_end, + col: col_end, + }; + + let mut plaintext: *mut libc::c_char = + unsafe { std::mem::uninitialized() }; let mut len: libc::size_t = unsafe { std::mem::uninitialized() }; unsafe { ffi::vt100_screen_get_string_plaintext( @@ -126,20 +130,19 @@ impl Screen { ) }; let rust_plaintext = unsafe { - std::slice::from_raw_parts( - plaintext as *mut libc::c_uchar, - len - ) - }.to_vec(); + std::slice::from_raw_parts(plaintext as *mut libc::c_uchar, len) + } + .to_vec(); unsafe { libc::free(plaintext as *mut libc::c_void) }; std::string::String::from_utf8(rust_plaintext).unwrap() } - pub fn window_contents_formatted(&self, + pub fn window_contents_formatted( + &self, row_start: i32, col_start: i32, row_end: i32, - col_end: i32 + col_end: i32, ) -> String { let Screen(screen_impl) = *self; let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix; @@ -147,27 +150,30 @@ impl Screen { let grid_max_row = unsafe { (*(*prefix).grid).max.row }; let row_count = unsafe { (*(*prefix).grid).row_count }; - let row_start = std::cmp::min( - std::cmp::max(row_start, 0), - self.rows() - 1 - ) + row_count - grid_max_row; - let col_start = std::cmp::min( - std::cmp::max(col_start, 0), - self.cols() - 1 - ); - let row_end = std::cmp::min( - std::cmp::max(row_end, 0), - self.rows() - 1 - ) + row_count - grid_max_row; - let col_end = std::cmp::min( - std::cmp::max(col_end, 0), - self.cols() - 1 - ); - - let start_loc = types::Loc { row: row_start, col: col_start }; - let end_loc = types::Loc { row: row_end, col: col_end }; - - let mut formatted: *mut libc::c_char = unsafe { std::mem::uninitialized() }; + let row_start = + std::cmp::min(std::cmp::max(row_start, 0), self.rows() - 1) + + row_count + - grid_max_row; + let col_start = + std::cmp::min(std::cmp::max(col_start, 0), self.cols() - 1); + let row_end = + std::cmp::min(std::cmp::max(row_end, 0), self.rows() - 1) + + row_count + - grid_max_row; + let col_end = + std::cmp::min(std::cmp::max(col_end, 0), self.cols() - 1); + + let start_loc = types::Loc { + row: row_start, + col: col_start, + }; + let end_loc = types::Loc { + row: row_end, + col: col_end, + }; + + let mut formatted: *mut libc::c_char = + unsafe { std::mem::uninitialized() }; let mut len: libc::size_t = unsafe { std::mem::uninitialized() }; unsafe { ffi::vt100_screen_get_string_formatted( @@ -179,31 +185,26 @@ impl Screen { ) }; let rust_formatted = unsafe { - std::slice::from_raw_parts( - formatted as *mut libc::c_uchar, - len - ) - }.to_vec(); + std::slice::from_raw_parts(formatted as *mut libc::c_uchar, len) + } + .to_vec(); std::string::String::from_utf8(rust_formatted).unwrap() } pub fn cell(&self, row: i32, col: i32) -> Option<cell::Cell> { let Screen(screen_impl) = *self; if row < 0 || row >= self.rows() || col < 0 || col >= self.cols() { - return None + return None; } - let cell_impl = unsafe { - ffi::vt100_screen_cell_at(screen_impl, row, col) - }; + let cell_impl = + unsafe { ffi::vt100_screen_cell_at(screen_impl, row, col) }; Some(cell::Cell::new(cell_impl)) } pub fn cursor_position(&self) -> (i32, i32) { let Screen(screen_impl) = *self; let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix; - unsafe { - ((*(*prefix).grid).cur.row, (*(*prefix).grid).cur.col) - } + unsafe { ((*(*prefix).grid).cur.row, (*(*prefix).grid).cur.col) } } pub fn title(&self) -> Option<&str> { @@ -211,12 +212,11 @@ impl Screen { let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix; if unsafe { (*prefix).title }.is_null() { None - } - else { + } else { let slice: &mut [u8] = unsafe { std::slice::from_raw_parts_mut( (*prefix).title as *mut u8, - (*prefix).title_len + (*prefix).title_len, ) }; Some(std::str::from_utf8(slice).unwrap()) @@ -228,12 +228,11 @@ impl Screen { let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix; if unsafe { (*prefix).icon_name }.is_null() { None - } - else { + } else { let slice: &mut [u8] = unsafe { std::slice::from_raw_parts_mut( (*prefix).icon_name as *mut u8, - (*prefix).icon_name_len + (*prefix).icon_name_len, ) }; Some(std::str::from_utf8(slice).unwrap()) @@ -288,9 +287,7 @@ impl Screen { pub fn hide_cursor(&self) -> bool { let Screen(screen_impl) = *self; - unsafe { - ffi::vt100_wrapper_screen_hide_cursor(screen_impl) != 0 - } + unsafe { ffi::vt100_wrapper_screen_hide_cursor(screen_impl) != 0 } } pub fn application_keypad(&self) -> bool { @@ -317,14 +314,18 @@ impl Screen { pub fn mouse_reporting_press_release(&self) -> bool { let Screen(screen_impl) = *self; unsafe { - ffi::vt100_wrapper_screen_mouse_reporting_press_release(screen_impl) != 0 + ffi::vt100_wrapper_screen_mouse_reporting_press_release( + screen_impl, + ) != 0 } } pub fn mouse_reporting_button_motion(&self) -> bool { let Screen(screen_impl) = *self; unsafe { - ffi::vt100_wrapper_screen_mouse_reporting_button_motion(screen_impl) != 0 + ffi::vt100_wrapper_screen_mouse_reporting_button_motion( + screen_impl, + ) != 0 } } @@ -337,9 +338,7 @@ impl Screen { pub fn bracketed_paste(&self) -> bool { let Screen(screen_impl) = *self; - unsafe { - ffi::vt100_wrapper_screen_bracketed_paste(screen_impl) != 0 - } + unsafe { ffi::vt100_wrapper_screen_bracketed_paste(screen_impl) != 0 } } pub fn alternate_buffer_active(&self) -> bool { @@ -351,7 +350,8 @@ impl Screen { pub fn check_visual_bell(&self) -> bool { let Screen(screen_impl) = *self; unsafe { - let state = ffi::vt100_wrapper_screen_visual_bell(screen_impl) != 0; + let state = + ffi::vt100_wrapper_screen_visual_bell(screen_impl) != 0; ffi::vt100_wrapper_screen_clear_visual_bell(screen_impl); state } @@ -360,7 +360,8 @@ impl Screen { pub fn check_audible_bell(&self) -> bool { let Screen(screen_impl) = *self; unsafe { - let state = ffi::vt100_wrapper_screen_audible_bell(screen_impl) != 0; + let state = + ffi::vt100_wrapper_screen_audible_bell(screen_impl) != 0; ffi::vt100_wrapper_screen_clear_audible_bell(screen_impl); state } @@ -369,7 +370,8 @@ impl Screen { pub fn check_update_title(&self) -> bool { let Screen(screen_impl) = *self; unsafe { - let state = ffi::vt100_wrapper_screen_update_title(screen_impl) != 0; + let state = + ffi::vt100_wrapper_screen_update_title(screen_impl) != 0; ffi::vt100_wrapper_screen_clear_update_title(screen_impl); state } @@ -378,7 +380,8 @@ impl Screen { pub fn check_update_icon_name(&self) -> bool { let Screen(screen_impl) = *self; unsafe { - let state = ffi::vt100_wrapper_screen_update_icon_name(screen_impl) != 0; + let state = + ffi::vt100_wrapper_screen_update_icon_name(screen_impl) != 0; ffi::vt100_wrapper_screen_clear_update_icon_name(screen_impl); state } diff --git a/tests/attr.rs b/tests/attr.rs index 33582c5..2532819 100644 --- a/tests/attr.rs +++ b/tests/attr.rs @@ -12,12 +12,24 @@ fn colors() { screen.assert_process(b"foo\x1b[31mbar"); assert_eq!(screen.cell(0, 0).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 0).unwrap().fgcolor(), vt100::Color::ColorDefault); - assert_eq!(screen.cell(0, 0).unwrap().bgcolor(), vt100::Color::ColorDefault); + assert_eq!( + screen.cell(0, 0).unwrap().fgcolor(), + vt100::Color::ColorDefault + ); + assert_eq!( + screen.cell(0, 0).unwrap().bgcolor(), + vt100::Color::ColorDefault + ); assert_eq!(screen.cell(0, 3).unwrap().contents(), "b"); - assert_eq!(screen.cell(0, 3).unwrap().fgcolor(), vt100::Color::ColorIdx(1)); - assert_eq!(screen.cell(0, 3).unwrap().bgcolor(), vt100::Color::ColorDefault); + assert_eq!( + screen.cell(0, 3).unwrap().fgcolor(), + vt100::Color::ColorIdx(1) + ); + assert_eq!( + screen.cell(0, 3).unwrap().bgcolor(), + vt100::Color::ColorDefault + ); assert_eq!(screen.fgcolor(), vt100::Color::ColorIdx(1)); assert_eq!(screen.bgcolor(), vt100::Color::ColorDefault); @@ -25,8 +37,14 @@ fn colors() { screen.assert_process(b"\x1b[2D\x1b[45mab"); assert_eq!(screen.cell(0, 4).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 4).unwrap().fgcolor(), vt100::Color::ColorIdx(1)); - assert_eq!(screen.cell(0, 4).unwrap().bgcolor(), vt100::Color::ColorIdx(5)); + assert_eq!( + screen.cell(0, 4).unwrap().fgcolor(), + vt100::Color::ColorIdx(1) + ); + assert_eq!( + screen.cell(0, 4).unwrap().bgcolor(), + vt100::Color::ColorIdx(5) + ); assert_eq!(screen.fgcolor(), vt100::Color::ColorIdx(1)); assert_eq!(screen.bgcolor(), vt100::Color::ColorIdx(5)); @@ -39,12 +57,24 @@ fn colors() { screen.assert_process(b"\x1b[15;15Hfoo\x1b[31mbar\x1b[m"); assert_eq!(screen.cell(14, 14).unwrap().contents(), "f"); - assert_eq!(screen.cell(14, 14).unwrap().fgcolor(), vt100::Color::ColorDefault); - assert_eq!(screen.cell(14, 14).unwrap().bgcolor(), vt100::Color::ColorDefault); + assert_eq!( + screen.cell(14, 14).unwrap().fgcolor(), + vt100::Color::ColorDefault + ); + assert_eq!( + screen.cell(14, 14).unwrap().bgcolor(), + vt100::Color::ColorDefault + ); assert_eq!(screen.cell(14, 17).unwrap().contents(), "b"); - assert_eq!(screen.cell(14, 17).unwrap().fgcolor(), vt100::Color::ColorIdx(1)); - assert_eq!(screen.cell(14, 17).unwrap().bgcolor(), vt100::Color::ColorDefault); + assert_eq!( + screen.cell(14, 17).unwrap().fgcolor(), + vt100::Color::ColorIdx(1) + ); + assert_eq!( + screen.cell(14, 17).unwrap().bgcolor(), + vt100::Color::ColorDefault + ); assert_eq!(screen.fgcolor(), vt100::Color::ColorDefault); assert_eq!(screen.bgcolor(), vt100::Color::ColorDefault); @@ -52,8 +82,14 @@ fn colors() { screen.assert_process(b"\x1b[2D\x1b[45mab"); assert_eq!(screen.cell(14, 18).unwrap().contents(), "a"); - assert_eq!(screen.cell(14, 18).unwrap().fgcolor(), vt100::Color::ColorDefault); - assert_eq!(screen.cell(14, 18).unwrap().bgcolor(), vt100::Color::ColorIdx(5)); + assert_eq!( + screen.cell(14, 18).unwrap().fgcolor(), + vt100::Color::ColorDefault + ); + assert_eq!( + screen.cell(14, 18).unwrap().bgcolor(), + vt100::Color::ColorIdx(5) + ); assert_eq!(screen.fgcolor(), vt100::Color::ColorDefault); assert_eq!(screen.bgcolor(), vt100::Color::ColorIdx(5)); @@ -64,25 +100,55 @@ fn colors() { assert_eq!(screen.fgcolor(), vt100::Color::ColorIdx(123)); assert_eq!(screen.bgcolor(), vt100::Color::ColorIdx(158)); - assert_eq!(screen.cell(0, 0).unwrap().fgcolor(), vt100::Color::ColorDefault); - assert_eq!(screen.cell(0, 0).unwrap().bgcolor(), vt100::Color::ColorDefault); - - assert_eq!(screen.cell(0, 1).unwrap().fgcolor(), vt100::Color::ColorIdx(123)); - assert_eq!(screen.cell(0, 1).unwrap().bgcolor(), vt100::Color::ColorDefault); - - assert_eq!(screen.cell(0, 2).unwrap().fgcolor(), vt100::Color::ColorIdx(123)); - assert_eq!(screen.cell(0, 2).unwrap().bgcolor(), vt100::Color::ColorIdx(158)); + assert_eq!( + screen.cell(0, 0).unwrap().fgcolor(), + vt100::Color::ColorDefault + ); + assert_eq!( + screen.cell(0, 0).unwrap().bgcolor(), + vt100::Color::ColorDefault + ); + + assert_eq!( + screen.cell(0, 1).unwrap().fgcolor(), + vt100::Color::ColorIdx(123) + ); + assert_eq!( + screen.cell(0, 1).unwrap().bgcolor(), + vt100::Color::ColorDefault + ); + + assert_eq!( + screen.cell(0, 2).unwrap().fgcolor(), + vt100::Color::ColorIdx(123) + ); + assert_eq!( + screen.cell(0, 2).unwrap().bgcolor(), + vt100::Color::ColorIdx(158) + ); screen.assert_process(b"\x1b[38;2;50;75;100md\x1b[48;2;125;150;175me"); assert_eq!(screen.fgcolor(), vt100::Color::ColorRgb(50, 75, 100)); assert_eq!(screen.bgcolor(), vt100::Color::ColorRgb(125, 150, 175)); - assert_eq!(screen.cell(0, 3).unwrap().fgcolor(), vt100::Color::ColorRgb(50, 75, 100)); - assert_eq!(screen.cell(0, 3).unwrap().bgcolor(), vt100::Color::ColorIdx(158)); - - assert_eq!(screen.cell(0, 4).unwrap().fgcolor(), vt100::Color::ColorRgb(50, 75, 100)); - assert_eq!(screen.cell(0, 4).unwrap().bgcolor(), vt100::Color::ColorRgb(125, 150, 175)); + assert_eq!( + screen.cell(0, 3).unwrap().fgcolor(), + vt100::Color::ColorRgb(50, 75, 100) + ); + assert_eq!( + screen.cell(0, 3).unwrap().bgcolor(), + vt100::Color::ColorIdx(158) + ); + + assert_eq!( + screen.cell(0, 4).unwrap().fgcolor(), + vt100::Color::ColorRgb(50, 75, 100) + ); + assert_eq!( + screen.cell(0, 4).unwrap().bgcolor(), + vt100::Color::ColorRgb(125, 150, 175) + ); screen.assert_process(b"\x1b[m\x1b[2J\x1b[H"); screen.assert_process(b"\x1b[32;47mfoo"); @@ -90,8 +156,14 @@ fn colors() { assert_eq!(screen.fgcolor(), vt100::Color::ColorIdx(2)); assert_eq!(screen.bgcolor(), vt100::Color::ColorIdx(7)); - assert_eq!(screen.cell(0, 1).unwrap().fgcolor(), vt100::Color::ColorIdx(2)); - assert_eq!(screen.cell(0, 1).unwrap().bgcolor(), vt100::Color::ColorIdx(7)); + assert_eq!( + screen.cell(0, 1).unwrap().fgcolor(), + vt100::Color::ColorIdx(2) + ); + assert_eq!( + screen.cell(0, 1).unwrap().bgcolor(), + vt100::Color::ColorIdx(7) + ); } #[test] @@ -103,30 +175,30 @@ fn attrs() { assert!(!screen.inverse()); screen.assert_process(b"f\x1b[1mo\x1b[3mo\x1b[4mo\x1b[7mo"); - assert!( screen.bold()); - assert!( screen.italic()); - assert!( screen.underline()); - assert!( screen.inverse()); + assert!(screen.bold()); + assert!(screen.italic()); + assert!(screen.underline()); + assert!(screen.inverse()); assert!(!screen.cell(0, 0).unwrap().bold()); assert!(!screen.cell(0, 0).unwrap().italic()); assert!(!screen.cell(0, 0).unwrap().underline()); assert!(!screen.cell(0, 0).unwrap().inverse()); - assert!( screen.cell(0, 1).unwrap().bold()); + assert!(screen.cell(0, 1).unwrap().bold()); assert!(!screen.cell(0, 1).unwrap().italic()); assert!(!screen.cell(0, 1).unwrap().underline()); assert!(!screen.cell(0, 1).unwrap().inverse()); - assert!( screen.cell(0, 2).unwrap().bold()); - assert!( screen.cell(0, 2).unwrap().italic()); + assert!(screen.cell(0, 2).unwrap().bold()); + assert!(screen.cell(0, 2).unwrap().italic()); assert!(!screen.cell(0, 2).unwrap().underline()); assert!(!screen.cell(0, 2).unwrap().inverse()); - assert!( screen.cell(0, 3).unwrap().bold()); - assert!( screen.cell(0, 3).unwrap().italic()); - assert!( screen.cell(0, 3).unwrap().underline()); + assert!(screen.cell(0, 3).unwrap().bold()); + assert!(screen.cell(0, 3).unwrap().italic()); + assert!(screen.cell(0, 3).unwrap().underline()); assert!(!screen.cell(0, 3).unwrap().inverse()); - assert!( screen.cell(0, 4).unwrap().bold()); - assert!( screen.cell(0, 4).unwrap().italic()); - assert!( screen.cell(0, 4).unwrap().underline()); - assert!( screen.cell(0, 4).unwrap().inverse()); + assert!(screen.cell(0, 4).unwrap().bold()); + assert!(screen.cell(0, 4).unwrap().italic()); + assert!(screen.cell(0, 4).unwrap().underline()); + assert!(screen.cell(0, 4).unwrap().inverse()); screen.assert_process(b"\x1b[m"); assert!(!screen.bold()); @@ -136,13 +208,13 @@ fn attrs() { screen.assert_process(b"\x1b[2J\x1b[H"); screen.assert_process(b"\x1b[1;4mf"); - assert!( screen.bold()); + assert!(screen.bold()); assert!(!screen.italic()); - assert!( screen.underline()); + assert!(screen.underline()); assert!(!screen.inverse()); - assert!( screen.cell(0, 0).unwrap().bold()); + assert!(screen.cell(0, 0).unwrap().bold()); assert!(!screen.cell(0, 0).unwrap().italic()); - assert!( screen.cell(0, 0).unwrap().underline()); + assert!(screen.cell(0, 0).unwrap().underline()); assert!(!screen.cell(0, 0).unwrap().inverse()); screen.assert_process(b"\x1b[22mo\x1b[24mo"); @@ -152,7 +224,7 @@ fn attrs() { assert!(!screen.inverse()); assert!(!screen.cell(0, 1).unwrap().bold()); assert!(!screen.cell(0, 1).unwrap().italic()); - assert!( screen.cell(0, 1).unwrap().underline()); + assert!(screen.cell(0, 1).unwrap().underline()); assert!(!screen.cell(0, 1).unwrap().inverse()); assert!(!screen.cell(0, 2).unwrap().bold()); assert!(!screen.cell(0, 2).unwrap().italic()); @@ -160,12 +232,12 @@ fn attrs() { assert!(!screen.cell(0, 2).unwrap().inverse()); screen.assert_process(b"\x1b[1;3;4;7mo"); - assert!( screen.bold()); - assert!( screen.italic()); - assert!( screen.underline()); - assert!( screen.inverse()); - assert!( screen.cell(0, 3).unwrap().bold()); - assert!( screen.cell(0, 3).unwrap().italic()); - assert!( screen.cell(0, 3).unwrap().underline()); - assert!( screen.cell(0, 3).unwrap().inverse()); + assert!(screen.bold()); + assert!(screen.italic()); + assert!(screen.underline()); + assert!(screen.inverse()); + assert!(screen.cell(0, 3).unwrap().bold()); + assert!(screen.cell(0, 3).unwrap().italic()); + assert!(screen.cell(0, 3).unwrap().underline()); + assert!(screen.cell(0, 3).unwrap().inverse()); } diff --git a/tests/control.rs b/tests/control.rs index 837f83c..787bdc2 100644 --- a/tests/control.rs +++ b/tests/control.rs @@ -24,7 +24,10 @@ fn bs() { assert_eq!(screen.cell(0, 2).unwrap().contents(), "a"); assert_eq!(screen.cell(0, 3).unwrap().contents(), ""); assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.window_contents(0, 0, 23, 79), "faa\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "faa\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"\r\nquux\x08\x08\x08\x08\x08\x08bar"); assert_eq!(screen.cell(1, 0).unwrap().contents(), "b"); @@ -33,7 +36,10 @@ fn bs() { assert_eq!(screen.cell(1, 3).unwrap().contents(), "x"); assert_eq!(screen.cell(1, 4).unwrap().contents(), ""); assert_eq!(screen.cell(2, 0).unwrap().contents(), ""); - assert_eq!(screen.window_contents(0, 0, 23, 79), "faa\nbarx\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "faa\nbarx\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); } #[test] @@ -53,7 +59,10 @@ fn tab() { assert_eq!(screen.cell(0, 9).unwrap().contents(), "a"); assert_eq!(screen.cell(0, 10).unwrap().contents(), "r"); assert_eq!(screen.cell(0, 11).unwrap().contents(), ""); - assert_eq!(screen.window_contents(0, 0, 23, 79), "foo bar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "foo bar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); } #[test] @@ -72,7 +81,10 @@ fn lf() { assert_eq!(screen.cell(1, 4).unwrap().contents(), "a"); assert_eq!(screen.cell(1, 5).unwrap().contents(), "r"); assert_eq!(screen.cell(1, 6).unwrap().contents(), ""); - assert_eq!(screen.window_contents(0, 0, 23, 79), "foo\n bar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "foo\n bar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); } #[test] @@ -86,5 +98,8 @@ fn cr() { assert_eq!(screen.cell(0, 3).unwrap().contents(), "o"); assert_eq!(screen.cell(0, 4).unwrap().contents(), ""); assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.window_contents(0, 0, 23, 79), "baro\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "baro\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); } diff --git a/tests/csi.rs b/tests/csi.rs index d525262..e19f377 100644 --- a/tests/csi.rs +++ b/tests/csi.rs @@ -96,7 +96,10 @@ fn relative_movement() { #[test] fn ed() { let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"foo\x1b[5;5Hbar\x1b[10;10Hbaz\x1b[20;20Hquux"); assert_eq!(screen.window_contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux\n\n\n\n\n"); @@ -105,13 +108,22 @@ fn ed() { assert_eq!(screen.window_contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n ba\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); screen.assert_process(b"\x1b[5;7H\x1b[1J"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n r\n\n\n\n\n ba\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n r\n\n\n\n\n ba\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"\x1b[7;7H\x1b[2J"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"\x1b[2J\x1b[H"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"foo\x1b[5;5Hbar\x1b[10;10Hbaz\x1b[20;20Hquux"); assert_eq!(screen.window_contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux\n\n\n\n\n"); @@ -120,7 +132,10 @@ fn ed() { assert_eq!(screen.window_contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n ba\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); screen.assert_process(b"\x1b[2J\x1b[H"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"foo\x1b[5;5Hbar\x1b[10;10Hbaz\x1b[20;20Hquux"); assert_eq!(screen.window_contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux\n\n\n\n\n"); @@ -129,13 +144,22 @@ fn ed() { assert_eq!(screen.window_contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n ba\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); screen.assert_process(b"\x1b[5;7H\x1b[?1J"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n r\n\n\n\n\n ba\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n r\n\n\n\n\n ba\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"\x1b[7;7H\x1b[?2J"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"\x1b[2J\x1b[H"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"foo\x1b[5;5Hbar\x1b[10;10Hbaz\x1b[20;20Hquux"); assert_eq!(screen.window_contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux\n\n\n\n\n"); @@ -147,9 +171,14 @@ fn ed() { #[test] fn el() { let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - - screen.assert_process(b"foo\x1b[5;5Hbarbar\x1b[10;10Hbazbaz\x1b[20;20Hquux"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); + + screen.assert_process( + b"foo\x1b[5;5Hbarbar\x1b[10;10Hbazbaz\x1b[20;20Hquux", + ); assert_eq!(screen.window_contents(0, 0, 23, 79), "foo\n\n\n\n barbar\n\n\n\n\n bazbaz\n\n\n\n\n\n\n\n\n\n quux\n\n\n\n\n"); screen.assert_process(b"\x1b[5;8H\x1b[0K"); @@ -165,9 +194,14 @@ fn el() { assert_eq!(screen.window_contents(0, 0, 23, 79), "f\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); screen.assert_process(b"\x1b[2J\x1b[H"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - - screen.assert_process(b"foo\x1b[5;5Hbarbar\x1b[10;10Hbazbaz\x1b[20;20Hquux"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); + + screen.assert_process( + b"foo\x1b[5;5Hbarbar\x1b[10;10Hbazbaz\x1b[20;20Hquux", + ); assert_eq!(screen.window_contents(0, 0, 23, 79), "foo\n\n\n\n barbar\n\n\n\n\n bazbaz\n\n\n\n\n\n\n\n\n\n quux\n\n\n\n\n"); screen.assert_process(b"\x1b[5;8H\x1b[?0K"); @@ -186,90 +220,153 @@ fn el() { #[test] fn ich_dch_ech() { let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"\x1b[10;10Hfoobar"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"\x1b[10;12H\x1b[3@"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n fo obar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n fo obar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (9, 11)); screen.assert_process(b"\x1b[4P"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n fobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n fobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (9, 11)); screen.assert_process(b"\x1b[100@"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n fo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n fo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (9, 11)); screen.assert_process(b"obar"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (9, 15)); screen.assert_process(b"\x1b[10;12H\x1b[100P"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n fo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n fo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (9, 11)); screen.assert_process(b"obar"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (9, 15)); screen.assert_process(b"\x1b[10;13H\x1b[X"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n foo ar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n foo ar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (9, 12)); screen.assert_process(b"\x1b[10;11H\x1b[4X"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n f r\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n f r\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (9, 10)); screen.assert_process(b"\x1b[10;11H\x1b[400X"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n f\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n f\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (9, 10)); } #[test] fn il_dl() { let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"\x1b[10;10Hfoobar\x1b[3D"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (9, 12)); screen.assert_process(b"\x1b[L"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (9, 12)); screen.assert_process(b"\x1b[3L"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (9, 12)); screen.assert_process(b"\x1b[500L"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (9, 12)); screen.assert_process(b"\x1b[10;10Hfoobar\x1b[3D\x1b[6A"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (3, 12)); screen.assert_process(b"\x1b[M"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (3, 12)); screen.assert_process(b"\x1b[3M"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (3, 12)); screen.assert_process(b"\x1b[500M"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.cursor_position(), (3, 12)); } #[test] fn scroll() { let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24"); assert_eq!(screen.window_contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n"); diff --git a/tests/escape.rs b/tests/escape.rs index acbad5c..4c01c82 100644 --- a/tests/escape.rs +++ b/tests/escape.rs @@ -17,7 +17,10 @@ fn deckpam() { fn ri() { let mut screen = vt100::Screen::new(24, 80); screen.assert_process(b"foo\nbar\x1bMbaz"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "foo baz\n bar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "foo baz\n bar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); } #[test] @@ -28,8 +31,14 @@ fn ris() { let cell = screen.cell(0, 0).unwrap(); assert_eq!(cell.contents(), ""); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - assert_eq!(screen.window_contents_formatted(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); + assert_eq!( + screen.window_contents_formatted(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.title(), None); assert_eq!(screen.icon_name(), None); @@ -60,7 +69,10 @@ fn ris() { let cell = screen.cell(0, 0).unwrap(); assert_eq!(cell.contents(), "f"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "foo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "foo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.window_contents_formatted(0, 0, 23, 79), "f\x1b[31;47;1;3;4moo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); assert_eq!(screen.title().unwrap(), "window title"); @@ -91,8 +103,14 @@ fn ris() { let cell = screen.cell(0, 0).unwrap(); assert_eq!(cell.contents(), ""); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - assert_eq!(screen.window_contents_formatted(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); + assert_eq!( + screen.window_contents_formatted(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); // title and icon name don't change with reset assert_eq!(screen.title().unwrap(), "window title"); @@ -131,5 +149,8 @@ fn vb() { fn decsc() { let mut screen = vt100::Screen::new(24, 80); screen.assert_process(b"foo\x1b7\r\n\r\n\r\n bar\x1b8baz"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "foobaz\n\n\n bar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "foobaz\n\n\n bar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); } diff --git a/tests/init.rs b/tests/init.rs index eb71a43..eb3179a 100644 --- a/tests/init.rs +++ b/tests/init.rs @@ -16,8 +16,14 @@ fn init() { let cell = screen.cell(0, 80); assert!(cell.is_none()); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - assert_eq!(screen.window_contents_formatted(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); + assert_eq!( + screen.window_contents_formatted(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert_eq!(screen.title(), None); assert_eq!(screen.icon_name(), None); diff --git a/tests/mode.rs b/tests/mode.rs index 19658b2..50f18ba 100644 --- a/tests/mode.rs +++ b/tests/mode.rs @@ -199,10 +199,16 @@ fn alternate_buffer() { assert_eq!(screen.window_contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n"); assert!(!screen.alternate_buffer_active()); screen.assert_process(b"\x1b[?1049h"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); assert!(screen.alternate_buffer_active()); screen.assert_process(b"foobar"); - assert_eq!(screen.window_contents(0, 0, 23, 79), "foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); screen.assert_process(b"\x1b[?1049l"); assert_eq!(screen.window_contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n"); assert!(!screen.alternate_buffer_active()); diff --git a/tests/text.rs b/tests/text.rs index 5e33e0d..13bd96c 100644 --- a/tests/text.rs +++ b/tests/text.rs @@ -12,8 +12,14 @@ fn ascii() { assert_eq!(screen.cell(0, 2).unwrap().contents(), "o"); assert_eq!(screen.cell(0, 3).unwrap().contents(), ""); assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.window_contents(0, 0, 23, 79), "foo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - assert_eq!(screen.window_contents(0, 0, 500, 500), "foo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "foo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); + assert_eq!( + screen.window_contents(0, 0, 500, 500), + "foo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); } #[test] @@ -26,8 +32,14 @@ fn utf8() { assert_eq!(screen.cell(0, 3).unwrap().contents(), "é"); assert_eq!(screen.cell(0, 4).unwrap().contents(), ""); assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.window_contents(0, 0, 23, 79), "café\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - assert_eq!(screen.window_contents(0, 0, 500, 500), "café\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "café\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); + assert_eq!( + screen.window_contents(0, 0, 500, 500), + "café\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); } #[test] @@ -45,8 +57,14 @@ fn newlines() { assert_eq!(screen.cell(2, 2).unwrap().contents(), "d"); assert_eq!(screen.cell(0, 3).unwrap().contents(), ""); assert_eq!(screen.cell(3, 0).unwrap().contents(), ""); - assert_eq!(screen.window_contents(0, 0, 23, 79), "f\noo\nood\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - assert_eq!(screen.window_contents(0, 0, 500, 500), "f\noo\nood\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "f\noo\nood\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); + assert_eq!( + screen.window_contents(0, 0, 500, 500), + "f\noo\nood\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); } #[test] @@ -61,8 +79,14 @@ fn wide() { assert_eq!(screen.cell(0, 5).unwrap().contents(), ""); assert_eq!(screen.cell(0, 6).unwrap().contents(), ""); assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.window_contents(0, 0, 23, 79), "aデbネ\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - assert_eq!(screen.window_contents(0, 0, 500, 500), "aデbネ\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + assert_eq!( + screen.window_contents(0, 0, 23, 79), + "aデbネ\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); + assert_eq!( + screen.window_contents(0, 0, 500, 500), + "aデbネ\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); } #[test] |