aboutsummaryrefslogtreecommitdiffstats
path: root/src/panes
diff options
context:
space:
mode:
authorBrooks J Rady <b.j.rady@gmail.com>2021-01-06 19:34:18 +0000
committerBrooks J Rady <b.j.rady@gmail.com>2021-01-06 19:34:18 +0000
commit1fa23e6fa4635a61a64ab0f53da1455c72b405d8 (patch)
tree789be804ce4bdae3f9da02bdabea7322c6179bdb /src/panes
parentA module rename to please clippy (diff)
downloadsl0ppij-1fa23e6fa4635a61a64ab0f53da1455c72b405d8.tar.gz
sl0ppij-1fa23e6fa4635a61a64ab0f53da1455c72b405d8.tar.xz
sl0ppij-1fa23e6fa4635a61a64ab0f53da1455c72b405d8.zip
Get clipped, fool
Diffstat (limited to 'src/panes')
-rw-r--r--src/panes/scroll.rs33
-rw-r--r--src/panes/terminal_character.rs11
-rw-r--r--src/panes/terminal_pane.rs15
3 files changed, 27 insertions, 32 deletions
diff --git a/src/panes/scroll.rs b/src/panes/scroll.rs
index 05252b03..2dedd1e7 100644
--- a/src/panes/scroll.rs
+++ b/src/panes/scroll.rs
@@ -1,5 +1,8 @@
use std::collections::VecDeque;
-use std::fmt::{self, Debug, Formatter};
+use std::{
+ cmp::max,
+ fmt::{self, Debug, Formatter},
+};
use crate::panes::terminal_character::{
CharacterStyles, TerminalCharacter, EMPTY_TERMINAL_CHARACTER,
@@ -341,10 +344,8 @@ impl Scroll {
if lines_to_skip > 0 {
lines_to_skip -= 1;
} else {
- for _ in line.len()..self.total_columns {
- // pad line if needed
- line.push(EMPTY_TERMINAL_CHARACTER);
- }
+ // pad line if needed
+ line.resize(self.total_columns, EMPTY_TERMINAL_CHARACTER);
lines.push_front(line);
}
if lines.len() == self.lines_in_view {
@@ -477,9 +478,14 @@ impl Scroll {
count
};
- for _ in current_fragment.characters.len()..current_cursor_column_position + move_count {
- current_fragment.characters.push(EMPTY_TERMINAL_CHARACTER);
- }
+ current_fragment.characters.resize(
+ max(
+ current_fragment.characters.len(),
+ current_cursor_column_position + move_count,
+ ),
+ EMPTY_TERMINAL_CHARACTER,
+ );
+
self.cursor_position.move_forward(move_count);
}
pub fn move_cursor_back(&mut self, count: usize) {
@@ -645,9 +651,10 @@ impl Scroll {
.get_mut(current_line_wrap_position)
.expect("cursor out of bounds");
- for _ in current_fragment.characters.len()..col {
- current_fragment.characters.push(EMPTY_TERMINAL_CHARACTER);
- }
+ current_fragment.characters.resize(
+ max(current_fragment.characters.len(), col),
+ EMPTY_TERMINAL_CHARACTER,
+ );
self.cursor_position.move_to_column(col);
}
pub fn move_cursor_to_column(&mut self, col: usize) {
@@ -680,9 +687,7 @@ impl Scroll {
self.scroll_region = None;
}
fn scroll_region_absolute_indices(&mut self) -> Option<(usize, usize)> {
- if self.scroll_region.is_none() {
- return None;
- };
+ self.scroll_region?;
if self.canonical_lines.len() > self.lines_in_view {
let absolute_top = self.canonical_lines.len() - 1 - self.lines_in_view;
let absolute_bottom = self.canonical_lines.len() - 1;
diff --git a/src/panes/terminal_character.rs b/src/panes/terminal_character.rs
index 28d638f9..80c3162b 100644
--- a/src/panes/terminal_character.rs
+++ b/src/panes/terminal_character.rs
@@ -390,7 +390,7 @@ impl CharacterStyles {
}
}
if let Some(next_params) = ansi_params.get(params_used..) {
- if next_params.len() > 0 {
+ if !next_params.is_empty() {
self.add_style_from_ansi_params(next_params);
}
}
@@ -536,14 +536,9 @@ impl Display for CharacterStyles {
write!(f, "\u{1b}[2m")?;
}
AnsiCode::Reset => {
- if let Some(bold) = self.bold {
+ if let Some(AnsiCode::Reset) = self.bold {
// we only reset dim if both dim and bold should be reset
- match bold {
- AnsiCode::Reset => {
- write!(f, "\u{1b}[22m")?;
- }
- _ => {}
- }
+ write!(f, "\u{1b}[22m")?;
}
}
_ => {}
diff --git a/src/panes/terminal_pane.rs b/src/panes/terminal_pane.rs
index 70eb216a..6bd39a3f 100644
--- a/src/panes/terminal_pane.rs
+++ b/src/panes/terminal_pane.rs
@@ -442,12 +442,10 @@ impl vte::Perform for TerminalPane {
} else {
(params[0] as usize - 1, params[0] as usize)
}
+ } else if params[0] == 0 {
+ (0, params[1] as usize - 1)
} else {
- if params[0] == 0 {
- (0, params[1] as usize - 1)
- } else {
- (params[0] as usize - 1, params[1] as usize - 1)
- }
+ (params[0] as usize - 1, params[1] as usize - 1)
};
self.scroll.move_cursor_to(row, col);
} else if c == 'A' {
@@ -607,11 +605,8 @@ impl vte::Perform for TerminalPane {
}
fn esc_dispatch(&mut self, intermediates: &[u8], _ignore: bool, byte: u8) {
- match (byte, intermediates.get(0)) {
- (b'M', None) => {
- self.scroll.move_cursor_up_in_scroll_region(1);
- }
- _ => {}
+ if let (b'M', None) = (byte, intermediates.get(0)) {
+ self.scroll.move_cursor_up_in_scroll_region(1);
}
}
}