Skip to content

Commit 846fda7

Browse files
committed
refactor: Remove Copy impl on TerminalCharacter
1 parent b9d957e commit 846fda7

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

zellij-server/src/output/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,8 +815,8 @@ impl CharacterChunk {
815815
}
816816
let next_character = self.terminal_characters.remove(0); // TODO: consider copying self.terminal_characters into a VecDeque to make this process faster?
817817
if drained_part_len + next_character.width() <= x {
818-
drained_part.push_back(next_character);
819818
drained_part_len += next_character.width();
819+
drained_part.push_back(next_character);
820820
} else {
821821
if drained_part_len == x {
822822
self.terminal_characters.insert(0, next_character); // put it back
@@ -963,7 +963,7 @@ impl OutputBuffer {
963963
row: &Row,
964964
viewport_width: usize,
965965
) -> Vec<TerminalCharacter> {
966-
let mut terminal_characters: Vec<TerminalCharacter> = row.columns.iter().copied().collect();
966+
let mut terminal_characters: Vec<TerminalCharacter> = row.columns.iter().cloned().collect();
967967
// pad row
968968
let row_width = row.width();
969969
if row_width < viewport_width {

zellij-server/src/panes/grid.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ impl Grid {
987987
.iter()
988988
.map(|r| {
989989
let excess_width = r.excess_width();
990-
let mut line: Vec<TerminalCharacter> = r.columns.iter().copied().collect();
990+
let mut line: Vec<TerminalCharacter> = r.columns.iter().cloned().collect();
991991
// pad line
992992
line.resize(
993993
self.width.saturating_sub(excess_width),
@@ -1205,7 +1205,7 @@ impl Grid {
12051205
pad_character.styles = self.cursor.pending_styles;
12061206
for _ in 0..count {
12071207
self.viewport.remove(scroll_region_top);
1208-
let columns = VecDeque::from(vec![pad_character; self.width]);
1208+
let columns = VecDeque::from(vec![pad_character.clone(); self.width]);
12091209
self.viewport
12101210
.insert(scroll_region_bottom, Row::from_columns(columns).canonical());
12111211
}
@@ -1220,7 +1220,7 @@ impl Grid {
12201220
};
12211221

12221222
for _ in 0..self.height {
1223-
let columns = VecDeque::from(vec![character; self.width]);
1223+
let columns = VecDeque::from(vec![character.clone(); self.width]);
12241224
self.viewport.push(Row::from_columns(columns).canonical());
12251225
}
12261226
self.output_buffer.update_all_lines();
@@ -1367,7 +1367,7 @@ impl Grid {
13671367
self.viewport
13681368
.get(self.cursor.y)
13691369
.and_then(|current_line| current_line.columns.get(absolute_x_in_line))
1370-
.copied()
1370+
.cloned()
13711371
}
13721372
pub fn get_absolute_character_index(&self, x: usize, y: usize) -> usize {
13731373
self.viewport.get(y).unwrap().absolute_character_index(x)
@@ -1390,7 +1390,7 @@ impl Grid {
13901390
pub fn clear_all_after_cursor(&mut self, replace_with: TerminalCharacter) {
13911391
if let Some(cursor_row) = self.viewport.get_mut(self.cursor.y) {
13921392
cursor_row.truncate(self.cursor.x);
1393-
let replace_with_columns = VecDeque::from(vec![replace_with; self.width]);
1393+
let replace_with_columns = VecDeque::from(vec![replace_with.clone(); self.width]);
13941394
self.replace_characters_in_line_after_cursor(replace_with);
13951395
for row in self.viewport.iter_mut().skip(self.cursor.y + 1) {
13961396
row.replace_columns(replace_with_columns.clone());
@@ -1400,8 +1400,8 @@ impl Grid {
14001400
}
14011401
pub fn clear_all_before_cursor(&mut self, replace_with: TerminalCharacter) {
14021402
if self.viewport.get(self.cursor.y).is_some() {
1403+
let replace_with_columns = VecDeque::from(vec![replace_with.clone(); self.width]);
14031404
self.replace_characters_in_line_before_cursor(replace_with);
1404-
let replace_with_columns = VecDeque::from(vec![replace_with; self.width]);
14051405
for row in self.viewport.iter_mut().take(self.cursor.y) {
14061406
row.replace_columns(replace_with_columns.clone());
14071407
}
@@ -1415,7 +1415,7 @@ impl Grid {
14151415
}
14161416
}
14171417
pub fn clear_all(&mut self, replace_with: TerminalCharacter) {
1418-
let replace_with_columns = VecDeque::from(vec![replace_with; self.width]);
1418+
let replace_with_columns = VecDeque::from(vec![replace_with.clone(); self.width]);
14191419
self.replace_characters_in_line_after_cursor(replace_with);
14201420
for row in &mut self.viewport {
14211421
row.replace_columns(replace_with_columns.clone());
@@ -1450,18 +1450,18 @@ impl Grid {
14501450

14511451
fn pad_current_line_until(&mut self, position: usize, pad_character: TerminalCharacter) {
14521452
if self.viewport.get(self.cursor.y).is_none() {
1453-
self.pad_lines_until(self.cursor.y, pad_character);
1453+
self.pad_lines_until(self.cursor.y, pad_character.clone());
14541454
}
14551455
if let Some(current_row) = self.viewport.get_mut(self.cursor.y) {
14561456
for _ in current_row.width()..position {
1457-
current_row.push(pad_character);
1457+
current_row.push(pad_character.clone());
14581458
}
14591459
self.output_buffer.update_line(self.cursor.y);
14601460
}
14611461
}
14621462
fn pad_lines_until(&mut self, position: usize, pad_character: TerminalCharacter) {
14631463
for _ in self.viewport.len()..=position {
1464-
let columns = VecDeque::from(vec![pad_character; self.width]);
1464+
let columns = VecDeque::from(vec![pad_character.clone(); self.width]);
14651465
self.viewport.push(Row::from_columns(columns).canonical());
14661466
self.output_buffer.update_line(self.viewport.len() - 1);
14671467
}
@@ -1480,13 +1480,13 @@ impl Grid {
14801480
} else {
14811481
self.cursor.y = std::cmp::min(self.height - 1, y + y_offset);
14821482
}
1483-
self.pad_lines_until(self.cursor.y, pad_character);
1483+
self.pad_lines_until(self.cursor.y, pad_character.clone());
14841484
self.pad_current_line_until(self.cursor.x, pad_character);
14851485
},
14861486
None => {
14871487
self.cursor.x = std::cmp::min(self.width - 1, x);
14881488
self.cursor.y = std::cmp::min(self.height - 1, y);
1489-
self.pad_lines_until(self.cursor.y, pad_character);
1489+
self.pad_lines_until(self.cursor.y, pad_character.clone());
14901490
self.pad_current_line_until(self.cursor.x, pad_character);
14911491
},
14921492
}
@@ -1586,7 +1586,7 @@ impl Grid {
15861586
// region
15871587
for _ in 0..count {
15881588
self.viewport.remove(current_line_index);
1589-
let columns = VecDeque::from(vec![pad_character; self.width]);
1589+
let columns = VecDeque::from(vec![pad_character.clone(); self.width]);
15901590
if self.viewport.len() > scroll_region_bottom {
15911591
self.viewport
15921592
.insert(scroll_region_bottom, Row::from_columns(columns).canonical());
@@ -1615,7 +1615,7 @@ impl Grid {
16151615
if scroll_region_bottom < self.viewport.len() {
16161616
self.viewport.remove(scroll_region_bottom);
16171617
}
1618-
let columns = VecDeque::from(vec![pad_character; self.width]);
1618+
let columns = VecDeque::from(vec![pad_character.clone(); self.width]);
16191619
self.viewport
16201620
.insert(current_line_index, Row::from_columns(columns).canonical());
16211621
}
@@ -1638,10 +1638,10 @@ impl Grid {
16381638
let mut empty_character = EMPTY_TERMINAL_CHARACTER;
16391639
empty_character.styles = empty_char_style;
16401640
let pad_until = std::cmp::min(self.width, self.cursor.x + count);
1641-
self.pad_current_line_until(pad_until, empty_character);
1641+
self.pad_current_line_until(pad_until, empty_character.clone());
16421642
if let Some(current_row) = self.viewport.get_mut(self.cursor.y) {
16431643
for i in 0..count {
1644-
current_row.replace_character_at(empty_character, self.cursor.x + i);
1644+
current_row.replace_character_at(empty_character.clone(), self.cursor.x + i);
16451645
}
16461646
self.output_buffer.update_line(self.cursor.y);
16471647
}
@@ -1664,9 +1664,9 @@ impl Grid {
16641664
.unwrap_or(0)
16651665
.saturating_sub(1);
16661666
for _ in 0..excess_width {
1667-
current_row.insert_character_at(empty_character, self.cursor.x);
1667+
current_row.insert_character_at(empty_character.clone(), self.cursor.x);
16681668
}
1669-
current_row.push(empty_character);
1669+
current_row.push(empty_character.clone());
16701670
}
16711671
self.output_buffer.update_line(self.cursor.y);
16721672
}
@@ -2145,7 +2145,7 @@ impl Perform for Grid {
21452145
let c = self.cursor.charsets[self.active_charset].map(c);
21462146

21472147
let terminal_character = TerminalCharacter::new_styled(c, self.cursor.pending_styles);
2148-
self.set_preceding_character(terminal_character);
2148+
self.set_preceding_character(terminal_character.clone());
21492149
self.add_character(terminal_character);
21502150
}
21512151

@@ -2821,9 +2821,9 @@ impl Perform for Grid {
28212821
self.add_character_at_cursor_position(pad_character, true);
28222822
}
28232823
} else if c == 'b' {
2824-
if let Some(c) = self.preceding_char {
2824+
if let Some(c) = self.preceding_char.clone() {
28252825
for _ in 0..next_param_or(1) {
2826-
self.add_character(c);
2826+
self.add_character(c.clone());
28272827
}
28282828
}
28292829
} else if c == 'E' {
@@ -3220,10 +3220,10 @@ impl Row {
32203220
pub fn add_character_at(&mut self, terminal_character: TerminalCharacter, x: usize) {
32213221
match self.width_cached().cmp(&x) {
32223222
Ordering::Equal => {
3223-
// adding the character at the end of the current line
3224-
self.columns.push_back(terminal_character);
32253223
// this is unwrapped because this always happens after self.width_cached()
32263224
*self.width.as_mut().unwrap() += terminal_character.width();
3225+
// adding the character at the end of the current line
3226+
self.columns.push_back(terminal_character);
32273227
},
32283228
Ordering::Less => {
32293229
// adding the character after the end of the current line
@@ -3295,10 +3295,11 @@ impl Row {
32953295
pub fn replace_character_at(&mut self, terminal_character: TerminalCharacter, x: usize) {
32963296
let absolute_x_index = self.absolute_character_index(x);
32973297
if absolute_x_index < self.columns.len() {
3298+
let terminal_character_width = terminal_character.width();
32983299
self.columns.push_back(terminal_character);
32993300
// this is much more performant than remove/insert
33003301
if let Some(character) = self.columns.swap_remove_back(absolute_x_index) {
3301-
let excess_width = character.width().saturating_sub(terminal_character.width());
3302+
let excess_width = character.width().saturating_sub(terminal_character_width);
33023303
for _ in 0..excess_width {
33033304
self.columns
33043305
.insert(absolute_x_index, EMPTY_TERMINAL_CHARACTER);
@@ -3418,8 +3419,8 @@ impl Row {
34183419
current_part = VecDeque::new();
34193420
current_part_len = 0;
34203421
}
3421-
current_part.push_back(character);
34223422
current_part_len += character.width();
3423+
current_part.push_back(character);
34233424
}
34243425
if !current_part.is_empty() {
34253426
parts.push(Row::from_columns(current_part))

zellij-server/src/panes/terminal_character.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ impl Cursor {
836836
}
837837
}
838838

839-
#[derive(Clone, Copy, PartialEq)]
839+
#[derive(Clone, PartialEq)]
840840
pub struct TerminalCharacter {
841841
pub character: char,
842842
pub styles: CharacterStyles,

0 commit comments

Comments
 (0)