From 45ec006a5dbfc5fe705d99e86e1782e4e77f431d Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 22 Jul 2018 05:44:51 -0700 Subject: [PATCH] rename screen::Screen to surface::Surface --- examples/hello.rs | 4 +- src/lib.rs | 2 +- src/render/terminfo.rs | 2 +- src/render/windows.rs | 2 +- src/{screen.rs => surface.rs} | 82 +++++++++++++++++------------------ src/terminal/mod.rs | 2 +- src/terminal/unix.rs | 2 +- src/terminal/windows.rs | 2 +- 8 files changed, 49 insertions(+), 49 deletions(-) rename src/{screen.rs => surface.rs} (95%) diff --git a/examples/hello.rs b/examples/hello.rs index 01fcf192c..fbe571b8c 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -5,7 +5,7 @@ use failure::Error; use termwiz::caps::Capabilities; use termwiz::cell::AttributeChange; use termwiz::color::AnsiColor; -use termwiz::screen::{Change, Screen}; +use termwiz::surface::{Change, Surface}; use termwiz::terminal::{self, Terminal}; #[cfg(unix)] @@ -25,7 +25,7 @@ fn main() -> Result<(), Error> { terminal.set_raw_mode()?; let size = terminal.get_screen_size()?; - let mut screen = Screen::new(size.cols as usize, size.rows as usize); + let mut screen = Surface::new(size.cols as usize, size.rows as usize); screen.add_change(Change::Attribute(AttributeChange::Foreground( AnsiColor::Maroon.into(), diff --git a/src/lib.rs b/src/lib.rs index ef05ac21b..79752565f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,5 +24,5 @@ pub mod color; pub mod escape; pub mod istty; pub mod render; -pub mod screen; +pub mod surface; pub mod terminal; diff --git a/src/render/terminfo.rs b/src/render/terminfo.rs index 6760164a5..1cfe3d11f 100644 --- a/src/render/terminfo.rs +++ b/src/render/terminfo.rs @@ -5,8 +5,8 @@ use color::{ColorAttribute, ColorSpec}; use escape::csi::{Cursor, Edit, EraseInDisplay, EraseInLine, Sgr, CSI}; use escape::osc::OperatingSystemCommand; use failure; -use screen::{Change, Position}; use std::io::{Read, Write}; +use surface::{Change, Position}; use terminal::unix::UnixTty; use terminfo::{capability as cap, Capability as TermInfoCapability}; diff --git a/src/render/windows.rs b/src/render/windows.rs index 063e84bd6..dcb4076b3 100644 --- a/src/render/windows.rs +++ b/src/render/windows.rs @@ -5,8 +5,8 @@ use cell::{AttributeChange, CellAttributes, Underline}; use color::{AnsiColor, ColorAttribute}; use failure; use num; -use screen::{Change, Position}; use std::io::{Read, Write}; +use surface::{Change, Position}; use terminal::windows::{ConsoleInputHandle, ConsoleOutputHandle}; use winapi::um::wincon::{ BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_INTENSITY, BACKGROUND_RED, diff --git a/src/screen.rs b/src/surface.rs similarity index 95% rename from src/screen.rs rename to src/surface.rs index 653483887..8ffce8ac2 100644 --- a/src/screen.rs +++ b/src/surface.rs @@ -19,7 +19,7 @@ pub enum Position { EndRelative(usize), } -/// `Change` describes an update operation to be applied to a `Screen`. +/// `Change` describes an update operation to be applied to a `Surface`. /// Changes to the active attributes (color, style), moving the cursor /// and outputting text are examples of some of the values. #[derive(Debug, Clone, Eq, PartialEq)] @@ -169,35 +169,35 @@ impl Line { } /// SequenceNo indicates a logical position within a stream of changes. -/// The sequence is only meaningful within a given `Screen` instance. +/// The sequence is only meaningful within a given `Surface` instance. pub type SequenceNo = usize; -/// The `Screen` type represents the contents of a terminal screen. +/// The `Surface` type represents the contents of a terminal screen. /// It is not directly connected to a terminal device. /// It consists of a buffer and a log of changes. You can accumulate /// updates to the screen by adding instances of the `Change` enum /// that describe the updates. /// -/// When ready to render the `Screen` to a `Terminal`, you can use +/// When ready to render the `Surface` to a `Terminal`, you can use /// the `get_changes` method to return an optimized stream of `Change`s /// since the last render and then pass it to an instance of `Renderer`. /// -/// `Screen`s can also be composited together; this is useful when +/// `Surface`s can also be composited together; this is useful when /// building up a UI with layers or widgets: each widget can be its -/// own `Screen` instance and have its content maintained independently +/// own `Surface` instance and have its content maintained independently /// from the other widgets on the screen and can then be copied into -/// the target `Screen` buffer for rendering. +/// the target `Surface` buffer for rendering. /// /// To support more efficient updates in the composite use case, a /// `draw_from_screen` method is available; the intent is to have one -/// `Screen` be hold the data that was last rendered, and a second `Screen` +/// `Surface` be hold the data that was last rendered, and a second `Surface` /// of the same size that is repeatedly redrawn from the composite /// of the widgets. `draw_from_screen` is used to extract the smallest /// difference between the updated screen and apply those changes to /// the render target, and then use `get_changes` to render those without /// repainting the world on each update. #[derive(Default)] -pub struct Screen { +pub struct Surface { width: usize, height: usize, lines: Vec, @@ -208,10 +208,10 @@ pub struct Screen { changes: Vec, } -impl Screen { - /// Create a new Screen surface with the specified width and height. +impl Surface { + /// Create a new Surface surface with the specified width and height. pub fn new(width: usize, height: usize) -> Self { - let mut scr = Screen { + let mut scr = Surface { width, height, ..Default::default() @@ -220,7 +220,7 @@ impl Screen { scr } - /// Resize the Screen surface to the specified width and height. + /// Resize the Surface surface to the specified width and height. /// If the width and/or height are smaller than previously, the rows and/or /// columns are truncated. If the width and/or height are larger than /// previously then an appropriate number of cells are added to the @@ -629,20 +629,20 @@ impl Screen { /// same sized region within `other` at coordinates `other_x`, `other_y`. /// /// `other` and `self` may be the same, causing regions within the same - /// `Screen` to be differenced; this is used by the `copy_region` method. + /// `Surface` to be differenced; this is used by the `copy_region` method. /// /// The returned list of `Change`s can be passed to the `add_changes` method /// to make the region within self match the region within other. /// # Panics /// Will panic if the regions of interest are not within the bounds of - /// their respective `Screen`. + /// their respective `Surface`. pub fn diff_region( &self, x: usize, y: usize, width: usize, height: usize, - other: &Screen, + other: &Surface, other_x: usize, other_y: usize, ) -> Vec { @@ -735,14 +735,14 @@ impl Screen { /// Computes the change stream required to make `self` have the same /// screen contents as `other`. - pub fn diff_screens(&self, other: &Screen) -> Vec { + pub fn diff_screens(&self, other: &Surface) -> Vec { self.diff_region(0, 0, self.width, self.height, other, 0, 0) } /// Draw the contents of `other` into self at the specified coordinates. /// The required updates are recorded as Change entries as well as stored /// in the screen line/cell data. - pub fn draw_from_screen(&mut self, other: &Screen, x: usize, y: usize) -> SequenceNo { + pub fn draw_from_screen(&mut self, other: &Surface, x: usize, y: usize) -> SequenceNo { let changes = self.diff_region(x, y, other.width, other.height, other, 0, 0); self.add_changes(changes) } @@ -753,7 +753,7 @@ impl Screen { /// # Panics /// The destination region must be the same size as the source /// (which is implied by the function parameters) and must fit - /// within the width and height of the Screen or this operation + /// within the width and height of the Surface or this operation /// will panic. pub fn copy_region( &mut self, @@ -799,7 +799,7 @@ mod test { #[test] fn basic_print() { - let mut s = Screen::new(4, 3); + let mut s = Surface::new(4, 3); assert_eq!( s.screen_chars_to_string(), "\x20\x20\x20\x20\n\ @@ -842,7 +842,7 @@ mod test { #[test] fn newline() { - let mut s = Screen::new(4, 4); + let mut s = Surface::new(4, 4); s.add_change("bloo\rwat\n hey\r\nho"); assert_eq!( s.screen_chars_to_string(), @@ -855,7 +855,7 @@ mod test { #[test] fn clear_screen() { - let mut s = Screen::new(2, 2); + let mut s = Surface::new(2, 2); s.add_change("hello"); s.add_change(Change::ClearScreen(Default::default())); assert_eq!(s.screen_chars_to_string(), " \n \n"); @@ -863,7 +863,7 @@ mod test { #[test] fn clear_eol() { - let mut s = Screen::new(3, 3); + let mut s = Surface::new(3, 3); s.add_change("helwowfoo"); s.add_change(Change::ClearToEndOfLine(Default::default())); assert_eq!(s.screen_chars_to_string(), "hel\nwow\nfoo\n"); @@ -883,7 +883,7 @@ mod test { #[test] fn clear_eos() { - let mut s = Screen::new(3, 3); + let mut s = Surface::new(3, 3); s.add_change("helwowfoo"); s.add_change(Change::ClearToEndOfScreen(Default::default())); assert_eq!(s.screen_chars_to_string(), "hel\nwow\nfoo\n"); @@ -910,7 +910,7 @@ mod test { #[test] fn clear_eos_back_color() { - let mut s = Screen::new(3, 3); + let mut s = Surface::new(3, 3); s.add_change(Change::ClearScreen(AnsiColor::Red.into())); s.add_change("helwowfoo"); assert_eq!(s.screen_chars_to_string(), "hel\nwow\nfoo\n"); @@ -943,7 +943,7 @@ mod test { #[test] fn clear_eol_opt() { - let mut s = Screen::new(3, 3); + let mut s = Surface::new(3, 3); s.add_change(Change::Attribute(AttributeChange::Background( AnsiColor::Red.into(), ))); @@ -979,7 +979,7 @@ mod test { #[test] fn clear_and_move_cursor() { - let mut s = Screen::new(4, 3); + let mut s = Surface::new(4, 3); s.add_change(Change::CursorPosition { x: Position::Absolute(3), y: Position::Absolute(2), @@ -999,7 +999,7 @@ mod test { #[test] fn cursor_movement() { - let mut s = Screen::new(4, 3); + let mut s = Surface::new(4, 3); s.add_change(Change::CursorPosition { x: Position::Absolute(3), y: Position::Absolute(2), @@ -1041,7 +1041,7 @@ mod test { fn attribute_setting() { use cell::Intensity; - let mut s = Screen::new(3, 1); + let mut s = Surface::new(3, 1); s.add_change("n"); s.add_change(AttributeChange::Intensity(Intensity::Bold)); s.add_change("b"); @@ -1061,7 +1061,7 @@ mod test { #[test] fn empty_changes() { - let s = Screen::new(4, 3); + let s = Surface::new(4, 3); let empty = &[Change::ClearScreen(Default::default())]; @@ -1078,7 +1078,7 @@ mod test { #[test] fn add_changes_empty() { - let mut s = Screen::new(2, 2); + let mut s = Surface::new(2, 2); let last_seq = s.add_change("foo"); assert_eq!(0, last_seq); assert_eq!(last_seq, s.add_changes(vec![])); @@ -1087,7 +1087,7 @@ mod test { #[test] fn resize_delta_flush() { - let mut s = Screen::new(4, 3); + let mut s = Surface::new(4, 3); s.add_change("a"); let (seq, _) = s.get_changes(0); s.resize(2, 2); @@ -1108,7 +1108,7 @@ mod test { #[test] fn dont_lose_first_char_on_attr_change() { - let mut s = Screen::new(2, 2); + let mut s = Surface::new(2, 2); s.add_change(Change::Attribute(AttributeChange::Foreground( AnsiColor::Maroon.into(), ))); @@ -1134,7 +1134,7 @@ mod test { #[test] fn resize_cursor_position() { - let mut s = Screen::new(4, 4); + let mut s = Surface::new(4, 4); s.add_change(" a"); s.add_change(Change::CursorPosition { @@ -1163,7 +1163,7 @@ mod test { #[test] fn delta_change() { - let mut s = Screen::new(4, 3); + let mut s = Surface::new(4, 3); // flushing nothing should be a NOP s.flush_changes_older_than(0); @@ -1233,7 +1233,7 @@ mod test { #[test] fn diff_screens() { - let mut s = Screen::new(4, 3); + let mut s = Surface::new(4, 3); s.add_change("w00t"); s.add_change("foo"); s.add_change("baar"); @@ -1245,7 +1245,7 @@ mod test { az \n" ); - let s2 = Screen::new(2, 2); + let s2 = Surface::new(2, 2); { // We want to sample the top left corner @@ -1308,12 +1308,12 @@ mod test { #[test] fn draw_screens() { - let mut s = Screen::new(4, 4); + let mut s = Surface::new(4, 4); - let mut s1 = Screen::new(2, 2); + let mut s1 = Surface::new(2, 2); s1.add_change("1234"); - let mut s2 = Screen::new(2, 2); + let mut s2 = Surface::new(2, 2); s2.add_change("XYZA"); s.draw_from_screen(&s1, 0, 0); @@ -1330,7 +1330,7 @@ mod test { #[test] fn copy_region() { - let mut s = Screen::new(4, 3); + let mut s = Surface::new(4, 3); s.add_change("w00t"); s.add_change("foo"); s.add_change("baar"); diff --git a/src/terminal/mod.rs b/src/terminal/mod.rs index c0398d766..10fa6d91b 100644 --- a/src/terminal/mod.rs +++ b/src/terminal/mod.rs @@ -6,9 +6,9 @@ use failure::Error; use num::{self, NumCast}; -use screen::Change; use std::fmt::Display; use std::io::{Read, Write}; +use surface::Change; #[cfg(unix)] pub mod unix; diff --git a/src/terminal/unix.rs b/src/terminal/unix.rs index 0ab99f220..ccd87423b 100644 --- a/src/terminal/unix.rs +++ b/src/terminal/unix.rs @@ -11,7 +11,7 @@ use termios::{ use caps::Capabilities; use render::terminfo::TerminfoRenderer; -use screen::Change; +use surface::Change; use terminal::{cast, ScreenSize, Terminal, BUF_SIZE}; /// Helper function to duplicate a file descriptor. diff --git a/src/terminal/windows.rs b/src/terminal/windows.rs index b779743ba..931a7f355 100644 --- a/src/terminal/windows.rs +++ b/src/terminal/windows.rs @@ -15,7 +15,7 @@ use winapi::um::wincon::{ use caps::Capabilities; use render::windows::WindowsConsoleRenderer; -use screen::Change; +use surface::Change; use terminal::{cast, ScreenSize, Terminal, BUF_SIZE}; pub trait ConsoleInputHandle {