@@ -30,6 +30,7 @@ impl StyledBuffer {
3030 StyledBuffer { text : vec ! [ ] }
3131 }
3232
33+ /// Returns content of `StyledBuffer` splitted by lines and line styles
3334 pub fn render ( & self ) -> Vec < Vec < StyledString > > {
3435 // Tabs are assumed to have been replaced by spaces in calling code.
3536 debug_assert ! ( self . text. iter( ) . all( |r| !r. iter( ) . any( |sc| sc. chr == '\t' ) ) ) ;
@@ -70,6 +71,9 @@ impl StyledBuffer {
7071 }
7172 }
7273
74+ /// Sets `chr` with `style` for given `line`, `col`.
75+ /// If line not exist in `StyledBuffer`, adds lines up to given
76+ /// and fills last line with spaces and `Style::NoStyle` style
7377 pub fn putc ( & mut self , line : usize , col : usize , chr : char , style : Style ) {
7478 self . ensure_lines ( line) ;
7579 if col < self . text [ line] . len ( ) {
@@ -84,6 +88,9 @@ impl StyledBuffer {
8488 }
8589 }
8690
91+ /// Sets `string` with `style` for given `line`, starting from `col`.
92+ /// If line not exist in `StyledBuffer`, adds lines up to given
93+ /// and fills last line with spaces and `Style::NoStyle` style
8794 pub fn puts ( & mut self , line : usize , col : usize , string : & str , style : Style ) {
8895 let mut n = col;
8996 for c in string. chars ( ) {
@@ -92,6 +99,8 @@ impl StyledBuffer {
9299 }
93100 }
94101
102+ /// For given `line` inserts `string` with `style` before old content of that line,
103+ /// adding lines if needed
95104 pub fn prepend ( & mut self , line : usize , string : & str , style : Style ) {
96105 self . ensure_lines ( line) ;
97106 let string_len = string. chars ( ) . count ( ) ;
@@ -104,6 +113,8 @@ impl StyledBuffer {
104113 self . puts ( line, 0 , string, style) ;
105114 }
106115
116+ /// For given `line` inserts `string` with `style` after old content of that line,
117+ /// adding lines if needed
107118 pub fn append ( & mut self , line : usize , string : & str , style : Style ) {
108119 if line >= self . text . len ( ) {
109120 self . puts ( line, 0 , string, style) ;
@@ -117,6 +128,9 @@ impl StyledBuffer {
117128 self . text . len ( )
118129 }
119130
131+ /// Set `style` for `line`, `col_start..col_end` range if:
132+ /// 1. That line and column range exist in `StyledBuffer`
133+ /// 2. `overwrite` is `true` or existing style is `Style::NoStyle` or `Style::Quotation`
120134 pub fn set_style_range (
121135 & mut self ,
122136 line : usize ,
@@ -130,6 +144,9 @@ impl StyledBuffer {
130144 }
131145 }
132146
147+ /// Set `style` for `line`, `col` if:
148+ /// 1. That line and column exist in `StyledBuffer`
149+ /// 2. Existing style is `Style::NoStyle` or `Style::Quotation` or `overwrite` is `true`
133150 pub fn set_style ( & mut self , line : usize , col : usize , style : Style , overwrite : bool ) {
134151 if let Some ( ref mut line) = self . text . get_mut ( line) {
135152 if let Some ( StyledChar { style : s, .. } ) = line. get_mut ( col) {
0 commit comments