Skip to content

Commit 7c6d932

Browse files
echobtfactorydroid
andauthored
fix: resolve compilation errors in cortex-tui-components and cortex-agents (#472)
- Implement Widget trait for &Toast to enable standalone rendering - Add tab() method alias on Navbar for backward compatibility - Fix unused_mut warnings in cortex-agents test code - Apply cargo fmt formatting to modified files Co-authored-by: Droid Agent <droid@factory.ai>
1 parent 66197cd commit 7c6d932

17 files changed

Lines changed: 431 additions & 206 deletions

File tree

cortex-agents/src/background/messaging.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ mod tests {
501501

502502
#[tokio::test]
503503
async fn test_mailbox_send_receive() {
504-
let (mut mailbox1, mut mailbox2) = create_connected_mailboxes();
504+
let (mailbox1, mut mailbox2) = create_connected_mailboxes();
505505

506506
// Send from 1 to 2
507507
mailbox1
@@ -579,7 +579,7 @@ mod tests {
579579

580580
#[tokio::test]
581581
async fn test_drain_messages() {
582-
let (mut mailbox1, _mailbox2) = create_connected_mailboxes();
582+
let (_mailbox1, _mailbox2) = create_connected_mailboxes();
583583

584584
// Send multiple messages (these go to mailbox2's rx which is mailbox1's tx in test setup)
585585
// The cross-connected test setup means we need to receive from the right side

cortex-agents/src/spec/transition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ mod tests {
208208
#[test]
209209
fn test_apply_with_plan() {
210210
let plan = SpecPlan::new("Feature X").with_summary("Implement feature X");
211-
let mut transition = ModeTransition::spec_to_build(plan);
211+
let transition = ModeTransition::spec_to_build(plan);
212212

213213
let result = transition.apply("Base prompt");
214214

cortex-tui-components/src/color_scheme.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ impl ColorScheme {
109109
}
110110

111111
/// Creates a color scheme with custom status colors.
112-
pub fn with_status(mut self, success: Color, warning: Color, error: Color, info: Color) -> Self {
112+
pub fn with_status(
113+
mut self,
114+
success: Color,
115+
warning: Color,
116+
error: Color,
117+
info: Color,
118+
) -> Self {
113119
self.success = success;
114120
self.warning = warning;
115121
self.error = error;

cortex-tui-components/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,11 @@ pub mod prelude {
152152
pub use crate::input::{InputState, TextInput};
153153
pub use crate::key_hints::{KeyHint, KeyHintsBar};
154154
pub use crate::list::{ListItem, ScrollableList};
155-
pub use crate::mascot::{MascotExpression, MASCOT, MASCOT_MINIMAL, MASCOT_MINIMAL_LINES};
155+
pub use crate::mascot::{MASCOT, MASCOT_MINIMAL, MASCOT_MINIMAL_LINES, MascotExpression};
156156
pub use crate::modal::{Modal, ModalAction, ModalBuilder, ModalResult, ModalStack};
157+
pub use crate::page_layout::{
158+
Badge, InfoItem, InfoSection, NavItem, Navbar, PageHeader, PageLayout, PageTab,
159+
};
157160
pub use crate::panel::{Panel, PanelPosition};
158161
pub use crate::popup::{Popup, PopupPosition};
159162
pub use crate::radio::{RadioGroup, RadioItem};
@@ -164,7 +167,6 @@ pub mod prelude {
164167
pub use crate::text::{StyledText, TextStyle};
165168
pub use crate::toast::{Toast, ToastLevel, ToastManager, ToastPosition, ToastWidget};
166169
pub use crate::welcome_card::{InfoCard, InfoCardPair, ToLines, WelcomeCard};
167-
pub use crate::page_layout::{Badge, InfoItem, InfoSection, NavItem, Navbar, PageHeader, PageLayout, PageTab};
168170
}
169171

170172
// Re-export cortex-core style for convenience

cortex-tui-components/src/mascot.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,8 @@ pub const MASCOT_MINIMAL: &str = r#" ▄█▀▀▀▀█▄
8686
█ █"#;
8787

8888
/// Minimal mascot lines for inline rendering (12 chars wide each).
89-
pub const MASCOT_MINIMAL_LINES: [&str; 4] = [
90-
" ▄█▀▀▀▀█▄ ",
91-
"██ ▌ ▐ ██ ",
92-
" █▄▄▄▄▄▄█ ",
93-
" █ █ ",
94-
];
89+
pub const MASCOT_MINIMAL_LINES: [&str; 4] =
90+
[" ▄█▀▀▀▀█▄ ", "██ ▌ ▐ ██ ", " █▄▄▄▄▄▄█ ", " █ █ "];
9591

9692
/// Mascot sparkle (special).
9793
pub const MASCOT_SPARKLE: &str = r#" ✦ ░▒▓████▓▒░ ✦

cortex-tui-components/src/page_layout.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,21 @@ impl Navbar {
9898
self
9999
}
100100

101+
/// Alias for `item()` for backward compatibility.
102+
pub fn tab(self, label: impl Into<String>, active: bool) -> Self {
103+
self.item(label, active)
104+
}
105+
101106
pub fn to_line(&self) -> Line<'static> {
102107
let mut spans: Vec<Span<'static>> = Vec::new();
103-
108+
104109
spans.push(Span::raw(" "));
105-
110+
106111
for (i, item) in self.items.iter().enumerate() {
107112
if i > 0 {
108113
spans.push(Span::styled(" ", Style::default().fg(TEXT_DIM)));
109114
}
110-
115+
111116
if item.active {
112117
spans.push(Span::styled(
113118
format!(" {} ", item.label),
@@ -186,23 +191,20 @@ impl InfoItem {
186191

187192
pub fn to_line(&self) -> Line<'static> {
188193
let mut spans: Vec<Span<'static>> = Vec::new();
189-
194+
190195
spans.push(Span::raw(" "));
191-
196+
192197
if let Some(icon) = self.icon {
193-
spans.push(Span::styled(
194-
format!("{} ", icon),
195-
self.value_style,
196-
));
198+
spans.push(Span::styled(format!("{} ", icon), self.value_style));
197199
}
198-
200+
199201
if !self.label.is_empty() {
200202
spans.push(Span::styled(
201203
format!("{}: ", self.label),
202204
Style::default().fg(TEXT_DIM),
203205
));
204206
}
205-
207+
206208
spans.push(Span::styled(self.value.clone(), self.value_style));
207209

208210
Line::from(spans)
@@ -331,10 +333,7 @@ impl PageLayout {
331333

332334
// Top border (only if enabled)
333335
if self.show_top_border {
334-
lines.push(Line::from(Span::styled(
335-
"─".repeat(w),
336-
border_style,
337-
)));
336+
lines.push(Line::from(Span::styled("─".repeat(w), border_style)));
338337
}
339338

340339
// Navbar
@@ -363,10 +362,7 @@ impl PageLayout {
363362

364363
// Bottom border (only if enabled)
365364
if self.show_bottom_border {
366-
lines.push(Line::from(Span::styled(
367-
"─".repeat(w),
368-
border_style,
369-
)));
365+
lines.push(Line::from(Span::styled("─".repeat(w), border_style)));
370366
}
371367

372368
lines
@@ -382,7 +378,7 @@ impl Default for PageLayout {
382378
impl Widget for PageLayout {
383379
fn render(self, area: Rect, buf: &mut Buffer) {
384380
let lines = self.to_lines(area.width);
385-
381+
386382
for (i, line) in lines.iter().enumerate() {
387383
if i as u16 >= area.height {
388384
break;

cortex-tui-components/src/selection_list.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,11 @@ impl SelectionList {
507507
let (bg, fg, prefix_fg) = if is_selected {
508508
(self.colors.accent, self.colors.void, self.colors.void)
509509
} else if item.disabled {
510-
(self.colors.surface, self.colors.text_muted, self.colors.text_muted)
510+
(
511+
self.colors.surface,
512+
self.colors.text_muted,
513+
self.colors.text_muted,
514+
)
511515
} else {
512516
(self.colors.surface, self.colors.text, self.colors.accent)
513517
};
@@ -614,7 +618,14 @@ impl SelectionList {
614618
}
615619

616620
let x = area.x + 1;
617-
buf.set_string(x, area.y, "/", Style::default().fg(self.colors.accent).bg(self.colors.surface_alt));
621+
buf.set_string(
622+
x,
623+
area.y,
624+
"/",
625+
Style::default()
626+
.fg(self.colors.accent)
627+
.bg(self.colors.surface_alt),
628+
);
618629

619630
let max_query_width = (area.width as usize).saturating_sub(15);
620631
let display_text = if self.search_query.is_empty() {
@@ -630,9 +641,13 @@ impl SelectionList {
630641
};
631642

632643
let text_style = if self.search_query.is_empty() {
633-
Style::default().fg(self.colors.text_muted).bg(self.colors.surface_alt)
644+
Style::default()
645+
.fg(self.colors.text_muted)
646+
.bg(self.colors.surface_alt)
634647
} else {
635-
Style::default().fg(self.colors.text).bg(self.colors.surface_alt)
648+
Style::default()
649+
.fg(self.colors.text)
650+
.bg(self.colors.surface_alt)
636651
};
637652

638653
buf.set_string(x + 2, area.y, &display_text, text_style);
@@ -650,7 +665,9 @@ impl SelectionList {
650665
count_x,
651666
area.y,
652667
&count_str,
653-
Style::default().fg(self.colors.text_dim).bg(self.colors.surface_alt),
668+
Style::default()
669+
.fg(self.colors.text_dim)
670+
.bg(self.colors.surface_alt),
654671
);
655672
}
656673
}
@@ -663,8 +680,12 @@ mod tests {
663680
fn create_test_items() -> Vec<SelectionItem> {
664681
vec![
665682
SelectionItem::new("Apple").with_shortcut('a'),
666-
SelectionItem::new("Banana").with_shortcut('b').with_current(true),
667-
SelectionItem::new("Cherry").with_shortcut('c').with_default(true),
683+
SelectionItem::new("Banana")
684+
.with_shortcut('b')
685+
.with_current(true),
686+
SelectionItem::new("Cherry")
687+
.with_shortcut('c')
688+
.with_default(true),
668689
SelectionItem::new("Date").with_disabled(true, Some("Not available".to_string())),
669690
SelectionItem::new("Elderberry").with_description("A tasty berry"),
670691
]

cortex-tui-components/src/toast.rs

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,22 @@ impl<'a> ToastWidget<'a> {
411411
}
412412

413413
if x < buf.area.width {
414-
buf.set_string(x, y, "|", Style::default().fg(faded_color).bg(self.colors.surface_alt));
414+
buf.set_string(
415+
x,
416+
y,
417+
"|",
418+
Style::default().fg(faded_color).bg(self.colors.surface_alt),
419+
);
415420
}
416421

417422
let icon_x = x + 2;
418423
if icon_x + 3 < buf.area.width {
419-
buf.set_string(icon_x, y, icon, Style::default().fg(faded_color).bg(self.colors.surface_alt));
424+
buf.set_string(
425+
icon_x,
426+
y,
427+
icon,
428+
Style::default().fg(faded_color).bg(self.colors.surface_alt),
429+
);
420430
}
421431

422432
let msg_x = x + 6;
@@ -431,12 +441,22 @@ impl<'a> ToastWidget<'a> {
431441
} else {
432442
toast.message.clone()
433443
};
434-
buf.set_string(msg_x, y, &message, Style::default().fg(faded_text).bg(self.colors.surface_alt));
444+
buf.set_string(
445+
msg_x,
446+
y,
447+
&message,
448+
Style::default().fg(faded_text).bg(self.colors.surface_alt),
449+
);
435450
}
436451

437452
let right_x = x + width.saturating_sub(1);
438453
if right_x < buf.area.width {
439-
buf.set_string(right_x, y, "|", Style::default().fg(faded_color).bg(self.colors.surface_alt));
454+
buf.set_string(
455+
right_x,
456+
y,
457+
"|",
458+
Style::default().fg(faded_color).bg(self.colors.surface_alt),
459+
);
440460
}
441461
}
442462
}
@@ -505,6 +525,77 @@ fn lerp(start: f32, end: f32, t: f32) -> f32 {
505525
start + (end - start) * t
506526
}
507527

528+
// ============================================================
529+
// WIDGET IMPL FOR TOAST (standalone rendering)
530+
// ============================================================
531+
532+
impl Widget for &Toast {
533+
fn render(self, area: Rect, buf: &mut Buffer) {
534+
if area.width < 5 || area.height < 1 {
535+
return;
536+
}
537+
538+
let scheme = ColorScheme::default();
539+
let color = self.level.color(&scheme);
540+
let icon = self.level.icon();
541+
542+
// Render: | [icon] message |
543+
let mut x = area.x;
544+
545+
// Left border
546+
if x < area.right() {
547+
buf.set_string(x, area.y, "|", Style::default().fg(color));
548+
x += 1;
549+
}
550+
551+
// Space
552+
if x < area.right() {
553+
buf.set_string(x, area.y, " ", Style::default());
554+
x += 1;
555+
}
556+
557+
// Icon
558+
let icon_len = icon.len() as u16;
559+
if x + icon_len <= area.right() {
560+
buf.set_string(x, area.y, icon, Style::default().fg(color));
561+
x += icon_len;
562+
}
563+
564+
// Space
565+
if x < area.right() {
566+
buf.set_string(x, area.y, " ", Style::default());
567+
x += 1;
568+
}
569+
570+
// Message (truncated if needed)
571+
let remaining_width = area.right().saturating_sub(x + 2) as usize; // -2 for " |" at end
572+
if remaining_width > 0 {
573+
let msg = if self.message.len() > remaining_width {
574+
if remaining_width > 3 {
575+
format!("{}...", &self.message[..remaining_width - 3])
576+
} else {
577+
self.message.chars().take(remaining_width).collect()
578+
}
579+
} else {
580+
self.message.clone()
581+
};
582+
buf.set_string(x, area.y, &msg, Style::default().fg(scheme.text));
583+
x += msg.len() as u16;
584+
}
585+
586+
// Padding to right border
587+
while x < area.right().saturating_sub(1) {
588+
buf.set_string(x, area.y, " ", Style::default());
589+
x += 1;
590+
}
591+
592+
// Right border
593+
if x < area.right() {
594+
buf.set_string(x, area.y, "|", Style::default().fg(color));
595+
}
596+
}
597+
}
598+
508599
#[cfg(test)]
509600
mod tests {
510601
use super::*;

0 commit comments

Comments
 (0)