@@ -15,21 +15,21 @@ use crate::{
1515 traits:: { ByteSuffixCheck , FirstChars , LineHelpers } ,
1616} ;
1717
18- #[ derive( Debug ) ]
18+ #[ derive( Debug , Clone ) ]
1919pub struct BufLine {
20- pub timestamp : DateTime < Local > ,
20+ pub ( super ) timestamp : DateTime < Local > ,
2121 timestamp_str : CompactString ,
2222
2323 index_info : CompactString ,
2424
25- value : Line < ' static > ,
25+ pub ( super ) value : Line < ' static > ,
2626
2727 /// How many vertical lines are needed in the terminal to fully show this line.
2828 // Truncated from usize, since even the ratatui sizes are capped there.
2929 rendered_line_height : u16 ,
3030
31- pub ( super ) raw_buffer_index : usize ,
32- pub ( super ) line_type : LineType ,
31+ pub raw_buffer_index : usize ,
32+ pub line_type : LineType ,
3333}
3434
3535// impl PartialEq for BufLine {
@@ -100,7 +100,7 @@ impl BufLine {
100100 // determine_color(&mut line, &[]);
101101 // }
102102
103- let index_info = index_info ( raw_value, raw_buffer_index, line_type) ;
103+ let index_info = make_index_info ( raw_value, raw_buffer_index, line_type) ;
104104
105105 let mut bufline = Self {
106106 timestamp_str : now. format ( time_format) . to_compact_string ( ) ,
@@ -121,41 +121,13 @@ impl BufLine {
121121 area_width : u16 ,
122122 rendering : & Rendering ,
123123 ) {
124- self . index_info = index_info ( full_line_slice, self . raw_buffer_index , self . line_type ) ;
124+ self . index_info = make_index_info ( full_line_slice, self . raw_buffer_index , self . line_type ) ;
125125
126126 self . value = line;
127127 self . value . remove_unsavory_chars ( ) ;
128128 self . update_line_height ( area_width, rendering) ;
129129 }
130130
131- // pub fn new(
132- // raw_value: &[u8],
133- // raw_buffer_index: usize,
134- // area_width: u16,
135- // with_timestamp: bool,
136- // ) -> Self {
137- // let time_format = "[%H:%M:%S%.3f] ";
138-
139- // let value = determine_color(raw_value);
140-
141- // let mut line = Self {
142- // value,
143- // // raw_value: raw_value.to_owned(),
144- // // raw_buffer_index,
145- // // style: None,
146- // rendered_line_height: 0,
147- // timestamp: Local::now().format(time_format).to_string(),
148- // };
149- // line.update_line_height(area_width, with_timestamp);
150- // line
151- // }
152-
153- // pub fn new_user_line(raw)
154-
155- // fn completed(&self, line_ending: &str) -> bool {
156- // self.value.ends_with(line_ending)
157- // }
158-
159131 pub fn update_line_height ( & mut self , area_width : u16 , rendering : & Rendering ) -> usize {
160132 let para = Paragraph :: new ( self . as_line ( rendering) ) . wrap ( Wrap { trim : false } ) ;
161133 // TODO make the sub 1 for margin/scrollbar more sane/clear
@@ -196,43 +168,13 @@ impl BufLine {
196168 pub fn index_in_buffer ( & self ) -> usize {
197169 self . raw_buffer_index
198170 }
199-
200- // pub fn timestamp(&self) -> (DateTime<Local>, &str) {
201- // (self.timestamp, &self.timestamp_str)
202- // }
203-
204- // pub fn is_bytes(&self) -> bool {}
205-
206- // pub fn is_macro(&self) -> bool {}
207-
208- // pub fn bytes(&self) -> &[u8] {
209- // self.raw_value.as_slice()
210- // }
211171}
212172
213- // fn determine_color(line: &mut Line, rules: &[u8]) {
214- // assert_eq!(line.spans.len(), 1);
215- // if let Some(slice) = line.spans[0].content.first_chars(5) {
216- // let mut style = Style::new();
217- // style = match slice {
218- // // "USER>" => style.dark_gray(),
219- // "Got m" => style.blue(),
220- // "ID:0x" => style.green(),
221- // "Chan." => style.dark_gray(),
222- // "Mode:" => style.yellow(),
223- // "Power" => style.red(),
224- // // "keepa" => style.red(),
225- // _ => style,
226- // };
227-
228- // if style != Style::new() {
229- // line.style = style;
230- // line.style_all_spans(style);
231- // }
232- // }
233- // }
234-
235- fn index_info ( full_line_slice : & [ u8 ] , start_index : usize , line_type : LineType ) -> CompactString {
173+ fn make_index_info (
174+ full_line_slice : & [ u8 ] ,
175+ start_index : usize ,
176+ line_type : LineType ,
177+ ) -> CompactString {
236178 if let LineType :: User { .. } = line_type {
237179 format_compact ! (
238180 "({start:06}->{end:06}, {len:3}) " ,
@@ -249,41 +191,3 @@ fn index_info(full_line_slice: &[u8], start_index: usize, line_type: LineType) -
249191 )
250192 }
251193}
252-
253- // fn determine_color(bytes: &[u8]) -> Line<'static> {
254- // // let ratatui::text::Text {
255- // // alignment: _alignment,
256- // // style,
257- // // mut lines,
258- // // } = bytes.into_line(Style::new(), None).unwrap();
259- // // debug!("{:?}", style);
260- // // assert_eq!(lines.len(), 1);
261-
262- // // lines.pop().unwrap()
263-
264- // bytes.into_line(None, Style::new()).unwrap()
265-
266- // // // Not sure if this is actually worth keeping, we'll see once I add proper custom rules.
267- // // if self.style.is_some() {
268- // // return;
269- // // }
270- // // What do I pass into here?
271- // // The rules? Should it instead be an outside decider that supplies the color?
272-
273- // // if let Some(slice) = self.value.first_chars(5) {
274- // // let mut style = Style::new();
275- // // style = match slice {
276- // // "USER>" => style.dark_gray(),
277- // // "Got m" => style.blue(),
278- // // "ID:0x" => style.green(),
279- // // "Chan." => style.dark_gray(),
280- // // "Mode:" => style.yellow(),
281- // // "Power" => style.red(),
282- // // _ => style,
283- // // };
284-
285- // // if style != Style::new() {
286- // // self.style = Some(style);
287- // // }
288- // // }
289- // }
0 commit comments