aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-10-29 13:42:00 -0400
committerJesse Luehrs <doy@tozt.net>2019-10-29 13:42:00 -0400
commitf84638fd816d2295c5d9f60c0ac8eb6df50d1aba (patch)
tree4562b26f23283710e454d257114813be1623ea1d
parente525fddb572614f4c6d6a7d71ed44e9dfe7af350 (diff)
downloadvt100-rust-f84638fd816d2295c5d9f60c0ac8eb6df50d1aba.tar.gz
vt100-rust-f84638fd816d2295c5d9f60c0ac8eb6df50d1aba.zip
start the rewrite
-rw-r--r--.gitignore3
-rw-r--r--.gitmodules3
-rw-r--r--Cargo.toml11
-rw-r--r--build.rs46
m---------libvt1000
-rw-r--r--src/cell.rs94
-rw-r--r--src/color.rs25
-rw-r--r--src/ffi.c118
-rw-r--r--src/ffi.rs127
-rw-r--r--src/lib.rs19
-rw-r--r--src/parser.rs7
-rw-r--r--src/pos.rs11
-rw-r--r--src/screen.rs437
-rw-r--r--src/types.rs19
-rw-r--r--tests/attr.rs137
-rw-r--r--tests/basic.rs24
-rw-r--r--tests/control.rs2
-rw-r--r--tests/csi.rs2
-rw-r--r--tests/escape.rs14
-rw-r--r--tests/init.rs8
-rw-r--r--tests/mode.rs2
-rw-r--r--tests/osc.rs2
-rw-r--r--tests/processing.rs2
-rw-r--r--tests/scroll.rs2
-rw-r--r--tests/split-escapes.rs8
-rw-r--r--tests/support/mod.rs8
-rw-r--r--tests/text.rs2
-rw-r--r--tests/zero-width.rs2
28 files changed, 234 insertions, 901 deletions
diff --git a/.gitignore b/.gitignore
index a9d37c5..6936990 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
-target
+/target
+**/*.rs.bk
Cargo.lock
diff --git a/.gitmodules b/.gitmodules
index 0077c76..e69de29 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +0,0 @@
-[submodule "libvt100"]
- path = libvt100
- url = https://github.com/doy/libvt100
diff --git a/Cargo.toml b/Cargo.toml
index ee7987c..df638d9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,6 +2,7 @@
name = "vt100"
version = "0.1.2"
authors = ["Jesse Luehrs <doy@tozt.net>"]
+edition = "2018"
description = "Library for parsing terminal data"
homepage = "https://github.com/doy/vt100-rust"
@@ -9,13 +10,3 @@ repository = "https://github.com/doy/vt100-rust"
readme = "README.md"
keywords = ["terminal", "vt100"]
license = "MIT"
-
-build = "build.rs"
-
-[build-dependencies]
-cc = "1.0"
-pkg-config = "0.3.8"
-
-[dependencies]
-libc = "0.2.10"
-glib-sys = "0.3.0"
diff --git a/build.rs b/build.rs
deleted file mode 100644
index 5c50c00..0000000
--- a/build.rs
+++ /dev/null
@@ -1,46 +0,0 @@
-extern crate cc;
-extern crate pkg_config;
-
-fn libvt100() {
- let dir = std::env::current_dir()
- .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));
- let absdir = std::env::current_dir()
- .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));
- std::env::set_current_dir(dir)
- .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-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);
- });
- 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");
-}
-
-fn main() {
- libvt100();
- glib();
- libvt100_wrappers();
-}
diff --git a/libvt100 b/libvt100
deleted file mode 160000
-Subproject b7d5ababc641e86e70308f182ad768b5fc1e99a
diff --git a/src/cell.rs b/src/cell.rs
index 40b7fad..b1821c6 100644
--- a/src/cell.rs
+++ b/src/cell.rs
@@ -1,84 +1,58 @@
-use libc;
-use std;
-
-use color;
-use ffi;
-use types;
-
-pub struct Cell(*mut types::CellImpl);
-
-#[repr(C)]
-struct CellPrefix {
- pub contents: [libc::c_char; 8],
- pub len: libc::size_t,
- pub attrs: types::CellAttrs,
+#[derive(Clone, Debug)]
+pub struct Cell {
+ contents: String,
+ fgcolor: crate::color::Color,
+ bgcolor: crate::color::Color,
+ bold: bool,
+ italic: bool,
+ inverse: bool,
+ underline: bool,
}
impl Cell {
- pub fn new(cell_impl: *mut types::CellImpl) -> Cell {
- Cell(cell_impl)
+ pub fn new() -> Self {
+ Self::default()
}
pub fn contents(&self) -> &str {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- let contents: &[u8] = unsafe {
- std::slice::from_raw_parts(
- &(*prefix).contents as *const i8 as *const u8,
- (*prefix).len,
- )
- };
- std::str::from_utf8(contents).unwrap()
+ &self.contents
}
- pub fn fgcolor(&self) -> color::Color {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- let attrs = unsafe { &(*prefix).attrs };
- color::Color::new(&attrs.fgcolor)
+ pub fn fgcolor(&self) -> crate::color::Color {
+ self.fgcolor
}
- pub fn bgcolor(&self) -> color::Color {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- let attrs = unsafe { &(*prefix).attrs };
- color::Color::new(&attrs.bgcolor)
- }
-
- pub fn is_wide(&self) -> bool {
- let Cell(cell_impl) = *self;
- unsafe { ffi::vt100_wrapper_cell_is_wide(cell_impl) != 0 }
+ pub fn bgcolor(&self) -> crate::color::Color {
+ self.bgcolor
}
pub fn bold(&self) -> bool {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- unsafe {
- ffi::vt100_wrapper_cell_attrs_bold(&mut (*prefix).attrs) != 0
- }
+ self.bold
}
pub fn italic(&self) -> bool {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- unsafe {
- ffi::vt100_wrapper_cell_attrs_italic(&mut (*prefix).attrs) != 0
- }
+ self.italic
+ }
+
+ pub fn inverse(&self) -> bool {
+ self.inverse
}
pub fn underline(&self) -> bool {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- unsafe {
- ffi::vt100_wrapper_cell_attrs_underline(&mut (*prefix).attrs) != 0
- }
+ self.underline
}
+}
- pub fn inverse(&self) -> bool {
- let Cell(cell_impl) = *self;
- let prefix: *mut CellPrefix = cell_impl as *mut CellPrefix;
- unsafe {
- ffi::vt100_wrapper_cell_attrs_inverse(&mut (*prefix).attrs) != 0
+impl Default for Cell {
+ fn default() -> Self {
+ Self {
+ contents: String::new(),
+ fgcolor: crate::color::Color::Default,
+ bgcolor: crate::color::Color::Default,
+ bold: false,
+ italic: false,
+ inverse: false,
+ underline: false,
}
}
}
diff --git a/src/color.rs b/src/color.rs
index 76f8ab3..b93acea 100644
--- a/src/color.rs
+++ b/src/color.rs
@@ -1,23 +1,12 @@
-use std;
-
-use types;
-
-#[derive(Eq, PartialEq, Debug)]
+#[derive(Eq, PartialEq, Debug, Copy, Clone)]
pub enum Color {
- ColorDefault,
- ColorIdx(u8),
- ColorRgb(u8, u8, u8),
+ Default,
+ Idx(u8),
+ Rgb(u8, u8, u8),
}
-impl Color {
- pub fn new(color_impl: &types::ColorImpl) -> Color {
- let &types::ColorImpl(color_repr) = color_impl;
- let bytes: [u8; 4] = unsafe { std::mem::transmute(color_repr) };
- match bytes[3] {
- 0 => Color::ColorDefault,
- 1 => Color::ColorIdx(bytes[0]),
- 2 => Color::ColorRgb(bytes[0], bytes[1], bytes[2]),
- _ => panic!("invalid color type"),
- }
+impl Default for Color {
+ fn default() -> Self {
+ Self::Default
}
}
diff --git a/src/ffi.c b/src/ffi.c
deleted file mode 100644
index cff8da3..0000000
--- a/src/ffi.c
+++ /dev/null
@@ -1,118 +0,0 @@
-#include <stdlib.h>
-#include "../libvt100/src/vt100.h"
-
-int vt100_wrapper_screen_hide_cursor(struct vt100_screen *screen)
-{
- return screen->hide_cursor;
-}
-
-int vt100_wrapper_screen_application_keypad(struct vt100_screen *screen)
-{
- return screen->application_keypad;
-}
-
-int vt100_wrapper_screen_application_cursor(struct vt100_screen *screen)
-{
- return screen->application_cursor;
-}
-
-int vt100_wrapper_screen_mouse_reporting_press(struct vt100_screen *screen)
-{
- return screen->mouse_reporting_press;
-}
-
-int vt100_wrapper_screen_mouse_reporting_press_release(struct vt100_screen *screen)
-{
- return screen->mouse_reporting_press_release;
-}
-
-int vt100_wrapper_screen_mouse_reporting_button_motion(struct vt100_screen *screen)
-{
- return screen->mouse_reporting_button_motion;
-}
-
-unsigned char vt100_wrapper_screen_mouse_reporting_mode(
- struct vt100_screen *screen)
-{
- return screen->mouse_reporting_mode;
-}
-
-int vt100_wrapper_screen_bracketed_paste(struct vt100_screen *screen)
-{
- return screen->bracketed_paste;
-}
-
-int vt100_wrapper_screen_visual_bell(struct vt100_screen *screen)
-{
- return screen->visual_bell;
-}
-
-int vt100_wrapper_screen_audible_bell(struct vt100_screen *screen)
-{
- return screen->audible_bell;
-}
-
-int vt100_wrapper_screen_update_title(struct vt100_screen *screen)
-{
- return screen->update_title;
-}
-
-int vt100_wrapper_screen_update_icon_name(struct vt100_screen *screen)
-{
- return screen->update_icon_name;
-}
-
-int vt100_wrapper_screen_dirty(struct vt100_screen *screen)
-{
- return screen->dirty;
-}
-
-void vt100_wrapper_screen_clear_visual_bell(struct vt100_screen *screen)
-{
- screen->visual_bell = 0;
-}
-
-void vt100_wrapper_screen_clear_audible_bell(struct vt100_screen *screen)
-{
- screen->audible_bell = 0;
-}
-
-void vt100_wrapper_screen_clear_update_title(struct vt100_screen *screen)
-{
- screen->update_title = 0;
-}
-
-void vt100_wrapper_screen_clear_update_icon_name(struct vt100_screen *screen)
-{
- screen->update_icon_name = 0;
-}
-
-void vt100_wrapper_screen_clear_dirty(struct vt100_screen *screen)
-{
- screen->dirty = 0;
-}
-
-int vt100_wrapper_cell_is_wide(struct vt100_cell *cell)
-{
- return cell->is_wide;
-}
-
-int vt100_wrapper_cell_attrs_bold(struct vt100_cell_attrs *attrs)
-{
- return attrs->bold;
-}
-
-int vt100_wrapper_cell_attrs_italic(struct vt100_cell_attrs *attrs)
-{
- return attrs->italic;
-}
-
-int vt100_wrapper_cell_attrs_underline(struct vt100_cell_attrs *attrs)
-{
- return attrs->underline;
-}
-
-int vt100_wrapper_cell_attrs_inverse(struct vt100_cell_attrs *attrs)
-{
- return attrs->inverse;
-}
diff --git a/src/ffi.rs b/src/ffi.rs
deleted file mode 100644
index f86eb12..0000000
--- a/src/ffi.rs
+++ /dev/null
@@ -1,127 +0,0 @@
-use libc;
-
-use types;
-
-extern "C" {
- pub fn vt100_screen_new(
- rows: libc::c_int,
- cols: libc::c_int,
- ) -> *mut types::ScreenImpl;
- pub fn vt100_screen_delete(screen: *mut types::ScreenImpl);
-
- pub fn vt100_screen_process_string(
- screen: *mut types::ScreenImpl,
- buf: *const libc::c_char,
- len: libc::size_t,
- ) -> libc::c_int;
- pub fn vt100_screen_get_string_plaintext(
- screen: *mut types::ScreenImpl,
- start: *const types::Loc,
- end: *const types::Loc,
- outp: *mut *mut libc::c_char,
- outlen: *mut libc::size_t,
- );
- pub fn vt100_screen_get_string_formatted(
- screen: *mut types::ScreenImpl,
- start: *const types::Loc,
- end: *const types::Loc,
- outp: *mut *mut libc::c_char,
- outlen: *mut libc::size_t,
- );
-
- pub fn vt100_screen_set_window_size(
- screen: *mut types::ScreenImpl,
- rows: libc::c_int,
- cols: libc::c_int,
- );
- pub fn vt100_screen_set_scrollback_length(
- screen: *mut types::ScreenImpl,
- rows: libc::c_int,
- );
-
- pub fn vt100_screen_cell_at(
- screen: *mut types::ScreenImpl,
- row: libc::c_int,
- col: libc::c_int,
- ) -> *mut types::CellImpl;
-
- // 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_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;
-}
-
-#[cfg(test)]
-mod tests {
- #[test]
- fn ffi() {
- let ptr = unsafe { super::vt100_screen_new(24, 80) };
- assert!(!ptr.is_null());
- unsafe { super::vt100_screen_delete(ptr) };
- }
-}
diff --git a/src/lib.rs b/src/lib.rs
index 2852c57..3db6c7d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,17 +1,12 @@
-#![cfg_attr(feature = "cargo-clippy", feature(tool_lints))]
-// we use empty enums to represent opaque c pointers, but we don't have a way
-// to indicate that those pointers do actually have additional alignment
-// restrictions, so casting them to their prefixes is actually safe
-#![cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))]
-
-extern crate libc;
+#![warn(clippy::pedantic)]
+#![warn(clippy::nursery)]
+#![allow(clippy::missing_const_for_fn)]
mod cell;
-mod color;
-mod ffi;
-mod screen;
-mod types;
-
pub use cell::Cell;
+mod color;
pub use color::Color;
+mod parser;
+mod pos;
+mod screen;
pub use screen::Screen;
diff --git a/src/parser.rs b/src/parser.rs
new file mode 100644
index 0000000..c805469
--- /dev/null
+++ b/src/parser.rs
@@ -0,0 +1,7 @@
+pub struct Parser {}
+
+impl Parser {
+ pub fn new() -> Self {
+ Parser {}
+ }
+}
diff --git a/src/pos.rs b/src/pos.rs
new file mode 100644
index 0000000..0759527
--- /dev/null
+++ b/src/pos.rs
@@ -0,0 +1,11 @@
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+pub struct Pos {
+ pub row: u16,
+ pub col: u16,
+}
+
+impl Default for Pos {
+ fn default() -> Self {
+ Self { row: 0, col: 0 }
+ }
+}
diff --git a/src/screen.rs b/src/screen.rs
index 041af0d..88a3629 100644
--- a/src/screen.rs
+++ b/src/screen.rs
@@ -1,405 +1,160 @@
-use libc;
-use std;
-
-use cell;
-use color;
-use ffi;
-use types;
-
-pub struct Screen(*mut types::ScreenImpl);
-
-#[repr(C)]
-struct ScreenGridPrefix {
- cur: types::Loc,
- max: types::Loc,
- saved: types::Loc,
- scroll_top: libc::c_int,
- scroll_bottom: libc::c_int,
- row_count: libc::c_int,
- row_capacity: libc::c_int,
- row_top: libc::c_int,
-}
-
-enum ScreenParserState {}
-
-#[repr(C)]
-struct ScreenPrefix {
- grid: *mut ScreenGridPrefix,
- alternate: *mut ScreenGridPrefix,
-
- parser_state: *mut ScreenParserState,
-
- title: *mut libc::c_char,
- title_len: libc::size_t,
- icon_name: *mut libc::c_char,
- icon_name_len: libc::size_t,
-
- scrollback_length: libc::c_int,
-
- attrs: types::CellAttrs,
+pub struct Screen {
+ size: crate::pos::Pos,
+ parser: crate::parser::Parser,
+ cells: Vec<Vec<crate::cell::Cell>>,
+ cursor_position: crate::pos::Pos,
+ fgcolor: crate::color::Color,
+ bgcolor: crate::color::Color,
+ bold: bool,
+ italic: bool,
+ inverse: bool,
+ underline: bool,
}
impl Screen {
- pub fn new(rows: i32, cols: i32) -> Screen {
- let screen_impl = unsafe {
- ffi::vt100_screen_new(rows as libc::c_int, cols as libc::c_int)
+ pub fn new(rows: u16, cols: u16) -> Self {
+ Self {
+ size: crate::pos::Pos {
+ row: rows,
+ col: cols,
+ },
+ parser: crate::parser::Parser::new(),
+ cells: vec![
+ vec![crate::cell::Cell::default(); cols as usize];
+ rows as usize
+ ],
+ cursor_position: crate::pos::Pos::default(),
+ fgcolor: crate::color::Color::default(),
+ bgcolor: crate::color::Color::default(),
+ bold: false,
+ italic: false,
+ inverse: false,
+ underline: false,
+ }
+ }
+
+ pub fn rows(&self) -> u16 {
+ self.size.row
+ }
+
+ pub fn cols(&self) -> u16 {
+ self.size.col
+ }
+
+ pub fn set_window_size(&mut self, rows: u16, cols: u16) {
+ self.size = crate::pos::Pos {
+ row: rows,
+ col: cols,
};
- Screen(screen_impl)
}
- pub fn rows(&self) -> i32 {
- let Screen(screen_impl) = *self;
- let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix;
- unsafe { (*(*prefix).grid).max.row }
+ pub fn process(&mut self, bytes: &[u8]) -> usize {
+ unimplemented!()
}
- pub fn cols(&self) -> i32 {
- let Screen(screen_impl) = *self;
- let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix;
- unsafe { (*(*prefix).grid).max.col }
- }
-
- pub fn set_window_size(&self, rows: i32, cols: i32) {
- let Screen(screen_impl) = *self;
- unsafe { ffi::vt100_screen_set_window_size(screen_impl, rows, cols) };
- }
-
- pub fn set_scrollback_length(&self, rows: i32) {
- let Screen(screen_impl) = *self;
- unsafe { ffi::vt100_screen_set_scrollback_length(screen_impl, rows) };
- }
-
- pub fn process(&mut self, s: &[u8]) -> u64 {
- let Screen(screen_impl) = *self;
- unsafe {
- ffi::vt100_screen_process_string(
- screen_impl,
- s.as_ptr() as *const libc::c_char,
- s.len(),
- ) as u64
- }
+ pub fn cell(&self, row: u16, col: u16) -> Option<&crate::cell::Cell> {
+ self.cells
+ .get(row as usize)
+ .and_then(|v| v.get(col as usize))
}
pub fn window_contents(
&self,
- row_start: i32,
- col_start: i32,
- row_end: i32,
- col_end: i32,
+ row_start: u16,
+ col_start: u16,
+ row_end: u16,
+ col_end: u16,
) -> String {
- let Screen(screen_impl) = *self;
- let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix;
-
- // XXX not super happy about this - can we maybe disable the
- // optimization in libvt100 if no scrollback at all was requested?
- 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 mut len: libc::size_t = unsafe { std::mem::uninitialized() };
- unsafe {
- ffi::vt100_screen_get_string_plaintext(
- screen_impl,
- &start_loc as *const types::Loc,
- &end_loc as *const types::Loc,
- &mut plaintext as *mut *mut libc::c_char,
- &mut len as *mut libc::size_t,
- )
- };
- let rust_plaintext = unsafe {
- 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()
+ unimplemented!()
}
pub fn window_contents_formatted(
&self,
- row_start: i32,
- col_start: i32,
- row_end: i32,
- col_end: i32,
+ row_start: u16,
+ col_start: u16,
+ row_end: u16,
+ col_end: u16,
) -> String {
- let Screen(screen_impl) = *self;
- let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix;
-
- 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 mut len: libc::size_t = unsafe { std::mem::uninitialized() };
- unsafe {
- ffi::vt100_screen_get_string_formatted(
- screen_impl,
- &start_loc as *const types::Loc,
- &end_loc as *const types::Loc,
- &mut formatted as *mut *mut libc::c_char,
- &mut len as *mut libc::size_t,
- )
- };
- let rust_formatted = unsafe {
- 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;
- }
- 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) }
- }
-
- pub fn title(&self) -> Option<&str> {
- let Screen(screen_impl) = *self;
- let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix;
- if unsafe { (*prefix).title }.is_null() {
- None
- } else {
- let slice: &mut [u8] = unsafe {
- std::slice::from_raw_parts_mut(
- (*prefix).title as *mut u8,
- (*prefix).title_len,
- )
- };
- Some(std::str::from_utf8(slice).unwrap())
- }
+ unimplemented!()
}
- pub fn icon_name(&self) -> Option<&str> {
- let Screen(screen_impl) = *self;
- let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix;
- if unsafe { (*prefix).icon_name }.is_null() {
- None
- } else {
- let slice: &mut [u8] = unsafe {
- std::slice::from_raw_parts_mut(
- (*prefix).icon_name as *mut u8,
- (*prefix).icon_name_len,
- )
- };
- Some(std::str::from_utf8(slice).unwrap())
- }
+ pub fn cursor_position(&self) -> (u16, u16) {
+ (self.cursor_position.row, self.cursor_position.col)
}
- pub fn fgcolor(&self) -> color::Color {
- let Screen(screen_impl) = *self;
- let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix;
- let attrs = unsafe { &(*prefix).attrs };
- color::Color::new(&attrs.fgcolor)
+ pub fn fgcolor(&self) -> crate::color::Color {
+ self.fgcolor
}
- pub fn bgcolor(&self) -> color::Color {
- let Screen(screen_impl) = *self;
- let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix;
- let attrs = unsafe { &(*prefix).attrs };
- color::Color::new(&attrs.bgcolor)
+ pub fn bgcolor(&self) -> crate::color::Color {
+ self.bgcolor
}
pub fn bold(&self) -> bool {
- let Screen(screen_impl) = *self;
- let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix;
- unsafe {
- ffi::vt100_wrapper_cell_attrs_bold(&mut (*prefix).attrs) != 0
- }
+ self.bold
}
pub fn italic(&self) -> bool {
- let Screen(screen_impl) = *self;
- let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix;
- unsafe {
- ffi::vt100_wrapper_cell_attrs_italic(&mut (*prefix).attrs) != 0
- }
- }
-
- pub fn underline(&self) -> bool {
- let Screen(screen_impl) = *self;
- let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix;
- unsafe {
- ffi::vt100_wrapper_cell_attrs_underline(&mut (*prefix).attrs) != 0
- }
+ self.italic
}
pub fn inverse(&self) -> bool {
- let Screen(screen_impl) = *self;
- let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix;
- unsafe {
- ffi::vt100_wrapper_cell_attrs_inverse(&mut (*prefix).attrs) != 0
- }
+ self.inverse
}
- pub fn hide_cursor(&self) -> bool {
- let Screen(screen_impl) = *self;
- unsafe { ffi::vt100_wrapper_screen_hide_cursor(screen_impl) != 0 }
+ pub fn underline(&self) -> bool {
+ self.underline
}
- pub fn application_keypad(&self) -> bool {
- let Screen(screen_impl) = *self;
- unsafe {
- ffi::vt100_wrapper_screen_application_keypad(screen_impl) != 0
- }
+ pub fn title(&self) -> Option<&str> {
+ unimplemented!()
}
- pub fn application_cursor(&self) -> bool {
- let Screen(screen_impl) = *self;
- unsafe {
- ffi::vt100_wrapper_screen_application_cursor(screen_impl) != 0
- }
+ pub fn icon_name(&self) -> Option<&str> {
+ unimplemented!()
}
- pub fn mouse_reporting_press(&self) -> bool {
- let Screen(screen_impl) = *self;
- unsafe {
- ffi::vt100_wrapper_screen_mouse_reporting_press(screen_impl) != 0
- }
+ pub fn hide_cursor(&self) -> bool {
+ unimplemented!()
}
- 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
- }
+ pub fn alternate_buffer_active(&self) -> bool {
+ unimplemented!()
}
- 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
- }
+ pub fn application_cursor(&self) -> bool {
+ unimplemented!()
}
- pub fn mouse_reporting_sgr_mode(&self) -> bool {
- let Screen(screen_impl) = *self;
- unsafe {
- ffi::vt100_wrapper_screen_mouse_reporting_mode(screen_impl) == 2
- }
+ pub fn application_keypad(&self) -> bool {
+ unimplemented!()
}
pub fn bracketed_paste(&self) -> bool {
- let Screen(screen_impl) = *self;
- unsafe { ffi::vt100_wrapper_screen_bracketed_paste(screen_impl) != 0 }
- }
-
- pub fn alternate_buffer_active(&self) -> bool {
- let Screen(screen_impl) = *self;
- let prefix: *mut ScreenPrefix = screen_impl as *mut ScreenPrefix;
- !unsafe { (*prefix).alternate }.is_null()
+ unimplemented!()
}
- pub fn check_visual_bell(&self) -> bool {
- let Screen(screen_impl) = *self;
- unsafe {
- let state =
- ffi::vt100_wrapper_screen_visual_bell(screen_impl) != 0;
- ffi::vt100_wrapper_screen_clear_visual_bell(screen_impl);
- state
- }
+ pub fn mouse_reporting_button_motion(&self) -> bool {
+ unimplemented!()
}
- pub fn check_audible_bell(&self) -> bool {
- let Screen(screen_impl) = *self;
- unsafe {
- let state =
- ffi::vt100_wrapper_screen_audible_bell(screen_impl) != 0;
- ffi::vt100_wrapper_screen_clear_audible_bell(screen_impl);
- state
- }
+ pub fn mouse_reporting_sgr_mode(&self) -> bool {
+ unimplemented!()
}
- pub fn check_update_title(&self) -> bool {
- let Screen(screen_impl) = *self;
- unsafe {
- let state =
- ffi::vt100_wrapper_screen_update_title(screen_impl) != 0;
- ffi::vt100_wrapper_screen_clear_update_title(screen_impl);
- state
- }
+ pub fn mouse_reporting_press(&self) -> bool {
+ unimplemented!()
}
- 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;
- ffi::vt100_wrapper_screen_clear_update_icon_name(screen_impl);
- state
- }
+ pub fn mouse_reporting_press_release(&self) -> bool {
+ unimplemented!()
}
- pub fn check_dirty(&self) -> bool {
- let Screen(screen_impl) = *self;
- unsafe {
- let state = ffi::vt100_wrapper_screen_dirty(screen_impl) != 0;
- ffi::vt100_wrapper_screen_clear_dirty(screen_impl);
- state
- }
+ pub fn check_audible_bell(&mut self) -> bool {
+ unimplemented!()
}
-}
-impl Drop for Screen {
- fn drop(&mut self) {
- let Screen(screen_impl) = *self;
- unsafe { ffi::vt100_screen_delete(screen_impl) };
+ pub fn check_visual_bell(&mut self) -> bool {
+ unimplemented!()
}
}
diff --git a/src/types.rs b/src/types.rs
deleted file mode 100644
index c1277c9..0000000
--- a/src/types.rs
+++ /dev/null
@@ -1,19 +0,0 @@
-use libc;
-
-pub enum ScreenImpl {}
-pub enum CellImpl {}
-#[repr(C)]
-pub struct ColorImpl(pub libc::uint32_t);
-
-#[repr(C)]
-pub struct CellAttrs {
- pub fgcolor: ColorImpl,
- pub bgcolor: ColorImpl,
- pub attrs: libc::c_uchar,
-}
-
-#[repr(C)]
-pub struct Loc {
- pub row: libc::c_int,
- pub col: libc::c_int,
-}
diff --git a/tests/attr.rs b/tests/attr.rs
index 2532819..e621098 100644
--- a/tests/attr.rs
+++ b/tests/attr.rs
@@ -1,4 +1,4 @@
-extern crate vt100;
+#![allow(clippy::cognitive_complexity)]
mod support;
use support::TestHelpers;
@@ -6,164 +6,113 @@ use support::TestHelpers;
#[test]
fn colors() {
let mut screen = vt100::Screen::new(24, 80);
- assert_eq!(screen.fgcolor(), vt100::Color::ColorDefault);
- assert_eq!(screen.bgcolor(), vt100::Color::ColorDefault);
+ assert_eq!(screen.fgcolor(), vt100::Color::Default);
+ assert_eq!(screen.bgcolor(), vt100::Color::Default);
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::Default);
+ assert_eq!(screen.cell(0, 0).unwrap().bgcolor(), vt100::Color::Default);
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::Idx(1));
+ assert_eq!(screen.cell(0, 3).unwrap().bgcolor(), vt100::Color::Default);
- assert_eq!(screen.fgcolor(), vt100::Color::ColorIdx(1));
- assert_eq!(screen.bgcolor(), vt100::Color::ColorDefault);
+ assert_eq!(screen.fgcolor(), vt100::Color::Idx(1));
+ assert_eq!(screen.bgcolor(), vt100::Color::Default);
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::Idx(1));
+ assert_eq!(screen.cell(0, 4).unwrap().bgcolor(), vt100::Color::Idx(5));
- assert_eq!(screen.fgcolor(), vt100::Color::ColorIdx(1));
- assert_eq!(screen.bgcolor(), vt100::Color::ColorIdx(5));
+ assert_eq!(screen.fgcolor(), vt100::Color::Idx(1));
+ assert_eq!(screen.bgcolor(), vt100::Color::Idx(5));
screen.assert_process(b"\x1b[m");
- assert_eq!(screen.fgcolor(), vt100::Color::ColorDefault);
- assert_eq!(screen.bgcolor(), vt100::Color::ColorDefault);
+ assert_eq!(screen.fgcolor(), vt100::Color::Default);
+ assert_eq!(screen.bgcolor(), vt100::Color::Default);
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
+ vt100::Color::Default
);
assert_eq!(
screen.cell(14, 14).unwrap().bgcolor(),
- vt100::Color::ColorDefault
+ vt100::Color::Default
);
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().fgcolor(), vt100::Color::Idx(1));
assert_eq!(
screen.cell(14, 17).unwrap().bgcolor(),
- vt100::Color::ColorDefault
+ vt100::Color::Default
);
- assert_eq!(screen.fgcolor(), vt100::Color::ColorDefault);
- assert_eq!(screen.bgcolor(), vt100::Color::ColorDefault);
+ assert_eq!(screen.fgcolor(), vt100::Color::Default);
+ assert_eq!(screen.bgcolor(), vt100::Color::Default);
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)
+ vt100::Color::Default
);
+ assert_eq!(screen.cell(14, 18).unwrap().bgcolor(), vt100::Color::Idx(5));
- assert_eq!(screen.fgcolor(), vt100::Color::ColorDefault);
- assert_eq!(screen.bgcolor(), vt100::Color::ColorIdx(5));
+ assert_eq!(screen.fgcolor(), vt100::Color::Default);
+ assert_eq!(screen.bgcolor(), vt100::Color::Idx(5));
screen.assert_process(b"\x1b[m\x1b[2J\x1b[H");
screen.assert_process(b"a\x1b[38;5;123mb\x1b[48;5;158mc");
- assert_eq!(screen.fgcolor(), vt100::Color::ColorIdx(123));
- assert_eq!(screen.bgcolor(), vt100::Color::ColorIdx(158));
+ assert_eq!(screen.fgcolor(), vt100::Color::Idx(123));
+ assert_eq!(screen.bgcolor(), vt100::Color::Idx(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, 0).unwrap().fgcolor(), vt100::Color::Default);
+ assert_eq!(screen.cell(0, 0).unwrap().bgcolor(), vt100::Color::Default);
- 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, 1).unwrap().fgcolor(), vt100::Color::Idx(123));
+ assert_eq!(screen.cell(0, 1).unwrap().bgcolor(), vt100::Color::Default);
- 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, 2).unwrap().fgcolor(), vt100::Color::Idx(123));
+ assert_eq!(screen.cell(0, 2).unwrap().bgcolor(), vt100::Color::Idx(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.fgcolor(), vt100::Color::Rgb(50, 75, 100));
+ assert_eq!(screen.bgcolor(), vt100::Color::Rgb(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)
+ vt100::Color::Rgb(50, 75, 100)
);
+ assert_eq!(screen.cell(0, 3).unwrap().bgcolor(), vt100::Color::Idx(158));
assert_eq!(
screen.cell(0, 4).unwrap().fgcolor(),
- vt100::Color::ColorRgb(50, 75, 100)
+ vt100::Color::Rgb(50, 75, 100)
);
assert_eq!(
screen.cell(0, 4).unwrap().bgcolor(),
- vt100::Color::ColorRgb(125, 150, 175)
+ vt100::Color::Rgb(125, 150, 175)
);
screen.assert_process(b"\x1b[m\x1b[2J\x1b[H");
screen.assert_process(b"\x1b[32;47mfoo");
- assert_eq!(screen.fgcolor(), vt100::Color::ColorIdx(2));
- assert_eq!(screen.bgcolor(), vt100::Color::ColorIdx(7));
+ assert_eq!(screen.fgcolor(), vt100::Color::Idx(2));
+ assert_eq!(screen.bgcolor(), vt100::Color::Idx(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::Idx(2));
+ assert_eq!(screen.cell(0, 1).unwrap().bgcolor(), vt100::Color::Idx(7));
}
#[test]
diff --git a/tests/basic.rs b/tests/basic.rs
index babec39..46d9265 100644
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -1,5 +1,3 @@
-extern crate vt100;
-
#[test]
fn object_creation() {
let screen = vt100::Screen::new(24, 80);
@@ -17,7 +15,7 @@ fn process_text() {
#[test]
fn set_window_size() {
- let screen = vt100::Screen::new(24, 80);
+ let mut screen = vt100::Screen::new(24, 80);
assert_eq!(screen.rows(), 24);
assert_eq!(screen.cols(), 80);
@@ -46,22 +44,10 @@ fn cell_colors() {
let input = b"foo\x1b[31m\x1b[32mb\x1b[3;7;42ma\x1b[23mr";
screen.process(input);
- assert_eq!(
- screen.cell(0, 0).unwrap().fgcolor(),
- vt100::Color::ColorDefault
- );
- assert_eq!(
- screen.cell(0, 3).unwrap().fgcolor(),
- vt100::Color::ColorIdx(2)
- );
- assert_eq!(
- screen.cell(0, 4).unwrap().fgcolor(),
- vt100::Color::ColorIdx(2)
- );
- assert_eq!(
- screen.cell(0, 4).unwrap().bgcolor(),
- vt100::Color::ColorIdx(2)
- );
+ assert_eq!(screen.cell(0, 0).unwrap().fgcolor(), vt100::Color::Default);
+ assert_eq!(screen.cell(0, 3).unwrap().fgcolor(), vt100::Color::Idx(2));
+ assert_eq!(screen.cell(0, 4).unwrap().fgcolor(), vt100::Color::Idx(2));
+ assert_eq!(screen.cell(0, 4).unwrap().bgcolor(), vt100::Color::Idx(2));
}
#[test]
diff --git a/tests/control.rs b/tests/control.rs
index 787bdc2..82b996c 100644
--- a/tests/control.rs
+++ b/tests/control.rs
@@ -1,5 +1,3 @@
-extern crate vt100;
-
mod support;
use support::TestHelpers;
diff --git a/tests/csi.rs b/tests/csi.rs
index e19f377..519fc94 100644
--- a/tests/csi.rs
+++ b/tests/csi.rs
@@ -1,5 +1,3 @@
-extern crate vt100;
-
mod support;
use support::TestHelpers;
diff --git a/tests/escape.rs b/tests/escape.rs
index 4c01c82..6661188 100644
--- a/tests/escape.rs
+++ b/tests/escape.rs
@@ -1,4 +1,4 @@
-extern crate vt100;
+#![allow(clippy::cognitive_complexity)]
mod support;
use support::TestHelpers;
@@ -43,8 +43,8 @@ fn ris() {
assert_eq!(screen.title(), None);
assert_eq!(screen.icon_name(), None);
- assert_eq!(screen.fgcolor(), vt100::Color::ColorDefault);
- assert_eq!(screen.bgcolor(), vt100::Color::ColorDefault);
+ assert_eq!(screen.fgcolor(), vt100::Color::Default);
+ assert_eq!(screen.bgcolor(), vt100::Color::Default);
assert!(!screen.bold());
assert!(!screen.italic());
@@ -78,8 +78,8 @@ fn ris() {
assert_eq!(screen.title().unwrap(), "window title");
assert_eq!(screen.icon_name().unwrap(), "window icon name");
- assert_eq!(screen.fgcolor(), vt100::Color::ColorIdx(1));
- assert_eq!(screen.bgcolor(), vt100::Color::ColorIdx(7));
+ assert_eq!(screen.fgcolor(), vt100::Color::Idx(1));
+ assert_eq!(screen.bgcolor(), vt100::Color::Idx(7));
assert!(screen.bold());
assert!(screen.italic());
@@ -116,8 +116,8 @@ fn ris() {
assert_eq!(screen.title().unwrap(), "window title");
assert_eq!(screen.icon_name().unwrap(), "window icon name");
- assert_eq!(screen.fgcolor(), vt100::Color::ColorDefault);
- assert_eq!(screen.bgcolor(), vt100::Color::ColorDefault);
+ assert_eq!(screen.fgcolor(), vt100::Color::Default);
+ assert_eq!(screen.bgcolor(), vt100::Color::Default);
assert!(!screen.bold());
assert!(!screen.italic());
diff --git a/tests/init.rs b/tests/init.rs
index eb3179a..f5c896a 100644
--- a/tests/init.rs
+++ b/tests/init.rs
@@ -1,8 +1,8 @@
-extern crate vt100;
+#![allow(clippy::cognitive_complexity)]
#[test]
fn init() {
- let screen = vt100::Screen::new(24, 80);
+ let mut screen = vt100::Screen::new(24, 80);
assert_eq!(screen.rows(), 24);
assert_eq!(screen.cols(), 80);
assert_eq!(screen.cursor_position(), (0, 0));
@@ -28,8 +28,8 @@ fn init() {
assert_eq!(screen.title(), None);
assert_eq!(screen.icon_name(), None);
- assert_eq!(screen.fgcolor(), vt100::Color::ColorDefault);
- assert_eq!(screen.bgcolor(), vt100::Color::ColorDefault);
+ assert_eq!(screen.fgcolor(), vt100::Color::Default);
+ assert_eq!(screen.bgcolor(), vt100::Color::Default);
assert!(!screen.bold());
assert!(!screen.italic());
diff --git a/tests/mode.rs b/tests/mode.rs
index 50f18ba..5f8b2a4 100644
--- a/tests/mode.rs
+++ b/tests/mode.rs
@@ -1,4 +1,4 @@
-extern crate vt100;
+#![allow(clippy::cognitive_complexity)]
mod support;
use support::TestHelpers;
diff --git a/tests/osc.rs b/tests/osc.rs
index 59ab943..be3c476 100644
--- a/tests/osc.rs
+++ b/tests/osc.rs
@@ -1,5 +1,3 @@
-extern crate vt100;
-
mod support;
use support::TestHelpers;
diff --git a/tests/processing.rs b/tests/processing.rs
index 02c2766..3110814 100644
--- a/tests/processing.rs
+++ b/tests/processing.rs
@@ -1,4 +1,4 @@
-extern crate vt100;
+#![allow(clippy::cognitive_complexity)]
#[test]
fn split_escape_sequences() {
diff --git a/tests/scroll.rs b/tests/scroll.rs
index b5a8891..3ac0074 100644
--- a/tests/scroll.rs
+++ b/tests/scroll.rs
@@ -1,5 +1,3 @@
-extern crate vt100;
-
mod support;
use support::TestHelpers;
diff --git a/tests/split-escapes.rs b/tests/split-escapes.rs
index bd7d20a..33f3c0d 100644
--- a/tests/split-escapes.rs
+++ b/tests/split-escapes.rs
@@ -1,6 +1,4 @@
-extern crate vt100;
-
-use std::io::prelude::*;
+use std::io::Read as _;
fn get_file_contents(name: &str) -> Vec<u8> {
let mut file = std::fs::File::open(name).unwrap();
@@ -14,8 +12,8 @@ fn write_to_screen(chunks: &mut Vec<Vec<u8>>) -> String {
let mut full_chunk = vec![];
for chunk in chunks.iter_mut() {
full_chunk.append(chunk);
- let bytes = screen.process(&mut full_chunk);
- full_chunk = full_chunk.split_off(bytes as usize);
+ let bytes = screen.process(&full_chunk);
+ full_chunk = full_chunk.split_off(bytes);
}
assert_eq!(full_chunk.len(), 0);
screen.window_contents(0, 0, 36, 192)
diff --git a/tests/support/mod.rs b/tests/support/mod.rs
index 51ad600..cfa6320 100644
--- a/tests/support/mod.rs
+++ b/tests/support/mod.rs
@@ -1,13 +1,11 @@
-use vt100;
-
pub trait TestHelpers {
- fn assert_process(&mut self, s: &[u8]) -> u64;
+ fn assert_process(&mut self, s: &[u8]) -> usize;
}
impl TestHelpers for vt100::Screen {
- fn assert_process(&mut self, s: &[u8]) -> u64 {
+ fn assert_process(&mut self, s: &[u8]) -> usize {
let ret = self.process(s);
- assert_eq!(ret, s.len() as u64);
+ assert_eq!(ret, s.len());
ret
}
}
diff --git a/tests/text.rs b/tests/text.rs
index 13bd96c..140b32f 100644
--- a/tests/text.rs
+++ b/tests/text.rs
@@ -1,4 +1,4 @@
-extern crate vt100;
+#![allow(clippy::cognitive_complexity)]
mod support;
use support::TestHelpers;
diff --git a/tests/zero-width.rs b/tests/zero-width.rs
index 5de6faf..0722b66 100644
--- a/tests/zero-width.rs
+++ b/tests/zero-width.rs
@@ -1,4 +1,4 @@
-extern crate vt100;
+#![allow(clippy::cognitive_complexity)]
#[test]
fn zero_width_characters() {