started working on refactoringterminal
This commit is contained in:
		
							parent
							
								
									26472359bc
								
							
						
					
					
						commit
						1ff70a9653
					
				| @ -4,66 +4,52 @@ | |||||||
| use super::super::cursor::cursor; | use super::super::cursor::cursor; | ||||||
| use super::{ClearType, ITerminal, Rc}; | use super::{ClearType, ITerminal, Rc}; | ||||||
| use shared::functions; | use shared::functions; | ||||||
| use Context; | use ScreenManager; | ||||||
| 
 | 
 | ||||||
| /// This struct is an ansi implementation for terminal related actions.
 | /// This struct is an ansi implementation for terminal related actions.
 | ||||||
| pub struct AnsiTerminal { | pub struct AnsiTerminal; | ||||||
|     context: Rc<Context>, |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| impl AnsiTerminal { | impl AnsiTerminal { | ||||||
|     pub fn new(context: Rc<Context>) -> Box<AnsiTerminal> { |     pub fn new() -> AnsiTerminal { | ||||||
|         Box::from(AnsiTerminal { context: context }) |         AnsiTerminal {} | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl ITerminal for AnsiTerminal { | impl ITerminal for AnsiTerminal { | ||||||
|     fn clear(&self, clear_type: ClearType) { |     fn clear(&self, clear_type: ClearType, screen_manager: &ScreenManager) { | ||||||
|         let mut screen_manager = self.context.screen_manager.lock().unwrap(); |         match clear_type { | ||||||
|         { |             ClearType::All => { | ||||||
|             match clear_type { |                 screen_manager.write_str(csi!("2J")); | ||||||
|                 ClearType::All => { |             } | ||||||
|                     screen_manager.write_str(csi!("2J")); |             ClearType::FromCursorDown => { | ||||||
|                 } |                 screen_manager.write_str(csi!("J")); | ||||||
|                 ClearType::FromCursorDown => { |             } | ||||||
|                     screen_manager.write_str(csi!("J")); |             ClearType::FromCursorUp => { | ||||||
|                 } |                 screen_manager.write_str(csi!("1J")); | ||||||
|                 ClearType::FromCursorUp => { |             } | ||||||
|                     screen_manager.write_str(csi!("1J")); |             ClearType::CurrentLine => { | ||||||
|                 } |                 screen_manager.write_str(csi!("2K")); | ||||||
|                 ClearType::CurrentLine => { |             } | ||||||
|                     screen_manager.write_str(csi!("2K")); |             ClearType::UntilNewLine => { | ||||||
|                 } |                 screen_manager.write_str(csi!("K")); | ||||||
|                 ClearType::UntilNewLine => { |             } | ||||||
|                     screen_manager.write_str(csi!("K")); |         }; | ||||||
|                 } |  | ||||||
|             }; |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn terminal_size(&self) -> (u16, u16) { |     fn terminal_size(&self, screen_manager: &ScreenManager) -> (u16, u16) { | ||||||
|         functions::get_terminal_size(&self.context.screen_manager) |         functions::get_terminal_size(&self.context.screen_manager) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn scroll_up(&self, count: i16) { |     fn scroll_up(&self, count: i16, screen_manager: &ScreenManager) { | ||||||
|         let mut screen = self.context.screen_manager.lock().unwrap(); |         screen_manager.write_string(format!(csi!("{}S"), count)); | ||||||
|         { |  | ||||||
|             screen.write_string(format!(csi!("{}S"), count)); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn scroll_down(&self, count: i16) { |     fn scroll_down(&self, count: i16, screen_manager: &ScreenManager) { | ||||||
|         let mut screen = self.context.screen_manager.lock().unwrap(); |         screen_manager.write_string(format!(csi!("{}T"), count)); | ||||||
|         { |  | ||||||
|             screen.write_string(format!(csi!("{}T"), count)); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn set_size(&self, width: i16, height: i16) { |     fn set_size(&self, width: i16, height: i16, screen_manager: &ScreenManager) { | ||||||
|         let mut screen = self.context.screen_manager.lock().unwrap(); |         screen_manager.write_string(format!(csi!("8;{};{}t"), width, height)); | ||||||
|         { |  | ||||||
|             screen.write_string(format!(csi!("8;{};{}t"), width, height)); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn exit(&self) { |     fn exit(&self) { | ||||||
|  | |||||||
| @ -16,6 +16,7 @@ use self::ansi_terminal::AnsiTerminal; | |||||||
| #[cfg(target_os = "windows")] | #[cfg(target_os = "windows")] | ||||||
| use self::winapi_terminal::WinApiTerminal; | use self::winapi_terminal::WinApiTerminal; | ||||||
| use std::rc::Rc; | use std::rc::Rc; | ||||||
|  | use ScreenManager; | ||||||
| 
 | 
 | ||||||
| pub use self::terminal::terminal; | pub use self::terminal::terminal; | ||||||
| use Context; | use Context; | ||||||
| @ -39,15 +40,15 @@ pub enum ClearType { | |||||||
| ///! so that cursor related actions can be preformed on both unix and windows systems.
 | ///! so that cursor related actions can be preformed on both unix and windows systems.
 | ||||||
| pub trait ITerminal { | pub trait ITerminal { | ||||||
|     /// Clear the current cursor by specifying the clear type
 |     /// Clear the current cursor by specifying the clear type
 | ||||||
|     fn clear(&self, clear_type: ClearType); |     fn clear(&self, clear_type: ClearType, screen_manager: &ScreenManager); | ||||||
|     /// Get the terminal size (x,y)
 |     /// Get the terminal size (x,y)
 | ||||||
|     fn terminal_size(&self) -> (u16, u16); |     fn terminal_size(&self, screen_manager: &ScreenManager) -> (u16, u16); | ||||||
|     /// Scroll `n` lines up in the current terminal.
 |     /// Scroll `n` lines up in the current terminal.
 | ||||||
|     fn scroll_up(&self, count: i16); |     fn scroll_up(&self, count: i16, screen_manager: &ScreenManager); | ||||||
|     /// Scroll `n` lines down in the current terminal.
 |     /// Scroll `n` lines down in the current terminal.
 | ||||||
|     fn scroll_down(&self, count: i16); |     fn scroll_down(&self, count: i16,screen_manager: &ScreenManager); | ||||||
|     /// Resize terminal to the given width and height.
 |     /// Resize terminal to the given width and height.
 | ||||||
|     fn set_size(&self, width: i16, height: i16); |     fn set_size(&self, width: i16, height: i16, screen_manager: &ScreenManager); | ||||||
|     /// Close the current terminal
 |     /// Close the current terminal
 | ||||||
|     fn exit(&self); |     fn exit(&self); | ||||||
| } | } | ||||||
|  | |||||||
| @ -12,26 +12,26 @@ use std::io::Write; | |||||||
| use std::rc::Rc; | use std::rc::Rc; | ||||||
| 
 | 
 | ||||||
| /// Struct that stores an specific platform implementation for terminal related actions.
 | /// Struct that stores an specific platform implementation for terminal related actions.
 | ||||||
| pub struct Terminal { | pub struct Terminal<'terminal> { | ||||||
|     terminal: Box<ITerminal>, |     terminal: Box<ITerminal>, | ||||||
|     context: Rc<Context>, |     screen_manager: &'terminal ScreenManager, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Terminal { | impl<'terminal> Terminal<'terminal> { | ||||||
|     /// Create new terminal instance whereon terminal related actions can be performed.
 |     /// Create new terminal instance whereon terminal related actions can be performed.
 | ||||||
|     pub fn new(context: Rc<Context>) -> Terminal { |     pub fn new(screen_manager: &'terminal ScreenManager) -> Terminal<'terminal> { | ||||||
|         #[cfg(target_os = "windows")] |         #[cfg(target_os = "windows")] | ||||||
|         let terminal = functions::get_module::<Box<ITerminal>>( |         let terminal = functions::get_module::<Box<ITerminal>>( | ||||||
|             WinApiTerminal::new(context.clone()), |             Box::new(WinApiTerminal::new()), | ||||||
|             AnsiTerminal::new(context.clone()), |             Box::new(AnsiTerminal::new()), | ||||||
|         ).unwrap(); |         ).unwrap(); | ||||||
| 
 | 
 | ||||||
|         #[cfg(not(target_os = "windows"))] |         #[cfg(not(target_os = "windows"))] | ||||||
|         let terminal = AnsiTerminal::new(context.clone()) as Box<ITerminal>; |         let terminal = AnsiTerminal::new() as Box<ITerminal>; | ||||||
| 
 | 
 | ||||||
|         Terminal { |         Terminal { | ||||||
|             terminal, |             terminal, | ||||||
|             context: context, |             screen_manager: screen_manager | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -61,7 +61,7 @@ impl Terminal { | |||||||
|     ///
 |     ///
 | ||||||
|     /// ```
 |     /// ```
 | ||||||
|     pub fn clear(&self, clear_type: ClearType) { |     pub fn clear(&self, clear_type: ClearType) { | ||||||
|         self.terminal.clear(clear_type); |         self.terminal.clear(clear_type, &self.screen_manager); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Get the terminal size (x,y).
 |     /// Get the terminal size (x,y).
 | ||||||
| @ -82,7 +82,7 @@ impl Terminal { | |||||||
|     ///
 |     ///
 | ||||||
|     /// ```
 |     /// ```
 | ||||||
|     pub fn terminal_size(&self) -> (u16, u16) { |     pub fn terminal_size(&self) -> (u16, u16) { | ||||||
|         return self.terminal.terminal_size(); |         return self.terminal.terminal_size(&self.screen_manager); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Scroll `n` lines up in the current terminal.
 |     /// Scroll `n` lines up in the current terminal.
 | ||||||
| @ -103,7 +103,7 @@ impl Terminal { | |||||||
|     ///
 |     ///
 | ||||||
|     /// ```
 |     /// ```
 | ||||||
|     pub fn scroll_up(&self, count: i16) { |     pub fn scroll_up(&self, count: i16) { | ||||||
|         self.terminal.scroll_up(count); |         self.terminal.scroll_up(count,&self.screen_manager); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Scroll `n` lines up in the current terminal.
 |     /// Scroll `n` lines up in the current terminal.
 | ||||||
| @ -124,7 +124,7 @@ impl Terminal { | |||||||
|     ///
 |     ///
 | ||||||
|     /// ```
 |     /// ```
 | ||||||
|     pub fn scroll_down(&self, count: i16) { |     pub fn scroll_down(&self, count: i16) { | ||||||
|         self.terminal.scroll_down(count); |         self.terminal.scroll_down(count,&self.screen_manager); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Set the terminal size. Note that not all terminals can be set to a very small scale.
 |     /// Set the terminal size. Note that not all terminals can be set to a very small scale.
 | ||||||
| @ -145,7 +145,7 @@ impl Terminal { | |||||||
|     ///
 |     ///
 | ||||||
|     /// ```
 |     /// ```
 | ||||||
|     pub fn set_size(&self, width: i16, height: i16) { |     pub fn set_size(&self, width: i16, height: i16) { | ||||||
|         self.terminal.set_size(width, height); |         self.terminal.set_size(width, height,&self.screen_manager); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Wraps an displayable object so it can be formatted with colors and attributes.
 |     /// Wraps an displayable object so it can be formatted with colors and attributes.
 | ||||||
| @ -176,12 +176,12 @@ impl Terminal { | |||||||
|     /// }
 |     /// }
 | ||||||
|     ///
 |     ///
 | ||||||
|     /// ```
 |     /// ```
 | ||||||
|     pub fn paint<D>(&self, val: D) -> style::StyledObject<D> | //    pub fn paint<D>(&self, val: D) -> style::StyledObject<D>
 | ||||||
|     where | //    where
 | ||||||
|         D: fmt::Display, | //        D: fmt::Display,
 | ||||||
|     { | //    {
 | ||||||
|         style::ObjectStyle::new().apply_to(val, self.context.clone()) | //        style::ObjectStyle::new().apply_to(val, self.context.clone())
 | ||||||
|     } | //    }
 | ||||||
| 
 | 
 | ||||||
|     /// Exit the current process.
 |     /// Exit the current process.
 | ||||||
|     ///
 |     ///
 | ||||||
| @ -220,17 +220,9 @@ impl Terminal { | |||||||
|     ///
 |     ///
 | ||||||
|     /// ```
 |     /// ```
 | ||||||
|     pub fn write<D: fmt::Display>(&self, value: D) { |     pub fn write<D: fmt::Display>(&self, value: D) { | ||||||
|         let mut mutex = &self.context.screen_manager; |         let mut string = String::new(); | ||||||
|         { |         write!(string, "{}", value).unwrap(); | ||||||
|             let mut screen_manager = mutex.lock().unwrap(); |         self.screen_manager.write_string(string); | ||||||
| 
 |  | ||||||
|             use std::fmt::Write; |  | ||||||
|             let mut string = String::new(); |  | ||||||
|             write!(string, "{}", value).unwrap(); |  | ||||||
| 
 |  | ||||||
|             screen_manager.write_string(string); |  | ||||||
|             screen_manager.flush(); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -255,6 +247,6 @@ impl Terminal { | |||||||
| ///
 | ///
 | ||||||
| /// ```
 | /// ```
 | ||||||
| ///
 | ///
 | ||||||
| pub fn terminal(context: &Rc<Context>) -> Box<Terminal> { | pub fn terminal(screen_manager: &ScreenManager) -> Terminal { | ||||||
|     Box::from(Terminal::new(context.clone())) |     Terminal::new(screen_manager) | ||||||
| } | } | ||||||
|  | |||||||
| @ -7,41 +7,39 @@ use super::{ClearType, ITerminal, Rc}; | |||||||
| use cursor::cursor; | use cursor::cursor; | ||||||
| use kernel::windows_kernel::{csbi, kernel, terminal, writing}; | use kernel::windows_kernel::{csbi, kernel, terminal, writing}; | ||||||
| use winapi::um::wincon::{CONSOLE_SCREEN_BUFFER_INFO, COORD, SMALL_RECT}; | use winapi::um::wincon::{CONSOLE_SCREEN_BUFFER_INFO, COORD, SMALL_RECT}; | ||||||
| use Context; | use ScreenManager; | ||||||
| 
 | 
 | ||||||
| use std::sync::Mutex; | use std::sync::Mutex; | ||||||
| 
 | 
 | ||||||
| /// This struct is an windows implementation for terminal related actions.
 | /// This struct is an windows implementation for terminal related actions.
 | ||||||
| pub struct WinApiTerminal { | pub struct WinApiTerminal; | ||||||
|     context: Rc<Context>, |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| impl WinApiTerminal { | impl WinApiTerminal { | ||||||
|     pub fn new(context: Rc<Context>) -> Box<WinApiTerminal> { |     pub fn new() -> WinApiTerminal { | ||||||
|         Box::from(WinApiTerminal { context }) |         WinApiTerminal { } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl ITerminal for WinApiTerminal { | impl ITerminal for WinApiTerminal { | ||||||
|     fn clear(&self, clear_type: ClearType) { |     fn clear(&self, clear_type: ClearType, screen_manager: &ScreenManager) { | ||||||
|         let csbi = csbi::get_csbi(&self.context.screen_manager).unwrap(); |         let csbi = csbi::get_csbi(screen_manager).unwrap(); | ||||||
|         let pos = cursor(&self.context).pos(); |         let pos = cursor(screen_manager).pos(); | ||||||
| 
 | 
 | ||||||
|         match clear_type { |         match clear_type { | ||||||
|             ClearType::All => clear_entire_screen(csbi, &self.context), |             ClearType::All => clear_entire_screen(csbi, &screen_manager), | ||||||
|             ClearType::FromCursorDown => clear_after_cursor(pos, csbi, &self.context), |             ClearType::FromCursorDown => clear_after_cursor(pos, csbi, screen_manager), | ||||||
|             ClearType::FromCursorUp => clear_before_cursor(pos, csbi, &self.context), |             ClearType::FromCursorUp => clear_before_cursor(pos, csbi, screen_manager), | ||||||
|             ClearType::CurrentLine => clear_current_line(pos, csbi, &self.context), |             ClearType::CurrentLine => clear_current_line(pos, csbi, screen_manager), | ||||||
|             ClearType::UntilNewLine => clear_until_line(pos, csbi, &self.context), |             ClearType::UntilNewLine => clear_until_line(pos, csbi, screen_manager), | ||||||
|         }; |         }; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn terminal_size(&self) -> (u16, u16) { |     fn terminal_size(&self, screen_manager: &ScreenManager) -> (u16, u16) { | ||||||
|         terminal::terminal_size(&self.context.screen_manager) |         terminal::terminal_size(screen_manager) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn scroll_up(&self, count: i16) { |     fn scroll_up(&self, count: i16, screen_manager: &ScreenManager) { | ||||||
|         let csbi = csbi::get_csbi(&self.context.screen_manager).unwrap(); |         let csbi = csbi::get_csbi(&screen_manager).unwrap(); | ||||||
| 
 | 
 | ||||||
|         // Set srctWindow to the current window size and location.
 |         // Set srctWindow to the current window size and location.
 | ||||||
|         let mut srct_window = csbi.srWindow; |         let mut srct_window = csbi.srWindow; | ||||||
| @ -52,15 +50,15 @@ impl ITerminal for WinApiTerminal { | |||||||
|             srct_window.Bottom = count; // move bottom down
 |             srct_window.Bottom = count; // move bottom down
 | ||||||
| 
 | 
 | ||||||
|             let success = |             let success = | ||||||
|                 kernel::set_console_info(false, &mut srct_window, &self.context.screen_manager); |                 kernel::set_console_info(false, &mut srct_window, &screen_manager); | ||||||
|             if success { |             if success { | ||||||
|                 panic!("Something went wrong when scrolling down"); |                 panic!("Something went wrong when scrolling down"); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn scroll_down(&self, count: i16) { |     fn scroll_down(&self, count: i16, screen_manager: &ScreenManager) { | ||||||
|         let csbi = csbi::get_csbi(&self.context.screen_manager).unwrap(); |         let csbi = csbi::get_csbi(&screen_manager).unwrap(); | ||||||
|         // Set srctWindow to the current window size and location.
 |         // Set srctWindow to the current window size and location.
 | ||||||
|         let mut srct_window = csbi.srWindow; |         let mut srct_window = csbi.srWindow; | ||||||
| 
 | 
 | ||||||
| @ -75,7 +73,7 @@ impl ITerminal for WinApiTerminal { | |||||||
|             srct_window.Bottom += count; // move bottom down
 |             srct_window.Bottom += count; // move bottom down
 | ||||||
| 
 | 
 | ||||||
|             let success = |             let success = | ||||||
|                 kernel::set_console_info(true, &mut srct_window, &self.context.screen_manager); |                 kernel::set_console_info(true, &mut srct_window, &screen_manager); | ||||||
|             if success { |             if success { | ||||||
|                 panic!("Something went wrong when scrolling down"); |                 panic!("Something went wrong when scrolling down"); | ||||||
|             } |             } | ||||||
| @ -83,7 +81,7 @@ impl ITerminal for WinApiTerminal { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Set the current terminal size
 |     /// Set the current terminal size
 | ||||||
|     fn set_size(&self, width: i16, height: i16) { |     fn set_size(&self, width: i16, height: i16, screen_manager: &ScreenManager) { | ||||||
|         if width <= 0 { |         if width <= 0 { | ||||||
|             panic!("Cannot set the terminal width lower than 1"); |             panic!("Cannot set the terminal width lower than 1"); | ||||||
|         } |         } | ||||||
| @ -93,7 +91,7 @@ impl ITerminal for WinApiTerminal { | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // Get the position of the current console window
 |         // Get the position of the current console window
 | ||||||
|         let csbi = csbi::get_csbi(&self.context.screen_manager).unwrap(); |         let csbi = csbi::get_csbi(&screen_manager).unwrap(); | ||||||
|         let mut success = false; |         let mut success = false; | ||||||
| 
 | 
 | ||||||
|         // If the buffer is smaller than this new window size, resize the
 |         // If the buffer is smaller than this new window size, resize the
 | ||||||
| @ -122,7 +120,7 @@ impl ITerminal for WinApiTerminal { | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if resize_buffer { |         if resize_buffer { | ||||||
|             success = csbi::set_console_screen_buffer_size(size, &self.context.screen_manager); |             success = csbi::set_console_screen_buffer_size(size, &screen_manager); | ||||||
| 
 | 
 | ||||||
|             if !success { |             if !success { | ||||||
|                 panic!("Something went wrong when setting screen buffer size."); |                 panic!("Something went wrong when setting screen buffer size."); | ||||||
| @ -134,12 +132,12 @@ impl ITerminal for WinApiTerminal { | |||||||
|         fsr_window.Bottom = fsr_window.Top + height; |         fsr_window.Bottom = fsr_window.Top + height; | ||||||
|         fsr_window.Right = fsr_window.Left + width; |         fsr_window.Right = fsr_window.Left + width; | ||||||
| 
 | 
 | ||||||
|         let success = kernel::set_console_info(true, &fsr_window, &self.context.screen_manager); |         let success = kernel::set_console_info(true, &fsr_window, &screen_manager); | ||||||
| 
 | 
 | ||||||
|         if success { |         if success { | ||||||
|             // If we resized the buffer, un-resize it.
 |             // If we resized the buffer, un-resize it.
 | ||||||
|             if resize_buffer { |             if resize_buffer { | ||||||
|                 csbi::set_console_screen_buffer_size(csbi.dwSize, &self.context.screen_manager); |                 csbi::set_console_screen_buffer_size(csbi.dwSize, &screen_manager); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             let bounds = kernel::get_largest_console_window_size(); |             let bounds = kernel::get_largest_console_window_size(); | ||||||
| @ -167,7 +165,7 @@ impl ITerminal for WinApiTerminal { | |||||||
| pub fn clear_after_cursor( | pub fn clear_after_cursor( | ||||||
|     pos: (u16, u16), |     pos: (u16, u16), | ||||||
|     csbi: CONSOLE_SCREEN_BUFFER_INFO, |     csbi: CONSOLE_SCREEN_BUFFER_INFO, | ||||||
|     context: &Rc<Context>, |     screen_manager: &ScreenManager, | ||||||
| ) { | ) { | ||||||
|     let (mut x, mut y) = pos; |     let (mut x, mut y) = pos; | ||||||
| 
 | 
 | ||||||
| @ -185,13 +183,13 @@ pub fn clear_after_cursor( | |||||||
|     // get sum cells before cursor
 |     // get sum cells before cursor
 | ||||||
|     let cells_to_write = csbi.dwSize.X as u32 * csbi.dwSize.Y as u32; |     let cells_to_write = csbi.dwSize.X as u32 * csbi.dwSize.Y as u32; | ||||||
| 
 | 
 | ||||||
|     clear(start_location, cells_to_write, &context.screen_manager); |     clear(start_location, cells_to_write, screen_manager); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn clear_before_cursor( | pub fn clear_before_cursor( | ||||||
|     pos: (u16, u16), |     pos: (u16, u16), | ||||||
|     csbi: CONSOLE_SCREEN_BUFFER_INFO, |     csbi: CONSOLE_SCREEN_BUFFER_INFO, | ||||||
|     context: &Rc<Context>, |     screen_manager: &ScreenManager, | ||||||
| ) { | ) { | ||||||
|     let (xpos, ypos) = pos; |     let (xpos, ypos) = pos; | ||||||
| 
 | 
 | ||||||
| @ -208,10 +206,10 @@ pub fn clear_before_cursor( | |||||||
|     // get sum cells before cursor
 |     // get sum cells before cursor
 | ||||||
|     let cells_to_write = (csbi.dwSize.X as u32 * ypos as u32) + (xpos as u32 + 1); |     let cells_to_write = (csbi.dwSize.X as u32 * ypos as u32) + (xpos as u32 + 1); | ||||||
| 
 | 
 | ||||||
|     clear(start_location, cells_to_write, &context.screen_manager); |     clear(start_location, cells_to_write, &screen_manager); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn clear_entire_screen(csbi: CONSOLE_SCREEN_BUFFER_INFO, context: &Rc<Context>) { | pub fn clear_entire_screen(csbi: CONSOLE_SCREEN_BUFFER_INFO, screen_manager: &ScreenManager) { | ||||||
|     // position x at start
 |     // position x at start
 | ||||||
|     let x = 0; |     let x = 0; | ||||||
|     // position y at start
 |     // position y at start
 | ||||||
| @ -226,16 +224,16 @@ pub fn clear_entire_screen(csbi: CONSOLE_SCREEN_BUFFER_INFO, context: &Rc<Contex | |||||||
| 
 | 
 | ||||||
|     let cells_to_write = csbi.dwSize.X as u32 * csbi.dwSize.Y as u32; |     let cells_to_write = csbi.dwSize.X as u32 * csbi.dwSize.Y as u32; | ||||||
| 
 | 
 | ||||||
|     clear(start_location, cells_to_write, &context.screen_manager); |     clear(start_location, cells_to_write, &screen_manager); | ||||||
| 
 | 
 | ||||||
|     // put the cursor back at (0, 0)
 |     // put the cursor back at (0, 0)
 | ||||||
|     cursor(&context).goto(0, 0); |     cursor(&screen_manager).goto(0, 0); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn clear_current_line( | pub fn clear_current_line( | ||||||
|     pos: (u16, u16), |     pos: (u16, u16), | ||||||
|     csbi: CONSOLE_SCREEN_BUFFER_INFO, |     csbi: CONSOLE_SCREEN_BUFFER_INFO, | ||||||
|     context: &Rc<Context>, |     screen_manager: &ScreenManager, | ||||||
| ) { | ) { | ||||||
|     // position x at start
 |     // position x at start
 | ||||||
|     let x = 0; |     let x = 0; | ||||||
| @ -251,13 +249,13 @@ pub fn clear_current_line( | |||||||
| 
 | 
 | ||||||
|     let cells_to_write = csbi.dwSize.X as u32; |     let cells_to_write = csbi.dwSize.X as u32; | ||||||
| 
 | 
 | ||||||
|     clear(start_location, cells_to_write, &context.screen_manager); |     clear(start_location, cells_to_write, screen_manager); | ||||||
| 
 | 
 | ||||||
|     // put the cursor back at 1 cell on current row
 |     // put the cursor back at 1 cell on current row
 | ||||||
|     cursor(&context).goto(0, y); |     cursor(&screen_manager).goto(0, y); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn clear_until_line(pos: (u16, u16), csbi: CONSOLE_SCREEN_BUFFER_INFO, context: &Rc<Context>) { | pub fn clear_until_line(pos: (u16, u16), csbi: CONSOLE_SCREEN_BUFFER_INFO, screen_manager: &ScreenManager) { | ||||||
|     let (x, y) = pos; |     let (x, y) = pos; | ||||||
| 
 | 
 | ||||||
|     // location where to start clearing
 |     // location where to start clearing
 | ||||||
| @ -268,13 +266,13 @@ pub fn clear_until_line(pos: (u16, u16), csbi: CONSOLE_SCREEN_BUFFER_INFO, conte | |||||||
|     // get sum cells before cursor
 |     // get sum cells before cursor
 | ||||||
|     let cells_to_write = (csbi.dwSize.X - x as i16) as u32; |     let cells_to_write = (csbi.dwSize.X - x as i16) as u32; | ||||||
| 
 | 
 | ||||||
|     clear(start_location, cells_to_write, &context.screen_manager); |     clear(start_location, cells_to_write, &screen_manager); | ||||||
| 
 | 
 | ||||||
|     // put the cursor back at original cursor position
 |     // put the cursor back at original cursor position
 | ||||||
|     cursor(&context).goto(x, y); |     cursor(&screen_manager).goto(x, y); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn clear(start_loaction: COORD, cells_to_write: u32, screen_manager: &Rc<Mutex<ScreenManager>>) { | fn clear(start_loaction: COORD, cells_to_write: u32, screen_manager: &ScreenManager) { | ||||||
|     let mut cells_written = 0; |     let mut cells_written = 0; | ||||||
|     let mut success = false; |     let mut success = false; | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user