fix(tui/notifications): honor custom filters and clarify UI copy

This commit is contained in:
James Peter
2025-09-27 07:22:58 +10:00
parent 6a8aac2d39
commit 51a3c283a7
2 changed files with 30 additions and 12 deletions
@@ -14,7 +14,7 @@ use super::BottomPane;
#[derive(Clone)]
pub(crate) enum NotificationsMode {
Toggle { enabled: bool },
Custom { command: Vec<String> },
Custom { entries: Vec<String> },
}
pub(crate) struct NotificationsSettingsView {
@@ -41,9 +41,18 @@ impl NotificationsSettingsView {
self.app_event_tx
.send(AppEvent::UpdateTuiNotifications(*enabled));
}
NotificationsMode::Custom { .. } => {
NotificationsMode::Custom { entries } => {
let filters = if entries.is_empty() {
"(none)".to_string()
} else {
entries.join(", ")
};
self.app_event_tx.send_background_event(format!(
"TUI notifications are filtered in config: [{}]",
filters
));
self.app_event_tx.send_background_event(
"TUI notifications use a custom command. Edit ~/.code/config.toml to change this.",
"Edit ~/.code/config.toml [tui].notifications to change filters.".to_string(),
);
}
}
@@ -63,17 +72,17 @@ impl NotificationsSettingsView {
Span::styled(status, Style::default().fg(color).add_modifier(Modifier::BOLD)),
])
}
NotificationsMode::Custom { command } => {
let command_display = if command.is_empty() {
"<empty>".to_string()
NotificationsMode::Custom { entries } => {
let filters = if entries.is_empty() {
"<none>".to_string()
} else {
command.join(" ")
entries.join(", ")
};
Line::from(vec![
Span::styled("Status: ", Style::default().fg(crate::colors::text_dim())),
Span::styled("Custom command", Style::default().fg(crate::colors::info()).add_modifier(Modifier::BOLD)),
Span::styled("Custom filter", Style::default().fg(crate::colors::info()).add_modifier(Modifier::BOLD)),
Span::raw(" "),
Span::styled(command_display, Style::default().fg(crate::colors::dim())),
Span::styled(filters, Style::default().fg(crate::colors::dim())),
])
}
}
@@ -199,7 +208,7 @@ impl<'a> BottomPaneView<'a> for NotificationsSettingsView {
NotificationsMode::Custom { .. } => Line::from(vec![
Span::styled("Edit ", Style::default().fg(crate::colors::text_dim())),
Span::styled("[tui].notifications", Style::default().fg(crate::colors::info())),
Span::styled(" in ~/.code/config.toml to change this setting.", Style::default().fg(crate::colors::text_dim())),
Span::styled(" in ~/.code/config.toml to adjust filters.", Style::default().fg(crate::colors::text_dim())),
]),
};
lines.push(footer);
+11 -2
View File
@@ -7439,7 +7439,7 @@ impl ChatWidget<'_> {
let mode = match &self.config.tui.notifications {
Notifications::Enabled(enabled) => NotificationsMode::Toggle { enabled: *enabled },
Notifications::Custom(command) => NotificationsMode::Custom { command: command.clone() },
Notifications::Custom(entries) => NotificationsMode::Custom { entries: entries.clone() },
};
let view = NotificationsSettingsView::new(mode, self.app_event_tx.clone());
@@ -19397,7 +19397,7 @@ impl ChatWidget<'_> {
}
fn emit_turn_complete_notification(&self, last_agent_message: Option<String>) {
if !matches!(self.config.tui.notifications, Notifications::Enabled(true)) {
if !self.tui_notifications_allow("agent-turn-complete") {
return;
}
@@ -19412,6 +19412,15 @@ impl ChatWidget<'_> {
});
}
fn tui_notifications_allow(&self, event: &str) -> bool {
match &self.config.tui.notifications {
Notifications::Enabled(enabled) => *enabled,
Notifications::Custom(entries) => entries
.iter()
.any(|entry| entry.eq_ignore_ascii_case(event)),
}
}
fn notification_snippet(input: &str) -> String {
let collapsed = input
.split_whitespace()