@@ -987,7 +987,7 @@ impl Grid {
987
987
. iter ( )
988
988
. map ( |r| {
989
989
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 ( ) ;
991
991
// pad line
992
992
line. resize (
993
993
self . width . saturating_sub ( excess_width) ,
@@ -1205,7 +1205,7 @@ impl Grid {
1205
1205
pad_character. styles = self . cursor . pending_styles ;
1206
1206
for _ in 0 ..count {
1207
1207
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] ) ;
1209
1209
self . viewport
1210
1210
. insert ( scroll_region_bottom, Row :: from_columns ( columns) . canonical ( ) ) ;
1211
1211
}
@@ -1220,7 +1220,7 @@ impl Grid {
1220
1220
} ;
1221
1221
1222
1222
for _ in 0 ..self . height {
1223
- let columns = VecDeque :: from ( vec ! [ character; self . width] ) ;
1223
+ let columns = VecDeque :: from ( vec ! [ character. clone ( ) ; self . width] ) ;
1224
1224
self . viewport . push ( Row :: from_columns ( columns) . canonical ( ) ) ;
1225
1225
}
1226
1226
self . output_buffer . update_all_lines ( ) ;
@@ -1367,7 +1367,7 @@ impl Grid {
1367
1367
self . viewport
1368
1368
. get ( self . cursor . y )
1369
1369
. and_then ( |current_line| current_line. columns . get ( absolute_x_in_line) )
1370
- . copied ( )
1370
+ . cloned ( )
1371
1371
}
1372
1372
pub fn get_absolute_character_index ( & self , x : usize , y : usize ) -> usize {
1373
1373
self . viewport . get ( y) . unwrap ( ) . absolute_character_index ( x)
@@ -1390,7 +1390,7 @@ impl Grid {
1390
1390
pub fn clear_all_after_cursor ( & mut self , replace_with : TerminalCharacter ) {
1391
1391
if let Some ( cursor_row) = self . viewport . get_mut ( self . cursor . y ) {
1392
1392
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] ) ;
1394
1394
self . replace_characters_in_line_after_cursor ( replace_with) ;
1395
1395
for row in self . viewport . iter_mut ( ) . skip ( self . cursor . y + 1 ) {
1396
1396
row. replace_columns ( replace_with_columns. clone ( ) ) ;
@@ -1400,8 +1400,8 @@ impl Grid {
1400
1400
}
1401
1401
pub fn clear_all_before_cursor ( & mut self , replace_with : TerminalCharacter ) {
1402
1402
if self . viewport . get ( self . cursor . y ) . is_some ( ) {
1403
+ let replace_with_columns = VecDeque :: from ( vec ! [ replace_with. clone( ) ; self . width] ) ;
1403
1404
self . replace_characters_in_line_before_cursor ( replace_with) ;
1404
- let replace_with_columns = VecDeque :: from ( vec ! [ replace_with; self . width] ) ;
1405
1405
for row in self . viewport . iter_mut ( ) . take ( self . cursor . y ) {
1406
1406
row. replace_columns ( replace_with_columns. clone ( ) ) ;
1407
1407
}
@@ -1415,7 +1415,7 @@ impl Grid {
1415
1415
}
1416
1416
}
1417
1417
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] ) ;
1419
1419
self . replace_characters_in_line_after_cursor ( replace_with) ;
1420
1420
for row in & mut self . viewport {
1421
1421
row. replace_columns ( replace_with_columns. clone ( ) ) ;
@@ -1450,18 +1450,18 @@ impl Grid {
1450
1450
1451
1451
fn pad_current_line_until ( & mut self , position : usize , pad_character : TerminalCharacter ) {
1452
1452
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 ( ) ) ;
1454
1454
}
1455
1455
if let Some ( current_row) = self . viewport . get_mut ( self . cursor . y ) {
1456
1456
for _ in current_row. width ( ) ..position {
1457
- current_row. push ( pad_character) ;
1457
+ current_row. push ( pad_character. clone ( ) ) ;
1458
1458
}
1459
1459
self . output_buffer . update_line ( self . cursor . y ) ;
1460
1460
}
1461
1461
}
1462
1462
fn pad_lines_until ( & mut self , position : usize , pad_character : TerminalCharacter ) {
1463
1463
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] ) ;
1465
1465
self . viewport . push ( Row :: from_columns ( columns) . canonical ( ) ) ;
1466
1466
self . output_buffer . update_line ( self . viewport . len ( ) - 1 ) ;
1467
1467
}
@@ -1480,13 +1480,13 @@ impl Grid {
1480
1480
} else {
1481
1481
self . cursor . y = std:: cmp:: min ( self . height - 1 , y + y_offset) ;
1482
1482
}
1483
- self . pad_lines_until ( self . cursor . y , pad_character) ;
1483
+ self . pad_lines_until ( self . cursor . y , pad_character. clone ( ) ) ;
1484
1484
self . pad_current_line_until ( self . cursor . x , pad_character) ;
1485
1485
} ,
1486
1486
None => {
1487
1487
self . cursor . x = std:: cmp:: min ( self . width - 1 , x) ;
1488
1488
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 ( ) ) ;
1490
1490
self . pad_current_line_until ( self . cursor . x , pad_character) ;
1491
1491
} ,
1492
1492
}
@@ -1586,7 +1586,7 @@ impl Grid {
1586
1586
// region
1587
1587
for _ in 0 ..count {
1588
1588
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] ) ;
1590
1590
if self . viewport . len ( ) > scroll_region_bottom {
1591
1591
self . viewport
1592
1592
. insert ( scroll_region_bottom, Row :: from_columns ( columns) . canonical ( ) ) ;
@@ -1615,7 +1615,7 @@ impl Grid {
1615
1615
if scroll_region_bottom < self . viewport . len ( ) {
1616
1616
self . viewport . remove ( scroll_region_bottom) ;
1617
1617
}
1618
- let columns = VecDeque :: from ( vec ! [ pad_character; self . width] ) ;
1618
+ let columns = VecDeque :: from ( vec ! [ pad_character. clone ( ) ; self . width] ) ;
1619
1619
self . viewport
1620
1620
. insert ( current_line_index, Row :: from_columns ( columns) . canonical ( ) ) ;
1621
1621
}
@@ -1638,10 +1638,10 @@ impl Grid {
1638
1638
let mut empty_character = EMPTY_TERMINAL_CHARACTER ;
1639
1639
empty_character. styles = empty_char_style;
1640
1640
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 ( ) ) ;
1642
1642
if let Some ( current_row) = self . viewport . get_mut ( self . cursor . y ) {
1643
1643
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) ;
1645
1645
}
1646
1646
self . output_buffer . update_line ( self . cursor . y ) ;
1647
1647
}
@@ -1664,9 +1664,9 @@ impl Grid {
1664
1664
. unwrap_or ( 0 )
1665
1665
. saturating_sub ( 1 ) ;
1666
1666
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 ) ;
1668
1668
}
1669
- current_row. push ( empty_character) ;
1669
+ current_row. push ( empty_character. clone ( ) ) ;
1670
1670
}
1671
1671
self . output_buffer . update_line ( self . cursor . y ) ;
1672
1672
}
@@ -2145,7 +2145,7 @@ impl Perform for Grid {
2145
2145
let c = self . cursor . charsets [ self . active_charset ] . map ( c) ;
2146
2146
2147
2147
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 ( ) ) ;
2149
2149
self . add_character ( terminal_character) ;
2150
2150
}
2151
2151
@@ -2821,9 +2821,9 @@ impl Perform for Grid {
2821
2821
self . add_character_at_cursor_position ( pad_character, true ) ;
2822
2822
}
2823
2823
} else if c == 'b' {
2824
- if let Some ( c) = self . preceding_char {
2824
+ if let Some ( c) = self . preceding_char . clone ( ) {
2825
2825
for _ in 0 ..next_param_or ( 1 ) {
2826
- self . add_character ( c) ;
2826
+ self . add_character ( c. clone ( ) ) ;
2827
2827
}
2828
2828
}
2829
2829
} else if c == 'E' {
@@ -3220,10 +3220,10 @@ impl Row {
3220
3220
pub fn add_character_at ( & mut self , terminal_character : TerminalCharacter , x : usize ) {
3221
3221
match self . width_cached ( ) . cmp ( & x) {
3222
3222
Ordering :: Equal => {
3223
- // adding the character at the end of the current line
3224
- self . columns . push_back ( terminal_character) ;
3225
3223
// this is unwrapped because this always happens after self.width_cached()
3226
3224
* 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) ;
3227
3227
} ,
3228
3228
Ordering :: Less => {
3229
3229
// adding the character after the end of the current line
@@ -3295,10 +3295,11 @@ impl Row {
3295
3295
pub fn replace_character_at ( & mut self , terminal_character : TerminalCharacter , x : usize ) {
3296
3296
let absolute_x_index = self . absolute_character_index ( x) ;
3297
3297
if absolute_x_index < self . columns . len ( ) {
3298
+ let terminal_character_width = terminal_character. width ( ) ;
3298
3299
self . columns . push_back ( terminal_character) ;
3299
3300
// this is much more performant than remove/insert
3300
3301
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 ) ;
3302
3303
for _ in 0 ..excess_width {
3303
3304
self . columns
3304
3305
. insert ( absolute_x_index, EMPTY_TERMINAL_CHARACTER ) ;
@@ -3418,8 +3419,8 @@ impl Row {
3418
3419
current_part = VecDeque :: new ( ) ;
3419
3420
current_part_len = 0 ;
3420
3421
}
3421
- current_part. push_back ( character) ;
3422
3422
current_part_len += character. width ( ) ;
3423
+ current_part. push_back ( character) ;
3423
3424
}
3424
3425
if !current_part. is_empty ( ) {
3425
3426
parts. push ( Row :: from_columns ( current_part) )
0 commit comments