Fix drawing getting stuck in empty terminal

Fix drawing getting stuck in loops when terminal is too small by
checking for it.
master
Manos Pitsidianakis 2020-02-06 21:49:21 +02:00
parent 4301fa3b04
commit f131e01bfc
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
7 changed files with 23 additions and 25 deletions

View File

@ -71,10 +71,16 @@ pub trait TextProcessing: UnicodeSegmentation + CodePointsIter {
impl TextProcessing for str { impl TextProcessing for str {
fn split_lines(&self, width: usize) -> Vec<String> { fn split_lines(&self, width: usize) -> Vec<String> {
if width == 0 {
return vec![];
}
super::line_break::linear(self, width) super::line_break::linear(self, width)
} }
fn split_lines_reflow(&self, reflow: Reflow, width: Option<usize>) -> Vec<String> { fn split_lines_reflow(&self, reflow: Reflow, width: Option<usize>) -> Vec<String> {
if width == Some(0) {
return vec![];
}
super::line_break::split_lines_reflow(self, reflow, width) super::line_break::split_lines_reflow(self, reflow, width)
} }
} }

View File

@ -1023,6 +1023,9 @@ pub fn split_lines_reflow(text: &str, reflow: Reflow, width: Option<usize>) -> V
ret.push(format!("{}", &line[prev_line_offset..end_offset])); ret.push(format!("{}", &line[prev_line_offset..end_offset]));
} }
} }
if prev_line_offset == end_offset && prev == new_off {
break;
}
prev_line_offset = end_offset; prev_line_offset = end_offset;
prev = new_off; prev = new_off;
} }

View File

@ -294,6 +294,9 @@ impl ListingTrait for CompactListing {
return; return;
} }
let rows = get_y(bottom_right) - get_y(upper_left) + 1; let rows = get_y(bottom_right) - get_y(upper_left) + 1;
if rows == 0 {
return;
}
if let Some(mvm) = self.movement.take() { if let Some(mvm) = self.movement.take() {
match mvm { match mvm {

View File

@ -295,6 +295,9 @@ impl ListingTrait for ConversationsListing {
return; return;
} }
let rows = (get_y(bottom_right) - get_y(upper_left) + 1) / 3; let rows = (get_y(bottom_right) - get_y(upper_left) + 1) / 3;
if rows == 0 {
return;
}
let pad = (get_y(bottom_right) - get_y(upper_left) + 1) % 3; let pad = (get_y(bottom_right) - get_y(upper_left) + 1) % 3;
if let Some(mvm) = self.movement.take() { if let Some(mvm) = self.movement.take() {

View File

@ -300,6 +300,9 @@ impl ListingTrait for PlainListing {
return; return;
} }
let rows = get_y(bottom_right) - get_y(upper_left) + 1; let rows = get_y(bottom_right) - get_y(upper_left) + 1;
if rows == 0 {
return;
}
if let Some(mvm) = self.movement.take() { if let Some(mvm) = self.movement.take() {
match mvm { match mvm {

View File

@ -225,6 +225,9 @@ impl ListingTrait for ThreadListing {
return; return;
} }
let rows = get_y(bottom_right) - get_y(upper_left) + 1; let rows = get_y(bottom_right) - get_y(upper_left) + 1;
if rows == 0 {
return;
}
if let Some(mvm) = self.movement.take() { if let Some(mvm) = self.movement.take() {
match mvm { match mvm {
PageMovement::Up(amount) => { PageMovement::Up(amount) => {

View File

@ -57,12 +57,8 @@ pub fn pos_dec(p: Pos, dec: (usize, usize)) -> Pos {
/// An `Area` consists of two points: the upper left and bottom right corners. /// An `Area` consists of two points: the upper left and bottom right corners.
/// ///
/// Example: /// Example:
/// ``` /// ```no_run
/// # #[macro_use] extern crate ui; fn main() {
/// use ui::*;
///
/// let new_area = ((0, 0), (1, 1)); /// let new_area = ((0, 0), (1, 1));
/// # }
/// ``` /// ```
pub type Area = (Pos, Pos); pub type Area = (Pos, Pos);
@ -70,12 +66,8 @@ pub type Area = (Pos, Pos);
/// ///
/// Example: /// Example:
/// ``` /// ```
/// # #[macro_use] extern crate ui; fn main() {
/// use ui::*;
///
/// let new_area = ((0, 0), (1, 1)); /// let new_area = ((0, 0), (1, 1));
/// assert_eq!(height!(new_area), 1); /// assert_eq!(height!(new_area), 1);
/// # }
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! height { macro_rules! height {
@ -88,12 +80,8 @@ macro_rules! height {
/// ///
/// Example: /// Example:
/// ``` /// ```
/// # #[macro_use] extern crate ui; fn main() {
/// use ui::*;
///
/// let new_area = ((0, 0), (1, 1)); /// let new_area = ((0, 0), (1, 1));
/// assert_eq!(width!(new_area), 1); /// assert_eq!(width!(new_area), 1);
/// # }
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! width { macro_rules! width {
@ -106,12 +94,8 @@ macro_rules! width {
/// ///
/// Example: /// Example:
/// ``` /// ```
/// # #[macro_use] extern crate ui; fn main() {
/// use ui::*;
///
/// let new_area = ((0, 0), (1, 1)); /// let new_area = ((0, 0), (1, 1));
/// assert_eq!(upper_left!(new_area), (0, 0)); /// assert_eq!(upper_left!(new_area), (0, 0));
/// # }
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! upper_left { macro_rules! upper_left {
@ -124,12 +108,8 @@ macro_rules! upper_left {
/// ///
/// Example: /// Example:
/// ``` /// ```
/// # #[macro_use] extern crate ui; fn main() {
/// use ui::*;
///
/// let new_area = ((0, 0), (1, 1)); /// let new_area = ((0, 0), (1, 1));
/// assert_eq!(bottom_right!(new_area), (1, 1)); /// assert_eq!(bottom_right!(new_area), (1, 1));
/// # }
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! bottom_right { macro_rules! bottom_right {
@ -142,15 +122,12 @@ macro_rules! bottom_right {
/// ///
/// Example: /// Example:
/// ``` /// ```
/// # #[macro_use] extern crate ui; fn main() {
/// use ui::*;
///
/// let valid_area = ((0, 0), (1, 1)); /// let valid_area = ((0, 0), (1, 1));
/// assert!(is_valid_area!(valid_area)); /// assert!(is_valid_area!(valid_area));
/// ///
/// let invalid_area = ((2, 2), (1, 1)); /// let invalid_area = ((2, 2), (1, 1));
/// assert!(!is_valid_area!(invalid_area)); /// assert!(!is_valid_area!(invalid_area));
/// # } /// ```
/// ///
#[macro_export] #[macro_export]
macro_rules! is_valid_area { macro_rules! is_valid_area {