fix(tui): fix launch panic, highlight search matches
This commit is contained in:
1 parent
41a63e16c4
commit
14fd9d1ebc
4 files changed
+49
-6
No files matched your search
@@ -239,9 +239,7 @@ pub async fn launch(
|
||||
Some(acc) => {
|
||||
let token = match acc.account_type {
|
||||
crate::auth::AccountType::Microsoft => {
|
||||
match tokio::runtime::Handle::current()
|
||||
.block_on(crate::auth::refresh_and_get_token(acc))
|
||||
{
|
||||
match crate::auth::refresh_and_get_token(acc).await {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
tracing::error!("Token refresh failed: {e}");
|
||||
|
||||
+3
-2
@@ -602,7 +602,7 @@ impl App {
|
||||
use ratatui::{
|
||||
layout::{Alignment, Margin},
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
text::Line,
|
||||
widgets::{
|
||||
Block, BorderType, Clear, Paragraph, Scrollbar, ScrollbarOrientation,
|
||||
},
|
||||
@@ -652,6 +652,7 @@ impl App {
|
||||
let inner = block.inner(overlay);
|
||||
frame.render_widget(block, overlay);
|
||||
|
||||
let search = &self.log_overlay_search;
|
||||
let styled: Vec<Line> = filtered
|
||||
.iter()
|
||||
.skip(self.log_overlay_scroll)
|
||||
@@ -666,7 +667,7 @@ impl App {
|
||||
} else {
|
||||
Style::default().fg(THEME.colors.foreground)
|
||||
};
|
||||
Line::from(Span::styled(line.as_str(), style))
|
||||
search.highlight_line(line, style)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
||||
@@ -500,15 +500,27 @@ fn render_viewer(
|
||||
return;
|
||||
}
|
||||
|
||||
let search = &state.viewer_search;
|
||||
let styled_lines: Vec<Line> = lines
|
||||
.iter()
|
||||
.skip(state.viewer_scroll)
|
||||
.take(visible_height)
|
||||
.map(|line| Line::from(Span::styled(line.as_str(), line_level_style(line))))
|
||||
.map(|line| search.highlight_line(line, line_level_style(line)))
|
||||
.collect();
|
||||
|
||||
frame.render_widget(Paragraph::new(styled_lines), area);
|
||||
|
||||
if let Some(sl) = state.viewer_search.title_line() {
|
||||
let sw = sl.width() as u16;
|
||||
let search_area = Rect {
|
||||
x: area.x + area.width.saturating_sub(sw + 1),
|
||||
y: area.y,
|
||||
width: sw + 1,
|
||||
height: 1,
|
||||
};
|
||||
frame.render_widget(Paragraph::new(sl), search_area);
|
||||
}
|
||||
|
||||
let scrollbar_area = Rect {
|
||||
x: area.x + area.width.saturating_sub(0),
|
||||
y: area.y + 1,
|
||||
|
||||
@@ -40,6 +40,38 @@ impl SearchState {
|
||||
text.to_lowercase().contains(&self.query.to_lowercase())
|
||||
}
|
||||
|
||||
pub fn highlight_line<'a>(&self, text: &'a str, base_style: Style) -> Line<'a> {
|
||||
if self.query.is_empty() {
|
||||
return Line::from(Span::styled(text, base_style));
|
||||
}
|
||||
|
||||
let query_lower = self.query.to_lowercase();
|
||||
let text_lower = text.to_lowercase();
|
||||
let mut spans = Vec::new();
|
||||
let mut last = 0;
|
||||
|
||||
for (start, _) in text_lower.match_indices(&query_lower) {
|
||||
if start > last {
|
||||
spans.push(Span::styled(&text[last..start], base_style));
|
||||
}
|
||||
spans.push(Span::styled(
|
||||
&text[start..start + self.query.len()],
|
||||
base_style.add_modifier(Modifier::BOLD | Modifier::UNDERLINED),
|
||||
));
|
||||
last = start + self.query.len();
|
||||
}
|
||||
|
||||
if last < text.len() {
|
||||
spans.push(Span::styled(&text[last..], base_style));
|
||||
}
|
||||
|
||||
if spans.is_empty() {
|
||||
Line::from(Span::styled(text, base_style))
|
||||
} else {
|
||||
Line::from(spans)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn title_line(&self) -> Option<Line<'static>> {
|
||||
if !self.active && self.query.is_empty() {
|
||||
return None;
|
||||
|
||||
Reference in new issue
Block a user