Render the model selector popup as an overlay
(&mut self, frame: &mut Frame, area: Rect, theme: &Theme)
| 109 | |
| 110 | /// Render the model selector popup as an overlay |
| 111 | pub fn render(&mut self, frame: &mut Frame, area: Rect, theme: &Theme) { |
| 112 | if !self.visible || self.items.is_empty() { |
| 113 | self.last_area = None; |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | // Calculate popup area (centered, leaving some margin) |
| 118 | let popup_width = area.width.saturating_sub(4).min(70); |
| 119 | let popup_height = (self.items.len() as u16 + 4).min(area.height.saturating_sub(2)); |
| 120 | if popup_height < 5 || popup_width < 20 { |
| 121 | self.last_area = None; |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | let popup_x = area.x + (area.width.saturating_sub(popup_width)) / 2; |
| 126 | let popup_y = area.y + (area.height.saturating_sub(popup_height)) / 2; |
| 127 | |
| 128 | let popup_area = Rect { |
| 129 | x: popup_x, |
| 130 | y: popup_y, |
| 131 | width: popup_width, |
| 132 | height: popup_height, |
| 133 | }; |
| 134 | self.last_area = Some(popup_area); |
| 135 | |
| 136 | // Build list items |
| 137 | let list_items: Vec<ListItem> = self |
| 138 | .items |
| 139 | .iter() |
| 140 | .map(|model| { |
| 141 | let is_current = self |
| 142 | .current_model_id |
| 143 | .as_ref() |
| 144 | .map_or(false, |id| id == &model.id); |
| 145 | |
| 146 | let marker = if is_current { "● " } else { " " }; |
| 147 | let marker_style = if is_current { |
| 148 | theme.style(StyleKind::Success) |
| 149 | } else { |
| 150 | theme.style(StyleKind::Muted) |
| 151 | }; |
| 152 | |
| 153 | let name_style = theme.style(StyleKind::Primary).add_modifier(Modifier::BOLD); |
| 154 | let detail_style = theme.style(StyleKind::Muted); |
| 155 | |
| 156 | let line = Line::from(vec![ |
| 157 | Span::styled(marker, marker_style), |
| 158 | Span::styled(&model.name, name_style), |
| 159 | Span::raw(" "), |
| 160 | Span::styled( |
| 161 | format!("[{}/{}]", model.provider, model.model_name), |
| 162 | detail_style, |
| 163 | ), |
| 164 | ]); |
| 165 | ListItem::new(line) |
| 166 | }) |
| 167 | .collect(); |
| 168 |