@@ -4,7 +4,7 @@ use crate::snippet::{Style, StyledString};
44
55#[ derive( Debug ) ]
66pub struct StyledBuffer {
7- text : Vec < Vec < StyledChar > > ,
7+ lines : Vec < Vec < StyledChar > > ,
88}
99
1010#[ derive( Debug ) ]
@@ -27,22 +27,22 @@ impl Default for StyledChar {
2727
2828impl StyledBuffer {
2929 pub fn new ( ) -> StyledBuffer {
30- StyledBuffer { text : vec ! [ ] }
30+ StyledBuffer { lines : vec ! [ ] }
3131 }
3232
3333 /// Returns content of `StyledBuffer` splitted by lines and line styles
3434 pub fn render ( & self ) -> Vec < Vec < StyledString > > {
3535 // 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' ) ) ) ;
3737
3838 let mut output: Vec < Vec < StyledString > > = vec ! [ ] ;
3939 let mut styled_vec: Vec < StyledString > = vec ! [ ] ;
4040
41- for styled_row in & self . text {
41+ for styled_line in & self . lines {
4242 let mut current_style = Style :: NoStyle ;
4343 let mut current_text = String :: new ( ) ;
4444
45- for sc in styled_row {
45+ for sc in styled_line {
4646 if sc. style != current_style {
4747 if !current_text. is_empty ( ) {
4848 styled_vec. push ( StyledString { text : current_text, style : current_style } ) ;
@@ -66,8 +66,8 @@ impl StyledBuffer {
6666 }
6767
6868 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 ! [ ] ) ;
7171 }
7272 }
7373
@@ -76,15 +76,15 @@ impl StyledBuffer {
7676 /// and fills last line with spaces and `Style::NoStyle` style
7777 pub fn putc ( & mut self , line : usize , col : usize , chr : char , style : Style ) {
7878 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) ;
8181 } else {
82- let mut i = self . text [ line] . len ( ) ;
82+ let mut i = self . lines [ line] . len ( ) ;
8383 while i < col {
84- self . text [ line] . push ( StyledChar :: default ( ) ) ;
84+ self . lines [ line] . push ( StyledChar :: default ( ) ) ;
8585 i += 1 ;
8686 }
87- self . text [ line] . push ( StyledChar :: new ( chr, style) ) ;
87+ self . lines [ line] . push ( StyledChar :: new ( chr, style) ) ;
8888 }
8989 }
9090
@@ -105,10 +105,10 @@ impl StyledBuffer {
105105 self . ensure_lines ( line) ;
106106 let string_len = string. chars ( ) . count ( ) ;
107107
108- if !self . text [ line] . is_empty ( ) {
108+ if !self . lines [ line] . is_empty ( ) {
109109 // Push the old content over to make room for new content
110110 for _ in 0 ..string_len {
111- self . text [ line] . insert ( 0 , StyledChar :: default ( ) ) ;
111+ self . lines [ line] . insert ( 0 , StyledChar :: default ( ) ) ;
112112 }
113113 }
114114
@@ -118,16 +118,16 @@ impl StyledBuffer {
118118 /// For given `line` inserts `string` with `style` after old content of that line,
119119 /// adding lines if needed
120120 pub fn append ( & mut self , line : usize , string : & str , style : Style ) {
121- if line >= self . text . len ( ) {
121+ if line >= self . lines . len ( ) {
122122 self . puts ( line, 0 , string, style) ;
123123 } else {
124- let col = self . text [ line] . len ( ) ;
124+ let col = self . lines [ line] . len ( ) ;
125125 self . puts ( line, col, string, style) ;
126126 }
127127 }
128128
129129 pub fn num_lines ( & self ) -> usize {
130- self . text . len ( )
130+ self . lines . len ( )
131131 }
132132
133133 /// Set `style` for `line`, `col_start..col_end` range if:
@@ -150,7 +150,7 @@ impl StyledBuffer {
150150 /// 1. That line and column exist in `StyledBuffer`
151151 /// 2. `overwrite` is `true` or existing style is `Style::NoStyle` or `Style::Quotation`
152152 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) {
154154 if let Some ( StyledChar { style : s, .. } ) = line. get_mut ( col) {
155155 if overwrite || * s == Style :: NoStyle || * s == Style :: Quotation {
156156 * s = style;
0 commit comments