diff options
author | ii41 <23465321+ii41@users.noreply.github.com> | 2020-09-27 15:36:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-27 22:36:08 +0000 |
commit | a754d06b44139b85e8b34a71ece4477cb1caa85e (patch) | |
tree | 1733f8d17101947b6df5e1ad15b3fd64cf1db9a0 /alacritty/src/message_bar.rs | |
parent | e9c0034f4d3ee003149fe5454942bea7ff3d98be (diff) | |
download | r-alacritty-a754d06b44139b85e8b34a71ece4477cb1caa85e.tar.gz r-alacritty-a754d06b44139b85e8b34a71ece4477cb1caa85e.tar.bz2 r-alacritty-a754d06b44139b85e8b34a71ece4477cb1caa85e.zip |
Add support for single line terminals
This changes the minimum terminal dimensions from 2 lines and 2 columns,
to 1 line and 2 columns.
This also reworks the `SizeInfo` to store the number of columns and
lines and consistently has only the terminal lines/columns stored,
instead of including the message bar and search in some places of the
Alacritty renderer/input.
These new changes also make it easy to properly start the selection
scrolling as soon as the mouse is over the message bar, instead of
waiting until it is beyond it.
Fixes #4207.
Co-authored-by: Christian Duerr <contact@christianduerr.com>
Diffstat (limited to 'alacritty/src/message_bar.rs')
-rw-r--r-- | alacritty/src/message_bar.rs | 107 |
1 files changed, 15 insertions, 92 deletions
diff --git a/alacritty/src/message_bar.rs b/alacritty/src/message_bar.rs index 4c43c3d3..851cb6ee 100644 --- a/alacritty/src/message_bar.rs +++ b/alacritty/src/message_bar.rs @@ -34,7 +34,9 @@ impl Message { /// Formatted message text lines. pub fn text(&self, size_info: &SizeInfo) -> Vec<String> { let num_cols = size_info.cols().0; - let max_lines = size_info.lines().saturating_sub(MIN_FREE_LINES); + let total_lines = + (size_info.height() - 2. * size_info.padding_y()) / size_info.cell_height(); + let max_lines = (total_lines as usize).saturating_sub(MIN_FREE_LINES); let button_len = CLOSE_BUTTON_TEXT.len(); // Split line to fit the screen. @@ -169,7 +171,8 @@ impl MessageBuffer { #[cfg(test)] mod tests { - use super::{Message, MessageBuffer, MessageType, MIN_FREE_LINES}; + use super::*; + use alacritty_terminal::term::SizeInfo; #[test] @@ -177,15 +180,7 @@ mod tests { let input = "a"; let mut message_buffer = MessageBuffer::new(); message_buffer.push(Message::new(input.into(), MessageType::Error)); - let size = SizeInfo { - width: 7., - height: 10., - cell_width: 1., - cell_height: 1., - padding_x: 0., - padding_y: 0., - dpr: 0., - }; + let size = SizeInfo::new(7., 10., 1., 1., 0., 0., false); let lines = message_buffer.message().unwrap().text(&size); @@ -197,15 +192,7 @@ mod tests { let input = "fo\nbar"; let mut message_buffer = MessageBuffer::new(); message_buffer.push(Message::new(input.into(), MessageType::Error)); - let size = SizeInfo { - width: 6., - height: 10., - cell_width: 1., - cell_height: 1., - padding_x: 0., - padding_y: 0., - dpr: 0., - }; + let size = SizeInfo::new(6., 10., 1., 1., 0., 0., false); let lines = message_buffer.message().unwrap().text(&size); @@ -217,15 +204,7 @@ mod tests { let input = "a\nb"; let mut message_buffer = MessageBuffer::new(); message_buffer.push(Message::new(input.into(), MessageType::Error)); - let size = SizeInfo { - width: 6., - height: 10., - cell_width: 1., - cell_height: 1., - padding_x: 0., - padding_y: 0., - dpr: 0., - }; + let size = SizeInfo::new(6., 10., 1., 1., 0., 0., false); let lines = message_buffer.message().unwrap().text(&size); @@ -237,15 +216,7 @@ mod tests { let input = "foobar1"; let mut message_buffer = MessageBuffer::new(); message_buffer.push(Message::new(input.into(), MessageType::Error)); - let size = SizeInfo { - width: 6., - height: 10., - cell_width: 1., - cell_height: 1., - padding_x: 0., - padding_y: 0., - dpr: 0., - }; + let size = SizeInfo::new(6., 10., 1., 1., 0., 0., false); let lines = message_buffer.message().unwrap().text(&size); @@ -257,15 +228,7 @@ mod tests { let input = "foobar"; let mut message_buffer = MessageBuffer::new(); message_buffer.push(Message::new(input.into(), MessageType::Error)); - let size = SizeInfo { - width: 6., - height: 0., - cell_width: 1., - cell_height: 1., - padding_x: 0., - padding_y: 0., - dpr: 0., - }; + let size = SizeInfo::new(6., 0., 1., 1., 0., 0., false); let lines = message_buffer.message().unwrap().text(&size); @@ -277,15 +240,7 @@ mod tests { let input = "hahahahahahahahahahaha truncate this because it's too long for the term"; let mut message_buffer = MessageBuffer::new(); message_buffer.push(Message::new(input.into(), MessageType::Error)); - let size = SizeInfo { - width: 22., - height: (MIN_FREE_LINES + 2) as f32, - cell_width: 1., - cell_height: 1., - padding_x: 0., - padding_y: 0., - dpr: 0., - }; + let size = SizeInfo::new(22., (MIN_FREE_LINES + 2) as f32, 1., 1., 0., 0., false); let lines = message_buffer.message().unwrap().text(&size); @@ -300,15 +255,7 @@ mod tests { let input = "ha"; let mut message_buffer = MessageBuffer::new(); message_buffer.push(Message::new(input.into(), MessageType::Error)); - let size = SizeInfo { - width: 2., - height: 10., - cell_width: 1., - cell_height: 1., - padding_x: 0., - padding_y: 0., - dpr: 0., - }; + let size = SizeInfo::new(2., 10., 1., 1., 0., 0., false); let lines = message_buffer.message().unwrap().text(&size); @@ -320,15 +267,7 @@ mod tests { let input = "hahahahahahahahaha"; let mut message_buffer = MessageBuffer::new(); message_buffer.push(Message::new(input.into(), MessageType::Error)); - let size = SizeInfo { - width: 2., - height: (MIN_FREE_LINES + 2) as f32, - cell_width: 1., - cell_height: 1., - padding_x: 0., - padding_y: 0., - dpr: 0., - }; + let size = SizeInfo::new(2., (MIN_FREE_LINES + 2) as f32, 1., 1., 0., 0., false); let lines = message_buffer.message().unwrap().text(&size); @@ -340,15 +279,7 @@ mod tests { let input = "test"; let mut message_buffer = MessageBuffer::new(); message_buffer.push(Message::new(input.into(), MessageType::Error)); - let size = SizeInfo { - width: 5., - height: 10., - cell_width: 1., - cell_height: 1., - padding_x: 0., - padding_y: 0., - dpr: 0., - }; + let size = SizeInfo::new(5., 10., 1., 1., 0., 0., false); let lines = message_buffer.message().unwrap().text(&size); @@ -398,15 +329,7 @@ mod tests { let input = "a\nbc defg"; let mut message_buffer = MessageBuffer::new(); message_buffer.push(Message::new(input.into(), MessageType::Error)); - let size = SizeInfo { - width: 5., - height: 10., - cell_width: 1., - cell_height: 1., - padding_x: 0., - padding_y: 0., - dpr: 0., - }; + let size = SizeInfo::new(5., 10., 1., 1., 0., 0., false); let lines = message_buffer.message().unwrap().text(&size); |