aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrooks J Rady <b.j.rady@gmail.com>2021-01-12 05:50:59 +0000
committerBrooks J Rady <b.j.rady@gmail.com>2021-01-12 05:50:59 +0000
commit7d9a33e13eaf0c4ce78b95eecba962ecc3481119 (patch)
treefec6cc79775bce42cee32096f6cb571f27f0086f
parentMerge branch 'main' into wasm-status-bar (diff)
downloadsl0ppij-7d9a33e13eaf0c4ce78b95eecba962ecc3481119.tar.gz
sl0ppij-7d9a33e13eaf0c4ce78b95eecba962ecc3481119.tar.xz
sl0ppij-7d9a33e13eaf0c4ce78b95eecba962ecc3481119.zip
Fixed 23 clippy lints and warnings
-rw-r--r--src/panes/grid.rs151
-rw-r--r--src/panes/terminal_pane.rs82
2 files changed, 84 insertions, 149 deletions
diff --git a/src/panes/grid.rs b/src/panes/grid.rs
index 27dd462c..e00b6c73 100644
--- a/src/panes/grid.rs
+++ b/src/panes/grid.rs
@@ -1,4 +1,7 @@
-use std::fmt::{self, Debug, Formatter};
+use std::{
+ cmp::Ordering,
+ fmt::{self, Debug, Formatter},
+};
use crate::panes::terminal_character::{
CharacterStyles, TerminalCharacter, EMPTY_TERMINAL_CHARACTER,
@@ -97,7 +100,7 @@ fn transfer_rows_up(
let mut next_lines: Vec<Row> = vec![];
for _ in 0..count {
if next_lines.is_empty() {
- if source.len() > 0 {
+ if !source.is_empty() {
let next_line = source.remove(0);
if !next_line.is_canonical {
let mut bottom_canonical_row_and_wraps_in_dst =
@@ -214,7 +217,7 @@ impl Grid {
y_coordinates
}
pub fn scroll_up_one_line(&mut self) {
- if self.lines_above.len() > 0 && self.viewport.len() == self.height {
+ if !self.lines_above.is_empty() && self.viewport.len() == self.height {
let line_to_push_down = self.viewport.pop().unwrap();
self.lines_below.insert(0, line_to_push_down);
let line_to_insert_at_viewport_top = self.lines_above.pop().unwrap();
@@ -222,7 +225,7 @@ impl Grid {
}
}
pub fn scroll_down_one_line(&mut self) {
- if self.lines_below.len() > 0 && self.viewport.len() == self.height {
+ if !self.lines_below.is_empty() && self.viewport.len() == self.height {
let mut line_to_push_up = self.viewport.remove(0);
if line_to_push_up.is_canonical {
self.lines_above.push(line_to_push_up);
@@ -243,7 +246,7 @@ impl Grid {
for mut row in self.viewport.drain(..) {
if !row.is_canonical
&& viewport_canonical_lines.is_empty()
- && self.lines_above.len() > 0
+ && !self.lines_above.is_empty()
{
let mut first_line_above = self.lines_above.pop().unwrap();
first_line_above.append(&mut row.columns);
@@ -269,7 +272,7 @@ impl Grid {
let mut new_viewport_rows = vec![];
for mut canonical_line in viewport_canonical_lines {
let mut canonical_line_parts: Vec<Row> = vec![];
- while canonical_line.columns.len() > 0 {
+ while !canonical_line.columns.is_empty() {
let next_wrap = if canonical_line.len() > new_columns {
canonical_line.columns.drain(..new_columns)
} else {
@@ -279,7 +282,7 @@ impl Grid {
// if there are no more parts, this row is canonical as long as it originall
// was canonical (it might not have been for example if it's the first row in
// the viewport, and the actual canonical row is above it in the scrollback)
- let row = if canonical_line_parts.len() == 0 && canonical_line.is_canonical {
+ let row = if canonical_line_parts.is_empty() && canonical_line.is_canonical {
row.canonical()
} else {
row
@@ -294,62 +297,70 @@ impl Grid {
let new_cursor_x = (cursor_index_in_canonical_line / new_columns)
+ (cursor_index_in_canonical_line % new_columns);
let current_viewport_row_count = self.viewport.len();
- if current_viewport_row_count < self.height {
- let row_count_to_transfer = self.height - current_viewport_row_count;
- transfer_rows_down(
- &mut self.lines_above,
- &mut self.viewport,
- row_count_to_transfer,
- None,
- Some(new_columns),
- );
- let rows_pulled = self.viewport.len() - current_viewport_row_count;
- new_cursor_y += rows_pulled;
- } else if current_viewport_row_count > self.height {
- let row_count_to_transfer = current_viewport_row_count - self.height;
- if row_count_to_transfer > new_cursor_y {
- new_cursor_y = 0;
- } else {
- new_cursor_y -= row_count_to_transfer;
+ match current_viewport_row_count.cmp(&self.height) {
+ Ordering::Less => {
+ let row_count_to_transfer = self.height - current_viewport_row_count;
+ transfer_rows_down(
+ &mut self.lines_above,
+ &mut self.viewport,
+ row_count_to_transfer,
+ None,
+ Some(new_columns),
+ );
+ let rows_pulled = self.viewport.len() - current_viewport_row_count;
+ new_cursor_y += rows_pulled;
}
- transfer_rows_up(
- &mut self.viewport,
- &mut self.lines_above,
- row_count_to_transfer,
- Some(new_columns),
- None,
- );
+ Ordering::Greater => {
+ let row_count_to_transfer = current_viewport_row_count - self.height;
+ if row_count_to_transfer > new_cursor_y {
+ new_cursor_y = 0;
+ } else {
+ new_cursor_y -= row_count_to_transfer;
+ }
+ transfer_rows_up(
+ &mut self.viewport,
+ &mut self.lines_above,
+ row_count_to_transfer,
+ Some(new_columns),
+ None,
+ );
+ }
+ Ordering::Equal => {}
}
self.cursor.y = new_cursor_y;
self.cursor.x = new_cursor_x;
}
if new_rows != self.height {
let current_viewport_row_count = self.viewport.len();
- if current_viewport_row_count < new_rows {
- let row_count_to_transfer = new_rows - current_viewport_row_count;
- transfer_rows_down(
- &mut self.lines_above,
- &mut self.viewport,
- row_count_to_transfer,
- None,
- Some(new_columns),
- );
- let rows_pulled = self.viewport.len() - current_viewport_row_count;
- self.cursor.y += rows_pulled;
- } else if current_viewport_row_count > new_rows {
- let row_count_to_transfer = current_viewport_row_count - new_rows;
- if row_count_to_transfer > self.cursor.y {
- self.cursor.y = 0;
- } else {
- self.cursor.y -= row_count_to_transfer;
+ match current_viewport_row_count.cmp(&new_rows) {
+ Ordering::Less => {
+ let row_count_to_transfer = new_rows - current_viewport_row_count;
+ transfer_rows_down(
+ &mut self.lines_above,
+ &mut self.viewport,
+ row_count_to_transfer,
+ None,
+ Some(new_columns),
+ );
+ let rows_pulled = self.viewport.len() - current_viewport_row_count;
+ self.cursor.y += rows_pulled;
}
- transfer_rows_up(
- &mut self.viewport,
- &mut self.lines_above,
- row_count_to_transfer,
- Some(new_columns),
- None,
- );
+ Ordering::Greater => {
+ let row_count_to_transfer = current_viewport_row_count - new_rows;
+ if row_count_to_transfer > self.cursor.y {
+ self.cursor.y = 0;
+ } else {
+ self.cursor.y -= row_count_to_transfer;
+ }
+ transfer_rows_up(
+ &mut self.viewport,
+ &mut self.lines_above,
+ row_count_to_transfer,
+ Some(new_columns),
+ None,
+ );
+ }
+ Ordering::Equal => {}
}
}
self.height = new_rows;
@@ -364,10 +375,8 @@ impl Grid {
.iter()
.map(|r| {
let mut line: Vec<TerminalCharacter> = r.columns.iter().copied().collect();
- for _ in line.len()..self.width {
- // pad line
- line.push(EMPTY_TERMINAL_CHARACTER);
- }
+ // pad line
+ line.resize(self.width, EMPTY_TERMINAL_CHARACTER);
line
})
.collect();
@@ -719,17 +728,17 @@ impl Row {
self
}
pub fn add_character_at(&mut self, terminal_character: TerminalCharacter, x: usize) {
- if x == self.columns.len() {
- self.columns.push(terminal_character);
- } else if x > self.columns.len() {
- for _ in self.columns.len()..x {
- self.columns.push(EMPTY_TERMINAL_CHARACTER);
+ match self.columns.len().cmp(&x) {
+ Ordering::Equal => self.columns.push(terminal_character),
+ Ordering::Less => {
+ self.columns.resize(x, EMPTY_TERMINAL_CHARACTER);
+ self.columns.push(terminal_character);
+ }
+ Ordering::Greater => {
+ // this is much more performant than remove/insert
+ self.columns.push(terminal_character);
+ self.columns.swap_remove(x);
}
- self.columns.push(terminal_character);
- } else {
- // this is much more performant than remove/insert
- self.columns.push(terminal_character);
- self.columns.swap_remove(x);
}
}
pub fn replace_character_at(&mut self, terminal_character: TerminalCharacter, x: usize) {
@@ -767,10 +776,10 @@ impl Row {
}
current_part.push(character);
}
- if current_part.len() > 0 {
+ if !current_part.is_empty() {
parts.push(Row::from_columns(current_part))
};
- if parts.len() > 0 && self.is_canonical {
+ if !parts.is_empty() && self.is_canonical {
parts.get_mut(0).unwrap().is_canonical = true;
}
parts
diff --git a/src/panes/terminal_pane.rs b/src/panes/terminal_pane.rs
index 6b78b647..b9369fea 100644
--- a/src/panes/terminal_pane.rs
+++ b/src/panes/terminal_pane.rs
@@ -4,10 +4,9 @@ use crate::tab::Pane;
use ::nix::pty::Winsize;
use ::std::os::unix::io::RawFd;
use ::vte::Perform;
-use std::fmt::{self, Debug, Formatter};
+use std::fmt::Debug;
-use crate::boundaries::Rect;
-use crate::panes::grid::{Grid, Row};
+use crate::panes::grid::Grid;
use crate::panes::terminal_character::{
CharacterStyles, TerminalCharacter, EMPTY_TERMINAL_CHARACTER,
};
@@ -338,14 +337,6 @@ impl TerminalPane {
// (x, y)
self.grid.cursor_coordinates()
}
- pub fn scroll_up(&mut self, count: usize) {
- self.grid.move_viewport_up(count);
- self.mark_for_rerender();
- }
- pub fn scroll_down(&mut self, count: usize) {
- self.grid.move_viewport_down(count);
- self.mark_for_rerender();
- }
pub fn rotate_scroll_region_up(&mut self, count: usize) {
self.grid.rotate_scroll_region_up(count);
self.mark_for_rerender();
@@ -354,68 +345,6 @@ impl TerminalPane {
self.grid.rotate_scroll_region_down(count);
self.mark_for_rerender();
}
- pub fn clear_scroll(&mut self) {
- self.grid.reset_viewport();
- self.mark_for_rerender();
- }
- pub fn override_size_and_position(&mut self, x: usize, y: usize, size: &PositionAndSize) {
- let position_and_size_override = PositionAndSize {
- x,
- y,
- rows: size.rows,
- columns: size.columns,
- };
- self.position_and_size_override = Some(position_and_size_override);
- self.reflow_lines();
- self.mark_for_rerender();
- }
- pub fn reset_size_and_position_override(&mut self) {
- self.position_and_size_override = None;
- self.reflow_lines();
- self.mark_for_rerender();
- }
- pub fn adjust_input_to_terminal(&self, input_bytes: Vec<u8>) -> Vec<u8> {
- // there are some cases in which the terminal state means that input sent to it
- // needs to be adjusted.
- // here we match against those cases - if need be, we adjust the input and if not
- // we send back the original input
- match input_bytes.as_slice() {
- [27, 91, 68] => {
- // left arrow
- if self.cursor_key_mode {
- // please note that in the line below, there is an ANSI escape code (27) at the beginning of the string,
- // some editors will not show this
- return "OD".as_bytes().to_vec();
- }
- }
- [27, 91, 67] => {
- // right arrow
- if self.cursor_key_mode {
- // please note that in the line below, there is an ANSI escape code (27) at the beginning of the string,
- // some editors will not show this
- return "OC".as_bytes().to_vec();
- }
- }
- [27, 91, 65] => {
- // up arrow
- if self.cursor_key_mode {
- // please note that in the line below, there is an ANSI escape code (27) at the beginning of the string,
- // some editors will not show this
- return "OA".as_bytes().to_vec();
- }
- }
- [27, 91, 66] => {
- // down arrow
- if self.cursor_key_mode {
- // please note that in the line below, there is an ANSI escape code (27) at the beginning of the string,
- // some editors will not show this
- return "OB".as_bytes().to_vec();
- }
- }
- _ => {}
- };
- input_bytes
- }
fn add_newline(&mut self) {
self.grid.add_canonical_line();
// self.reset_all_ansi_codes(); // TODO: find out if we should be resetting here or not
@@ -706,11 +635,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.grid.move_cursor_up_with_scrolling(1);
- }
- _ => {}
+ if let (b'M', None) = (byte, intermediates.get(0)) {
+ self.grid.move_cursor_up_with_scrolling(1);
}
}
}