Skip to content

Commit feb26a8

Browse files
authored
feat(tui): remove toast notifications (#22)
* feat(tui): disable toast notifications - Modified ToastManager.push/success/info/warning/error methods to return 0 immediately (no-op) - Commented out toast rendering block in rendering.rs - Applied same changes to both cortex-tui and cortex-tui-components toast modules * fix(tui): update toast tests for disabled functionality * fix(tui): remove unused next_id field from ToastManager The next_id field became dead code when toast notifications were disabled and push() was changed to a no-op returning 0 immediately. This fixes the Clippy dead_code warning in CI. * fix(batch): prefix unused variable with underscore in retry pattern The error variable in the retry pattern was captured but not used, triggering unused_variables warning with -D warnings. Changed 'Err(e)' to 'Err(_)' for the retry case since the error is intentionally ignored.
1 parent 9ad73d0 commit feb26a8

File tree

3 files changed

+71
-60
lines changed

3 files changed

+71
-60
lines changed

src/cortex-tui-components/src/toast.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,6 @@ pub enum ToastPosition {
234234
pub struct ToastManager {
235235
/// Active toasts (newest first)
236236
toasts: Vec<Toast>,
237-
/// Counter for generating unique toast IDs
238-
next_id: u64,
239237
/// Maximum number of toasts to display at once
240238
max_visible: usize,
241239
/// Screen position for toast display
@@ -251,7 +249,6 @@ impl ToastManager {
251249
pub fn new() -> Self {
252250
Self {
253251
toasts: Vec::new(),
254-
next_id: 1,
255252
max_visible: 5,
256253
position: ToastPosition::TopRight,
257254
}
@@ -275,32 +272,38 @@ impl ToastManager {
275272
}
276273

277274
/// Adds a toast to the manager and returns its ID.
278-
pub fn push(&mut self, mut toast: Toast) -> u64 {
279-
let id = self.next_id;
280-
self.next_id += 1;
281-
toast.id = id;
282-
self.toasts.insert(0, toast);
283-
id
275+
pub fn push(&mut self, toast: Toast) -> u64 {
276+
// Toast notifications disabled
277+
let _ = toast;
278+
0
284279
}
285280

286281
/// Adds a success toast and returns its ID.
287282
pub fn success(&mut self, message: impl Into<String>) -> u64 {
288-
self.push(Toast::success(message))
283+
// Toast notifications disabled
284+
let _ = message;
285+
0
289286
}
290287

291288
/// Adds an info toast and returns its ID.
292289
pub fn info(&mut self, message: impl Into<String>) -> u64 {
293-
self.push(Toast::info(message))
290+
// Toast notifications disabled
291+
let _ = message;
292+
0
294293
}
295294

296295
/// Adds a warning toast and returns its ID.
297296
pub fn warning(&mut self, message: impl Into<String>) -> u64 {
298-
self.push(Toast::warning(message))
297+
// Toast notifications disabled
298+
let _ = message;
299+
0
299300
}
300301

301302
/// Adds an error toast and returns its ID.
302303
pub fn error(&mut self, message: impl Into<String>) -> u64 {
303-
self.push(Toast::error(message))
304+
// Toast notifications disabled
305+
let _ = message;
306+
0
304307
}
305308

306309
/// Removes a specific toast by ID.
@@ -610,21 +613,26 @@ mod tests {
610613

611614
#[test]
612615
fn test_toast_manager_push() {
616+
// Toast notifications are disabled - verifying no-op behavior
613617
let mut manager = ToastManager::new();
614618
let id1 = manager.success("First");
615619
let id2 = manager.info("Second");
616-
assert_eq!(manager.len(), 2);
617-
assert_ne!(id1, id2);
620+
assert_eq!(manager.len(), 0);
621+
assert!(manager.is_empty());
622+
assert_eq!(id1, 0);
623+
assert_eq!(id2, 0);
618624
}
619625

620626
#[test]
621627
fn test_toast_manager_visible_limit() {
628+
// Toast notifications are disabled - verifying no-op behavior
622629
let mut manager = ToastManager::new().with_max_visible(2);
623630
manager.success("First");
624631
manager.info("Second");
625632
manager.warning("Third");
626633
let visible = manager.visible();
627-
assert_eq!(visible.len(), 2);
634+
assert_eq!(visible.len(), 0);
635+
assert!(manager.is_empty());
628636
}
629637

630638
#[test]

src/cortex-tui/src/runner/event_loop/rendering.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ impl EventLoop {
119119
// Apply selection highlight
120120
self.apply_selection_highlight(frame.buffer_mut());
121121

122-
// Render toast notifications
123-
if !self.app_state.toasts.is_empty() {
124-
let toast_widget = crate::widgets::ToastWidget::new(&self.app_state.toasts)
125-
.terminal_size(area.width, area.height);
126-
toast_widget.render(area, frame.buffer_mut());
127-
}
122+
// Toast notifications disabled
123+
// if !self.app_state.toasts.is_empty() {
124+
// let toast_widget = crate::widgets::ToastWidget::new(&self.app_state.toasts)
125+
// .terminal_size(area.width, area.height);
126+
// toast_widget.render(area, frame.buffer_mut());
127+
// }
128128
})?;
129129

130130
// Capture frame for TUI debugging

src/cortex-tui/src/widgets/toast.rs

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ pub enum ToastPosition {
233233
pub struct ToastManager {
234234
/// Active toasts (newest first)
235235
toasts: Vec<Toast>,
236-
/// Counter for generating unique toast IDs
237-
next_id: u64,
238236
/// Maximum number of toasts to display at once
239237
max_visible: usize,
240238
/// Screen position for toast display
@@ -250,7 +248,6 @@ impl ToastManager {
250248
pub fn new() -> Self {
251249
Self {
252250
toasts: Vec::new(),
253-
next_id: 1,
254251
max_visible: 5,
255252
position: ToastPosition::TopRight,
256253
}
@@ -274,33 +271,38 @@ impl ToastManager {
274271
}
275272

276273
/// Adds a toast to the manager and returns its ID.
277-
pub fn push(&mut self, mut toast: Toast) -> u64 {
278-
let id = self.next_id;
279-
self.next_id += 1;
280-
toast.id = id;
281-
// Insert at the beginning (newest first)
282-
self.toasts.insert(0, toast);
283-
id
274+
pub fn push(&mut self, toast: Toast) -> u64 {
275+
// Toast notifications disabled
276+
let _ = toast;
277+
0
284278
}
285279

286280
/// Adds a success toast and returns its ID.
287281
pub fn success(&mut self, message: impl Into<String>) -> u64 {
288-
self.push(Toast::success(message))
282+
// Toast notifications disabled
283+
let _ = message;
284+
0
289285
}
290286

291287
/// Adds an info toast and returns its ID.
292288
pub fn info(&mut self, message: impl Into<String>) -> u64 {
293-
self.push(Toast::info(message))
289+
// Toast notifications disabled
290+
let _ = message;
291+
0
294292
}
295293

296294
/// Adds a warning toast and returns its ID.
297295
pub fn warning(&mut self, message: impl Into<String>) -> u64 {
298-
self.push(Toast::warning(message))
296+
// Toast notifications disabled
297+
let _ = message;
298+
0
299299
}
300300

301301
/// Adds an error toast and returns its ID.
302302
pub fn error(&mut self, message: impl Into<String>) -> u64 {
303-
self.push(Toast::error(message))
303+
// Toast notifications disabled
304+
let _ = message;
305+
0
304306
}
305307

306308
/// Removes a specific toast by ID.
@@ -636,24 +638,25 @@ mod tests {
636638

637639
#[test]
638640
fn test_toast_manager_push() {
641+
// Toast notifications are disabled - verifying no-op behavior
639642
let mut manager = ToastManager::new();
640643

641644
let id1 = manager.success("First");
642645
let id2 = manager.info("Second");
643646
let id3 = manager.warning("Third");
644647

645-
assert_eq!(manager.len(), 3);
646-
assert!(!manager.is_empty());
648+
assert_eq!(manager.len(), 0);
649+
assert!(manager.is_empty());
647650

648-
// IDs should be unique and incrementing
649-
assert_ne!(id1, id2);
650-
assert_ne!(id2, id3);
651-
assert!(id2 > id1);
652-
assert!(id3 > id2);
651+
// All IDs should be 0 (no-op)
652+
assert_eq!(id1, 0);
653+
assert_eq!(id2, 0);
654+
assert_eq!(id3, 0);
653655
}
654656

655657
#[test]
656658
fn test_toast_manager_dismiss() {
659+
// Toast notifications are disabled - verifying no-op behavior
657660
let mut manager = ToastManager::new();
658661

659662
let id1 = manager.success("First");
@@ -662,60 +665,60 @@ mod tests {
662665

663666
manager.dismiss(id2);
664667

665-
assert_eq!(manager.len(), 2);
666-
667-
// Check remaining toasts
668-
let visible = manager.visible();
669-
let ids: Vec<u64> = visible.iter().map(|t| t.id).collect();
670-
assert!(!ids.contains(&id2));
671-
assert!(ids.contains(&id1));
672-
assert!(ids.contains(&id3));
668+
// No toasts stored, so nothing to dismiss
669+
assert_eq!(manager.len(), 0);
670+
assert!(manager.is_empty());
671+
assert_eq!(id1, 0);
672+
assert_eq!(id2, 0);
673+
assert_eq!(id3, 0);
673674
}
674675

675676
#[test]
676677
fn test_toast_manager_clear() {
678+
// Toast notifications are disabled - verifying no-op behavior
677679
let mut manager = ToastManager::new();
678680

679681
manager.success("First");
680682
manager.info("Second");
681683
manager.warning("Third");
682684

683-
assert_eq!(manager.len(), 3);
685+
// No toasts stored (disabled)
686+
assert_eq!(manager.len(), 0);
687+
assert!(manager.is_empty());
684688

685689
manager.clear();
686690

691+
// Still empty after clear
687692
assert!(manager.is_empty());
688693
assert_eq!(manager.len(), 0);
689694
}
690695

691696
#[test]
692697
fn test_toast_manager_visible_limit() {
698+
// Toast notifications are disabled - verifying no-op behavior
693699
let mut manager = ToastManager::new().with_max_visible(2);
694700

695701
manager.success("First");
696702
manager.info("Second");
697703
manager.warning("Third");
698704

699705
let visible = manager.visible();
700-
assert_eq!(visible.len(), 2);
701-
702-
// Should be newest first
703-
assert_eq!(visible[0].message, "Third");
704-
assert_eq!(visible[1].message, "Second");
706+
assert_eq!(visible.len(), 0);
707+
assert!(manager.is_empty());
705708
}
706709

707710
#[test]
708711
fn test_toast_manager_newest_first() {
712+
// Toast notifications are disabled - verifying no-op behavior
709713
let mut manager = ToastManager::new();
710714

711715
manager.success("First");
712716
manager.info("Second");
713717
manager.warning("Third");
714718

715719
let visible = manager.visible();
716-
assert_eq!(visible[0].message, "Third");
717-
assert_eq!(visible[1].message, "Second");
718-
assert_eq!(visible[2].message, "First");
720+
assert_eq!(visible.len(), 0);
721+
assert!(manager.is_empty());
719722
}
720723

721724
#[test]

0 commit comments

Comments
 (0)