diff options
author | Christian Duerr <contact@christianduerr.com> | 2019-10-05 02:29:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-05 02:29:26 +0200 |
commit | 729eef0c933831bccfeac6a355bdb410787fbe5f (patch) | |
tree | 35cdf2e6427ad18bc53efbab4cab34a0af2054d7 /alacritty_terminal/src/term | |
parent | b0c6fdff763f7271506d26d7e768e6377fdc691b (diff) | |
download | alacritty-729eef0c933831bccfeac6a355bdb410787fbe5f.tar.gz alacritty-729eef0c933831bccfeac6a355bdb410787fbe5f.zip |
Update to winit/glutin EventLoop 2.0
This takes the latest glutin master to port Alacritty to the EventLoop
2.0 rework.
This changes a big part of the event loop handling by pushing the event
loop in a separate thread from the renderer and running both in
parallel.
Fixes #2796.
Fixes #2694.
Fixes #2643.
Fixes #2625.
Fixes #2618.
Fixes #2601.
Fixes #2564.
Fixes #2456.
Fixes #2438.
Fixes #2334.
Fixes #2254.
Fixes #2217.
Fixes #1789.
Fixes #1750.
Fixes #1125.
Diffstat (limited to 'alacritty_terminal/src/term')
-rw-r--r-- | alacritty_terminal/src/term/cell.rs | 2 | ||||
-rw-r--r-- | alacritty_terminal/src/term/color.rs | 3 | ||||
-rw-r--r-- | alacritty_terminal/src/term/mod.rs | 398 |
3 files changed, 127 insertions, 276 deletions
diff --git a/alacritty_terminal/src/term/cell.rs b/alacritty_terminal/src/term/cell.rs index 7a759777..234805f9 100644 --- a/alacritty_terminal/src/term/cell.rs +++ b/alacritty_terminal/src/term/cell.rs @@ -13,6 +13,8 @@ // limitations under the License. use bitflags::bitflags; +use serde::{Deserialize, Serialize}; + use crate::ansi::{Color, NamedColor}; use crate::grid::{self, GridCell}; use crate::index::Column; diff --git a/alacritty_terminal/src/term/color.rs b/alacritty_terminal/src/term/color.rs index f2db335a..e9f0a26d 100644 --- a/alacritty_terminal/src/term/color.rs +++ b/alacritty_terminal/src/term/color.rs @@ -2,8 +2,9 @@ use std::fmt; use std::ops::{Index, IndexMut, Mul}; use std::str::FromStr; +use log::{error, trace}; use serde::de::Visitor; -use serde::{Deserialize, Deserializer}; +use serde::{Deserialize, Deserializer, Serialize}; use crate::ansi; use crate::config::Colors; diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 58d06318..4e51d734 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -18,9 +18,9 @@ use std::ops::{Index, IndexMut, Range, RangeInclusive}; use std::time::{Duration, Instant}; use std::{io, mem, ptr}; -use font::{self, Size}; -use glutin::MouseCursor; +use log::{debug, trace}; use rfind_url::{Parser, ParserState}; +use serde::{Deserialize, Serialize}; use unicode_width::UnicodeWidthChar; use crate::ansi::{ @@ -29,19 +29,17 @@ use crate::ansi::{ use crate::clipboard::{Clipboard, ClipboardType}; use crate::config::{Config, VisualBellAnimation}; use crate::cursor::CursorKey; +use crate::event::{Event, EventListener}; use crate::grid::{ BidirectionalIterator, DisplayIter, Grid, GridCell, IndexRegion, Indexed, Scroll, }; use crate::index::{self, Column, Contains, IndexRange, Line, Linear, Point}; -use crate::input::FONT_SIZE_STEP; -use crate::message_bar::MessageBuffer; use crate::selection::{self, Selection, SelectionRange, Span}; use crate::term::cell::{Cell, Flags, LineLength}; use crate::term::color::Rgb; -use crate::url::Url; - #[cfg(windows)] use crate::tty; +use crate::url::Url; pub mod cell; pub mod color; @@ -62,7 +60,7 @@ pub trait Search { fn bracket_search(&self, _: Point<usize>) -> Option<Point<usize>>; } -impl Search for Term { +impl<T> Search for Term<T> { fn semantic_search_left(&self, mut point: Point<usize>) -> Point<usize> { // Limit the starting point to the last line in the history point.line = min(point.line, self.grid.len() - 1); @@ -151,7 +149,7 @@ impl Search for Term { } } -impl selection::Dimensions for Term { +impl<T> selection::Dimensions for Term<T> { fn dimensions(&self) -> Point { let line = if self.mode.contains(TermMode::ALT_SCREEN) { self.grid.num_lines() @@ -170,30 +168,30 @@ impl selection::Dimensions for Term { /// /// This manages the cursor during a render. The cursor location is inverted to /// draw it, and reverted after drawing to maintain state. -pub struct RenderableCellsIter<'a> { +pub struct RenderableCellsIter<'a, C> { inner: DisplayIter<'a, Cell>, grid: &'a Grid<Cell>, cursor: &'a Point, cursor_offset: usize, cursor_key: Option<CursorKey>, cursor_style: CursorStyle, - config: &'a Config, + config: &'a Config<C>, colors: &'a color::List, selection: Option<SelectionRange>, url_highlight: &'a Option<RangeInclusive<index::Linear>>, } -impl<'a> RenderableCellsIter<'a> { +impl<'a, C> RenderableCellsIter<'a, C> { /// Create the renderable cells iterator /// /// The cursor and terminal mode are required for properly displaying the /// cursor. - fn new<'b>( - term: &'b Term, - config: &'b Config, + fn new<'b, T>( + term: &'b Term<T>, + config: &'b Config<C>, selection: Option<Span>, mut cursor_style: CursorStyle, - ) -> RenderableCellsIter<'b> { + ) -> RenderableCellsIter<'b, C> { let grid = &term.grid; let cursor_offset = grid.line_to_offset(term.cursor.point.line); @@ -250,13 +248,13 @@ impl<'a> RenderableCellsIter<'a> { } } -#[derive(Clone, Debug)] +#[derive(Copy, Clone, Debug)] pub enum RenderableCellContent { Chars([char; cell::MAX_ZEROWIDTH_CHARS + 1]), Cursor(CursorKey), } -#[derive(Clone, Debug)] +#[derive(Copy, Clone, Debug)] pub struct RenderableCell { /// A _Display_ line (not necessarily an _Active_ line) pub line: Line, @@ -269,7 +267,12 @@ pub struct RenderableCell { } impl RenderableCell { - fn new(config: &Config, colors: &color::List, cell: Indexed<Cell>, selected: bool) -> Self { + fn new<C>( + config: &Config<C>, + colors: &color::List, + cell: Indexed<Cell>, + selected: bool, + ) -> Self { // Lookup RGB values let mut fg_rgb = Self::compute_fg_rgb(config, colors, cell.fg, cell.flags); let mut bg_rgb = Self::compute_bg_rgb(colors, cell.bg); @@ -309,7 +312,12 @@ impl RenderableCell { } } - fn compute_fg_rgb(config: &Config, colors: &color::List, fg: Color, flags: cell::Flags) -> Rgb { + fn compute_fg_rgb<C>( + config: &Config<C>, + colors: &color::List, + fg: Color, + flags: cell::Flags, + ) -> Rgb { match fg { Color::Spec(rgb) => rgb, Color::Named(ansi) => { @@ -365,7 +373,7 @@ impl RenderableCell { } } -impl<'a> Iterator for RenderableCellsIter<'a> { +impl<'a, C> Iterator for RenderableCellsIter<'a, C> { type Item = RenderableCell; /// Gets the next renderable cell @@ -573,7 +581,7 @@ fn cubic_bezier(p0: f64, p1: f64, p2: f64, p3: f64, x: f64) -> f64 { } impl VisualBell { - pub fn new(config: &Config) -> VisualBell { + pub fn new<C>(config: &Config<C>) -> VisualBell { let visual_bell_config = &config.visual_bell; VisualBell { animation: visual_bell_config.animation, @@ -668,14 +676,14 @@ impl VisualBell { } } - pub fn update_config(&mut self, config: &Config) { + pub fn update_config<C>(&mut self, config: &Config<C>) { let visual_bell_config = &config.visual_bell; self.animation = visual_bell_config.animation; self.duration = visual_bell_config.duration(); } } -pub struct Term { +pub struct Term<T> { /// The grid grid: Grid<Cell>, @@ -686,14 +694,6 @@ pub struct Term { /// arrays. Without it we would have to sanitize cursor.col every time we used it. input_needs_wrap: bool, - /// Got a request to set title; it's buffered here until next draw. - /// - /// Would be nice to avoid the allocation... - next_title: Option<String>, - - /// Got a request to set the mouse cursor; it's buffered here until the next draw - next_mouse_cursor: Option<MouseCursor>, - /// Alternate grid alt_grid: Grid<Cell>, @@ -716,17 +716,9 @@ pub struct Term { /// Scroll region scroll_region: Range<Line>, - /// Font size - pub font_size: Size, - original_font_size: Size, - - /// Size - size_info: SizeInfo, - pub dirty: bool, pub visual_bell: VisualBell, - pub next_is_urgent: Option<bool>, /// Saved cursor from main grid cursor_save: Cursor, @@ -760,18 +752,18 @@ pub struct Term { /// Automatically scroll to bottom when new lines are added auto_scroll: bool, - /// Buffer to store messages for the message bar - message_buffer: MessageBuffer, - - /// Hint that Alacritty should be closed - should_exit: bool, - /// Clipboard access coupled to the active window clipboard: Clipboard, + + /// Proxy for sending events to the event loop + event_proxy: T, + + /// Terminal focus + pub is_focused: bool, } /// Terminal size info -#[derive(Debug, Copy, Clone, Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] pub struct SizeInfo { /// Terminal window width pub width: f32, @@ -829,7 +821,7 @@ impl SizeInfo { } } -impl Term { +impl<T> Term<T> { pub fn selection(&self) -> &Option<Selection> { &self.grid.selection } @@ -839,29 +831,22 @@ impl Term { } #[inline] - pub fn get_next_title(&mut self) -> Option<String> { - self.next_title.take() - } - - #[inline] - pub fn scroll_display(&mut self, scroll: Scroll) { - self.set_mouse_cursor(MouseCursor::Text); + pub fn scroll_display(&mut self, scroll: Scroll) + where + T: EventListener, + { + self.event_proxy.send_event(Event::MouseCursorDirty); self.grid.scroll_display(scroll); self.reset_url_highlight(); self.dirty = true; } - #[inline] - pub fn get_next_mouse_cursor(&mut self) -> Option<MouseCursor> { - self.next_mouse_cursor.take() - } - - pub fn new( - config: &Config, - size: SizeInfo, - message_buffer: MessageBuffer, + pub fn new<C>( + config: &Config<C>, + size: &SizeInfo, clipboard: Clipboard, - ) -> Term { + event_proxy: T, + ) -> Term<T> { let num_cols = size.cols(); let num_lines = size.lines(); @@ -877,17 +862,12 @@ impl Term { let colors = color::List::from(&config.colors); Term { - next_title: None, - next_mouse_cursor: None, dirty: false, visual_bell: VisualBell::new(config), - next_is_urgent: None, input_needs_wrap: false, grid, alt_grid: alt, alt: false, - font_size: config.font.size, - original_font_size: config.font.size, active_charset: Default::default(), cursor: Default::default(), cursor_save: Default::default(), @@ -895,7 +875,6 @@ impl Term { tabs, mode: Default::default(), scroll_region, - size_info: size, colors, color_modified: [false; color::COUNT], original_colors: colors, @@ -905,25 +884,13 @@ impl Term { dynamic_title: config.dynamic_title(), tabspaces, auto_scroll: config.scrolling.auto_scroll, - message_buffer, - should_exit: false, clipboard, + event_proxy, + is_focused: true, } } - pub fn change_font_size(&mut self, delta: f32) { - // Saturating addition with minimum font size FONT_SIZE_STEP - let new_size = self.font_size + Size::new(delta); - self.font_size = max(new_size, Size::new(FONT_SIZE_STEP)); - self.dirty = true; - } - - pub fn reset_font_size(&mut self) { - self.font_size = self.original_font_size; - self.dirty = true; - } - - pub fn update_config(&mut self, config: &Config) { + pub fn update_config<C>(&mut self, config: &Config<C>) { self.semantic_escape_chars = config.selection.semantic_escape_chars().to_owned(); self.original_colors.fill_named(&config.colors); self.original_colors.fill_cube(&config.colors); @@ -938,16 +905,6 @@ impl Term { self.dynamic_title = config.dynamic_title(); self.auto_scroll = config.scrolling.auto_scroll; self.grid.update_history(config.scrolling.history() as usize, &self.cursor.template); - - if self.original_font_size == self.font_size { - self.font_size = config.font.size; - } - self.original_font_size = config.font.size; - } - - #[inline] - pub fn needs_draw(&self) -> bool { - self.dirty } pub fn selection_to_string(&self) -> Option<String> { @@ -1072,21 +1029,6 @@ impl Term { self.grid.buffer_to_visible(point) } - /// Convert the given pixel values to a grid coordinate - /// - /// The mouse coordinates are expected to be relative to the top left. The - /// line and column returned are also relative to the top left. - /// - /// Returns None if the coordinates are outside the window, - /// padding pixels are considered inside the window - pub fn pixels_to_coords(&self, x: usize, y: usize) -> Option<Point> { - if self.size_info.contains_point(x, y, true) { - Some(self.size_info.pixels_to_coords(x, y)) - } else { - None - } - } - /// Access to the raw grid data structure /// /// This is a bit of a hack; when the window is closed, the event processor @@ -1106,14 +1048,10 @@ impl Term { /// A renderable cell is any cell which has content other than the default /// background color. Cells with an alternate background color are /// considered renderable as are cells with any text content. - pub fn renderable_cells<'b>( - &'b self, - config: &'b Config, - window_focused: bool, - ) -> RenderableCellsIter<'_> { + pub fn renderable_cells<'b, C>(&'b self, config: &'b Config<C>) -> RenderableCellsIter<'_, C> { let selection = self.grid.selection.as_ref().and_then(|s| s.to_span(self)); - let cursor = if window_focused || !config.cursor.unfocused_hollow() { + let cursor = if self.is_focused || !config.cursor.unfocused_hollow() { self.cursor_style.unwrap_or(self.default_cursor_style) } else { CursorStyle::HollowBlock @@ -1124,11 +1062,9 @@ impl Term { /// Resize terminal to new dimensions pub fn resize(&mut self, size: &SizeInfo) { - debug!("Resizing terminal"); - // Bounds check; lots of math assumes width and height are > 0 - if size.width as usize <= 2 * self.size_info.padding_x as usize - || size.height as usize <= 2 * self.size_info.padding_y as usize + if size.width as usize <= 2 * size.padding_x as usize + || size.height as usize <= 2 * size.padding_y as usize { return; } @@ -1138,12 +1074,6 @@ impl Term { let mut num_cols = size.cols(); let mut num_lines = size.lines(); - if let Some(message) = self.message_buffer.message() { - num_lines -= message.text(size).len(); - } - - self.size_info = *size; - if old_cols == num_cols && old_lines == num_lines { debug!("Term::resize dimensions unchanged"); return; @@ -1211,11 +1141,6 @@ impl Term { } #[inline] - pub fn size_info(&self) -> &SizeInfo { - &self.size_info - } - - #[inline] pub fn mode(&self) -> &TermMode { &self.mode } @@ -1266,7 +1191,10 @@ impl Term { self.grid.scroll_up(&(origin..self.scroll_region.end), lines, &template); } - fn deccolm(&mut self) { + fn deccolm(&mut self) + where + T: EventListener, + { // Setting 132 column font makes no sense, but run the other side effects // Clear scrolling region self.set_scrolling_region(1, self.grid.num_lines().0); @@ -1282,23 +1210,11 @@ impl Term { } #[inline] - pub fn message_buffer_mut(&mut self) -> &mut MessageBuffer { - &mut self.message_buffer - } - - #[inline] - pub fn message_buffer(&self) -> &MessageBuffer { - &self.message_buffer - } - - #[inline] - pub fn exit(&mut self) { - self.should_exit = true; - } - - #[inline] - pub fn should_exit(&self) -> bool { - self.should_exit + pub fn exit(&mut self) + where + T: EventListener, + { + self.event_proxy.send_event(Event::Exit); } #[inline] @@ -1389,7 +1305,7 @@ impl Term { } } -impl TermInfo for Term { +impl<T> TermInfo for Term<T> { #[inline] fn lines(&self) -> Line { self.grid.num_lines() @@ -1401,33 +1317,33 @@ impl TermInfo for Term { } } -impl ansi::Handler for Term { - /// Set the window title +impl<T: EventListener> ansi::Handler for Term<T> { #[inline] + #[cfg(not(windows))] fn set_title(&mut self, title: &str) { if self.dynamic_title { - self.next_title = Some(title.to_owned()); - - #[cfg(windows)] - { - // cmd.exe in winpty: winpty incorrectly sets the title to ' ' instead of - // 'Alacritty' - thus we have to substitute this back to get equivalent - // behaviour as conpty. - // - // The starts_with check is necessary because other shells e.g. bash set a - // different title and don't need Alacritty prepended. - if !tty::is_conpty() && title.starts_with(' ') { - self.next_title = Some(format!("Alacritty {}", title.trim())); - } - } + self.event_proxy.send_event(Event::Title(title.to_owned())); } } - /// Set the mouse cursor #[inline] - fn set_mouse_cursor(&mut self, cursor: MouseCursor) { - self.next_mouse_cursor = Some(cursor); - self.dirty = true; + #[cfg(windows)] + fn set_title(&mut self, title: &str) { + if self.dynamic_title { + // cmd.exe in winpty: winpty incorrectly sets the title to ' ' instead of + // 'Alacritty' - thus we have to substitute this back to get equivalent + // behaviour as conpty. + // + // The starts_with check is necessary because other shells e.g. bash set a + // different title and don't need Alacritty prepended. + let title = if !tty::is_conpty() && title.starts_with(' ') { + format!("Alacritty {}", title.trim()) + } else { + title.to_owned() + }; + + self.event_proxy.send_event(Event::Title(title)); + } } /// A character to be displayed @@ -1554,11 +1470,11 @@ impl ansi::Handler for Term { fn insert_blank(&mut self, count: Column) { // Ensure inserting within terminal bounds - let count = min(count, self.size_info.cols() - self.cursor.point.col); + let count = min(count, self.grid.num_cols() - self.cursor.point.col); let source = self.cursor.point.col; let destination = self.cursor.point.col + count; - let num_cells = (self.size_info.cols() - destination).0; + let num_cells = (self.grid.num_cols() - destination).0; let line = &mut self.grid[self.cursor.point.line]; @@ -1703,7 +1619,7 @@ impl ansi::Handler for Term { fn bell(&mut self) { trace!("Bell"); self.visual_bell.ring(); - self.next_is_urgent = Some(true); + self.event_proxy.send_event(Event::Urgent); } #[inline] @@ -1794,12 +1710,14 @@ impl ansi::Handler for Term { #[inline] fn delete_chars(&mut self, count: Column) { + let cols = self.grid.num_cols(); + // Ensure deleting within terminal bounds - let count = min(count, self.size_info.cols()); + let count = min(count, cols); let start = self.cursor.point.col; - let end = min(start + count, self.grid.num_cols() - 1); - let n = (self.size_info.cols() - end).0; + let end = min(start + count, cols - 1); + let n = (cols - end).0; let line = &mut self.grid[self.cursor.point.line]; @@ -1813,7 +1731,7 @@ impl ansi::Handler for Term { // Clear last `count` cells in line. If deleting 1 char, need to delete // 1 cell. let template = self.cursor.template; - let end = self.size_info.cols() - count; + let end = cols - count; for c in &mut line[end..] { c.reset(&template); } @@ -1983,13 +1901,9 @@ impl ansi::Handler for Term { self.swap_alt(); } self.input_needs_wrap = false; - self.next_title = None; - self.next_mouse_cursor = None; self.cursor = Default::default(); self.active_charset = Default::default(); self.mode = Default::default(); - self.font_size = self.original_font_size; - self.next_is_urgent = None; self.cursor_save = Default::default(); self.cursor_save_alt = Default::default(); self.colors = self.original_colors; @@ -2061,15 +1975,15 @@ impl ansi::Handler for Term { ansi::Mode::CursorKeys => self.mode.insert(TermMode::APP_CURSOR), ansi::Mode::ReportMouseClicks => { self.mode.insert(TermMode::MOUSE_REPORT_CLICK); - self.set_mouse_cursor(MouseCursor::Default); + self.event_proxy.send_event(Event::MouseCursorDirty); }, ansi::Mode::ReportCellMouseMotion => { self.mode.insert(TermMode::MOUSE_DRAG); - self.set_mouse_cursor(MouseCursor::Default); + self.event_proxy.send_event(Event::MouseCursorDirty); }, ansi::Mode::ReportAllMouseMotion => { self.mode.insert(TermMode::MOUSE_MOTION); - self.set_mouse_cursor(MouseCursor::Default); + self.event_proxy.send_event(Event::MouseCursorDirty); }, ansi::Mode::ReportFocusInOut => self.mode.insert(TermMode::FOCUS_IN_OUT), ansi::Mode::BracketedPaste => self.mode.insert(TermMode::BRACKETED_PASTE), @@ -2101,15 +2015,15 @@ impl ansi::Handler for Term { ansi::Mode::CursorKeys => self.mode.remove(TermMode::APP_CURSOR), ansi::Mode::ReportMouseClicks => { self.mode.remove(TermMode::MOUSE_REPORT_CLICK); - self.set_mouse_cursor(MouseCursor::Text); + self.event_proxy.send_event(Event::MouseCursorDirty); }, ansi::Mode::ReportCellMouseMotion => { self.mode.remove(TermMode::MOUSE_DRAG); - self.set_mouse_cursor(MouseCursor::Text); + self.event_proxy.send_event(Event::MouseCursorDirty); }, ansi::Mode::ReportAllMouseMotion => { self.mode.remove(TermMode::MOUSE_MOTION); - self.set_mouse_cursor(MouseCursor::Text); + self.event_proxy.send_event(Event::MouseCursorDirty); }, ansi::Mode::ReportFocusInOut => self.mode.remove(TermMode::FOCUS_IN_OUT), ansi::Mode::BracketedPaste => self.mode.remove(TermMode::BRACKETED_PASTE), @@ -2215,19 +2129,22 @@ impl IndexMut<Column> for TabStops { mod tests { use std::mem; - use font::Size; use serde_json; use crate::ansi::{self, CharsetIndex, Handler, StandardCharset}; use crate::clipboard::Clipboard; - use crate::config::Config; + use crate::config::MockConfig; + use crate::event::{Event, EventListener}; use crate::grid::{Grid, Scroll}; use crate::index::{Column, Line, Point, Side}; - use crate::input::FONT_SIZE_STEP; - use crate::message_bar::MessageBuffer; use crate::selection::Selection; use crate::term::{cell, Cell, SizeInfo, Term}; + struct Mock; + impl EventListener for Mock { + fn send_event(&self, _event: Event) {} + } + #[test] fn semantic_selection_works() { let size = SizeInfo { @@ -2239,8 +2156,7 @@ mod tests { padding_y: 0.0, dpr: 1.0, }; - let mut term = - Term::new(&Default::default(), size, MessageBuffer::new(), Clipboard::new_nop()); + let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock); let mut grid: Grid<Cell> = Grid::new(Line(3), Column(5), 0, Cell::default()); for i in 0..5 { for j in 0..2 { @@ -2284,8 +2200,7 @@ mod tests { padding_y: 0.0, dpr: 1.0, }; - let mut term = - Term::new(&Default::default(), size, MessageBuffer::new(), Clipboard::new_nop()); + let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock); let mut grid: Grid<Cell> = Grid::new(Line(1), Column(5), 0, Cell::default()); for i in 0..5 { grid[Line(0)][Column(i)].c = 'a'; @@ -2310,8 +2225,7 @@ mod tests { padding_y: 0.0, dpr: 1.0, }; - let mut term = - Term::new(&Default::default(), size, MessageBuffer::new(), Clipboard::new_nop()); + let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock); let mut grid: Grid<Cell> = Grid::new(Line(3), Column(3), 0, Cell::default()); for l in 0..3 { if l != 1 { @@ -2355,8 +2269,7 @@ mod tests { padding_y: 0.0, dpr: 1.0, }; - let mut term = - Term::new(&Default::default(), size, MessageBuffer::new(), Clipboard::new_nop()); + let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock); let cursor = Point::new(Line(0), Column(0)); term.configure_charset(CharsetIndex::G0, StandardCharset::SpecialCharacterAndLineDrawing); term.input('a'); @@ -2364,75 +2277,6 @@ mod tests { assert_eq!(term.grid()[&cursor].c, '▒'); } - fn change_font_size_works(font_size: f32) { - let size = SizeInfo { - width: 21.0, - height: 51.0, - cell_width: 3.0, - cell_height: 3.0, - padding_x: 0.0, - padding_y: 0.0, - dpr: 1.0, - }; - let config: Config = Default::default(); - let mut term: Term = Term::new(&config, size, MessageBuffer::new(), Clipboard::new_nop()); - term.change_font_size(font_size); - - let expected_font_size: Size = config.font.size + Size::new(font_size); - assert_eq!(term.font_size, expected_font_size); - } - - #[test] - fn increase_font_size_works() { - change_font_size_works(10.0); - } - - #[test] - fn decrease_font_size_works() { - change_font_size_works(-10.0); - } - - #[test] - fn prevent_font_below_threshold_works() { - let size = SizeInfo { - width: 21.0, - height: 51.0, - cell_width: 3.0, - cell_height: 3.0, - padding_x: 0.0, - padding_y: 0.0, - dpr: 1.0, - }; - let config: Config = Default::default(); - let mut term: Term = Term::new(&config, size, MessageBuffer::new(), Clipboard::new_nop()); - - term.change_font_size(-100.0); - - let expected_font_size: Size = Size::new(FONT_SIZE_STEP); - assert_eq!(term.font_size, expected_font_size); - } - - #[test] - fn reset_font_size_works() { - let size = SizeInfo { - width: 21.0, - height: 51.0, - cell_width: 3.0, - cell_height: 3.0, - padding_x: 0.0, - padding_y: 0.0, - dpr: 1.0, - }; - let config: Config = Default::default(); - let mut term: Term = Term::new(&config, size, MessageBuffer::new(), Clipboard::new_nop()); - - term.change_font_size(10.0); - term.reset_font_size(); - - let expected_font_size: Size = config.font.size; - assert_eq!(term.font_size, expected_font_size); - } - #[test] fn clear_saved_lines() { let size = SizeInfo { @@ -2444,8 +2288,7 @@ mod tests { padding_y: 0.0, dpr: 1.0, }; - let config: Config = Default::default(); - let mut term: Term = Term::new(&config, size, MessageBuffer::new(), Clipboard::new_nop()); + let mut term = Term::new(&MockConfig::default(), &size, Clipboard::new_nop(), Mock); // Add one line of scrollback term.grid.scroll_up(&(Line(0)..Line(1)), Line(1), &Cell::default()); @@ -2471,13 +2314,18 @@ mod benches { use std::path::Path; use crate::clipboard::Clipboard; - use crate::config::Config; + use crate::config::MockConfig; + use crate::event::{Event, EventListener}; use crate::grid::Grid; - use crate::message_bar::MessageBuffer; use super::cell::Cell; use super::{SizeInfo, Term}; + struct Mock; + impl EventListener for Mock { + fn send_event(&self, _event: Event) {} + } + fn read_string<P>(path: P) -> String where P: AsRef<Path>, @@ -2512,13 +2360,13 @@ mod benches { let mut grid: Grid<Cell> = json::from_str(&serialized_grid).unwrap(); let size: SizeInfo = json::from_str(&serialized_size).unwrap(); - let config = Config::default(); + let config = MockConfig::default(); - let mut terminal = Term::new(&config, size, MessageBuffer::new(), Clipboard::new_nop()); + let mut terminal = Term::new(&config, &size, Clipboard::new_nop(), Mock); mem::swap(&mut terminal.grid, &mut grid); b.iter(|| { - let iter = terminal.renderable_cells(&config, false); + let iter = terminal.renderable_cells(&config); for cell in iter { test::black_box(cell); } |