@@ -4,7 +4,7 @@ use crate::snippet::{Style, StyledString};
4
4
5
5
#[ derive( Debug ) ]
6
6
pub struct StyledBuffer {
7
- text : Vec < Vec < StyledChar > > ,
7
+ lines : Vec < Vec < StyledChar > > ,
8
8
}
9
9
10
10
#[ derive( Debug ) ]
@@ -27,22 +27,22 @@ impl Default for StyledChar {
27
27
28
28
impl StyledBuffer {
29
29
pub fn new ( ) -> StyledBuffer {
30
- StyledBuffer { text : vec ! [ ] }
30
+ StyledBuffer { lines : vec ! [ ] }
31
31
}
32
32
33
33
/// Returns content of `StyledBuffer` splitted by lines and line styles
34
34
pub fn render ( & self ) -> Vec < Vec < StyledString > > {
35
35
// Tabs are assumed to have been replaced by spaces in calling code.
36
- debug_assert ! ( self . text . iter( ) . all( |r| !r. iter( ) . any( |sc| sc. chr == '\t' ) ) ) ;
36
+ debug_assert ! ( self . lines . iter( ) . all( |r| !r. iter( ) . any( |sc| sc. chr == '\t' ) ) ) ;
37
37
38
38
let mut output: Vec < Vec < StyledString > > = vec ! [ ] ;
39
39
let mut styled_vec: Vec < StyledString > = vec ! [ ] ;
40
40
41
- for styled_row in & self . text {
41
+ for styled_line in & self . lines {
42
42
let mut current_style = Style :: NoStyle ;
43
43
let mut current_text = String :: new ( ) ;
44
44
45
- for sc in styled_row {
45
+ for sc in styled_line {
46
46
if sc. style != current_style {
47
47
if !current_text. is_empty ( ) {
48
48
styled_vec. push ( StyledString { text : current_text, style : current_style } ) ;
@@ -66,8 +66,8 @@ impl StyledBuffer {
66
66
}
67
67
68
68
fn ensure_lines ( & mut self , line : usize ) {
69
- while line >= self . text . len ( ) {
70
- self . text . push ( vec ! [ ] ) ;
69
+ while line >= self . lines . len ( ) {
70
+ self . lines . push ( vec ! [ ] ) ;
71
71
}
72
72
}
73
73
@@ -76,15 +76,15 @@ impl StyledBuffer {
76
76
/// and fills last line with spaces and `Style::NoStyle` style
77
77
pub fn putc ( & mut self , line : usize , col : usize , chr : char , style : Style ) {
78
78
self . ensure_lines ( line) ;
79
- if col < self . text [ line] . len ( ) {
80
- self . text [ line] [ col] = StyledChar :: new ( chr, style) ;
79
+ if col < self . lines [ line] . len ( ) {
80
+ self . lines [ line] [ col] = StyledChar :: new ( chr, style) ;
81
81
} else {
82
- let mut i = self . text [ line] . len ( ) ;
82
+ let mut i = self . lines [ line] . len ( ) ;
83
83
while i < col {
84
- self . text [ line] . push ( StyledChar :: default ( ) ) ;
84
+ self . lines [ line] . push ( StyledChar :: default ( ) ) ;
85
85
i += 1 ;
86
86
}
87
- self . text [ line] . push ( StyledChar :: new ( chr, style) ) ;
87
+ self . lines [ line] . push ( StyledChar :: new ( chr, style) ) ;
88
88
}
89
89
}
90
90
@@ -105,10 +105,10 @@ impl StyledBuffer {
105
105
self . ensure_lines ( line) ;
106
106
let string_len = string. chars ( ) . count ( ) ;
107
107
108
- if !self . text [ line] . is_empty ( ) {
108
+ if !self . lines [ line] . is_empty ( ) {
109
109
// Push the old content over to make room for new content
110
110
for _ in 0 ..string_len {
111
- self . text [ line] . insert ( 0 , StyledChar :: default ( ) ) ;
111
+ self . lines [ line] . insert ( 0 , StyledChar :: default ( ) ) ;
112
112
}
113
113
}
114
114
@@ -118,16 +118,16 @@ impl StyledBuffer {
118
118
/// For given `line` inserts `string` with `style` after old content of that line,
119
119
/// adding lines if needed
120
120
pub fn append ( & mut self , line : usize , string : & str , style : Style ) {
121
- if line >= self . text . len ( ) {
121
+ if line >= self . lines . len ( ) {
122
122
self . puts ( line, 0 , string, style) ;
123
123
} else {
124
- let col = self . text [ line] . len ( ) ;
124
+ let col = self . lines [ line] . len ( ) ;
125
125
self . puts ( line, col, string, style) ;
126
126
}
127
127
}
128
128
129
129
pub fn num_lines ( & self ) -> usize {
130
- self . text . len ( )
130
+ self . lines . len ( )
131
131
}
132
132
133
133
/// Set `style` for `line`, `col_start..col_end` range if:
@@ -150,7 +150,7 @@ impl StyledBuffer {
150
150
/// 1. That line and column exist in `StyledBuffer`
151
151
/// 2. `overwrite` is `true` or existing style is `Style::NoStyle` or `Style::Quotation`
152
152
pub fn set_style ( & mut self , line : usize , col : usize , style : Style , overwrite : bool ) {
153
- if let Some ( ref mut line) = self . text . get_mut ( line) {
153
+ if let Some ( ref mut line) = self . lines . get_mut ( line) {
154
154
if let Some ( StyledChar { style : s, .. } ) = line. get_mut ( col) {
155
155
if overwrite || * s == Style :: NoStyle || * s == Style :: Quotation {
156
156
* s = style;
0 commit comments