Compiles, but searching is very, very broken

This commit is contained in:
Xithrius 2023-02-12 22:58:43 -08:00
parent afba44e4c2
commit e5b47bfa73
No known key found for this signature in database
GPG Key ID: A867F27CC80B28C1
3 changed files with 49 additions and 68 deletions

View File

@ -66,22 +66,16 @@ impl MessageData {
Rgb(rgb[0], rgb[1], rgb[2])
}
pub fn to_row_and_num_search_results(
fn wrap_message(
&self,
frontend_config: &FrontendConfig,
width: usize,
search_highlight: Option<String>,
username_highlight: Option<String>,
) -> (Vec<Spans>, u32) {
let time_sent = self
.time_sent
.format(&frontend_config.date_format)
.to_string();
time_sent: String,
) -> Vec<String> {
let width_sub_margin = width - (frontend_config.margin as usize * 2);
// Subtraction of 2 for the spaces in between the date, user, and message.
let first_line_limit = width_sub_margin - self.author.len() - time_sent.len() - 4;
let first_line_limit = width_sub_margin - time_sent.len() - self.author.len() - 2;
let mut message_split = textwrap::wrap(
&self.payload,
@ -104,9 +98,49 @@ impl MessageData {
}
}
let message_spans = message_split
message_split
}
pub fn to_spans(
&self,
frontend_config: &FrontendConfig,
width: usize,
search_highlight: Option<String>,
username_highlight: Option<String>,
) -> (Vec<Spans>, u32) {
let time_sent = self
.time_sent
.format(&frontend_config.date_format)
.to_string();
let message_spans = self
.wrap_message(frontend_config, width, time_sent.clone())
.iter()
.map(|s| Span::raw(s.clone()))
.map(|s| {
if let Some(search) = search_highlight.clone() {
if let Some((_, indices)) = FUZZY_FINDER.fuzzy_indices(s, search.as_str()) {
return s
.chars()
.enumerate()
.map(|(i, c)| {
if indices.contains(&i) {
Span::styled(
c.to_string(),
Style::default()
.fg(Color::Red)
.add_modifier(Modifier::BOLD),
)
} else {
Span::raw(s.to_string())
}
})
.collect::<Vec<Span>>();
}
}
return vec![Span::raw(s.clone())];
})
.flatten()
.collect::<Vec<Span>>();
let mut info = if frontend_config.date_shown {
@ -163,57 +197,6 @@ impl MessageData {
// let mut num_search_matches = 0;
// let msg_cells = search_highlight.map_or_else(
// || {
// // If the user's name appears in a row, highlight it.
// message
// .split('\n')
// .map(|s| {
// Cell::from(Spans::from(vec![Span::styled(
// s.to_owned(),
// username_highlight_style,
// )]))
// })
// .collect::<Vec<Cell>>()
// },
// |search| {
// // Going through all the rows with a search to see if there's a fuzzy match.
// // If there is, highlight said match in red.
// message
// .split('\n')
// .map(|s| {
// let chars = s.chars();
// if let Some((_, indices)) = FUZZY_FINDER.fuzzy_indices(s, search.as_str()) {
// num_search_matches += 1;
// Cell::from(vec![Spans::from(
// chars
// .enumerate()
// .map(|(i, s)| {
// if indices.contains(&i) {
// Span::styled(
// s.to_string(),
// Style::default()
// .fg(Color::Red)
// .add_modifier(Modifier::BOLD),
// )
// } else {
// Span::raw(s.to_string())
// }
// })
// .collect::<Vec<Span>>(),
// )])
// } else {
// Cell::from(Spans::from(vec![Span::styled(
// s.to_owned(),
// username_highlight_style,
// )]))
// }
// })
// .collect::<Vec<Cell>>()
// },
// );
// if msg_cells.len() > 1 {
// for cell in msg_cells.iter().skip(1) {
// let mut wrapped_msg = vec![Cell::from(""), cell.clone()];

View File

@ -132,7 +132,7 @@ pub fn draw_ui<T: Backend>(frame: &mut Frame<T>, app: &mut App, config: &Complet
None
};
let (spans, _num_results) = data.to_row_and_num_search_results(
let (spans, _num_results) = data.to_spans(
&config.frontend,
message_chunk_width,
if app.input_buffer.is_empty() {
@ -215,8 +215,6 @@ pub fn draw_ui<T: Backend>(frame: &mut Frame<T>, app: &mut App, config: &Complet
}),
)
.style(Style::default().fg(Color::White));
// .highlight_style(Style::default().add_modifier(Modifier::ITALIC))
// .highlight_symbol(">>");
frame.render_widget(list, layout.first_chunk());

View File

@ -30,13 +30,13 @@ pub const DATETIME_LIGHT: Style = Style {
pub const HIGHLIGHT_NAME_DARK: Style = Style {
fg: Some(Color::Black),
bg: Some(Color::White),
add_modifier: Modifier::empty(),
add_modifier: Modifier::BOLD,
sub_modifier: Modifier::empty(),
};
pub const HIGHLIGHT_NAME_LIGHT: Style = Style {
fg: Some(Color::White),
bg: Some(Color::Black),
add_modifier: Modifier::empty(),
add_modifier: Modifier::BOLD,
sub_modifier: Modifier::empty(),
};