@@ -30,6 +30,7 @@ impl StyledBuffer {
30
30
StyledBuffer { text : vec ! [ ] }
31
31
}
32
32
33
+ /// Returns content of `StyledBuffer` splitted by lines and line styles
33
34
pub fn render ( & self ) -> Vec < Vec < StyledString > > {
34
35
// Tabs are assumed to have been replaced by spaces in calling code.
35
36
debug_assert ! ( self . text. iter( ) . all( |r| !r. iter( ) . any( |sc| sc. chr == '\t' ) ) ) ;
@@ -70,6 +71,9 @@ impl StyledBuffer {
70
71
}
71
72
}
72
73
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
73
77
pub fn putc ( & mut self , line : usize , col : usize , chr : char , style : Style ) {
74
78
self . ensure_lines ( line) ;
75
79
if col < self . text [ line] . len ( ) {
@@ -84,6 +88,9 @@ impl StyledBuffer {
84
88
}
85
89
}
86
90
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
87
94
pub fn puts ( & mut self , line : usize , col : usize , string : & str , style : Style ) {
88
95
let mut n = col;
89
96
for c in string. chars ( ) {
@@ -92,6 +99,8 @@ impl StyledBuffer {
92
99
}
93
100
}
94
101
102
+ /// For given `line` inserts `string` with `style` before old content of that line,
103
+ /// adding lines if needed
95
104
pub fn prepend ( & mut self , line : usize , string : & str , style : Style ) {
96
105
self . ensure_lines ( line) ;
97
106
let string_len = string. chars ( ) . count ( ) ;
@@ -104,6 +113,8 @@ impl StyledBuffer {
104
113
self . puts ( line, 0 , string, style) ;
105
114
}
106
115
116
+ /// For given `line` inserts `string` with `style` after old content of that line,
117
+ /// adding lines if needed
107
118
pub fn append ( & mut self , line : usize , string : & str , style : Style ) {
108
119
if line >= self . text . len ( ) {
109
120
self . puts ( line, 0 , string, style) ;
@@ -117,6 +128,9 @@ impl StyledBuffer {
117
128
self . text . len ( )
118
129
}
119
130
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`
120
134
pub fn set_style_range (
121
135
& mut self ,
122
136
line : usize ,
@@ -130,6 +144,9 @@ impl StyledBuffer {
130
144
}
131
145
}
132
146
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`
133
150
pub fn set_style ( & mut self , line : usize , col : usize , style : Style , overwrite : bool ) {
134
151
if let Some ( ref mut line) = self . text . get_mut ( line) {
135
152
if let Some ( StyledChar { style : s, .. } ) = line. get_mut ( col) {
0 commit comments