intelli_shell/widgets/
new_version.rs

1use ratatui::{prelude::*, style::Style, widgets::Clear};
2use semver::Version;
3
4use crate::config::Theme;
5
6/// A banner widget that displays a message about a new version of the application
7#[derive(Clone)]
8pub struct NewVersionBanner {
9    style: Style,
10    new_version: Version,
11}
12
13impl NewVersionBanner {
14    /// Creates a new [`NewVersionBanner`]
15    pub fn new(theme: &Theme, new_version: Version) -> Self {
16        Self {
17            style: theme.accent.into(),
18            new_version,
19        }
20    }
21
22    /// Renders the new version message popup within the given area.
23    ///
24    /// The message is displayed as an overlay on the last line of the specified `area`.
25    pub fn render_in(&mut self, frame: &mut Frame, area: Rect) {
26        // Render the new version message as an overlay
27        let error_overlay_rect = Rect {
28            x: area.x,
29            y: area.bottom() - 1,
30            width: area.width,
31            height: 1,
32        };
33
34        let message = format!(
35            "🚀 New Version Available: {} → {}",
36            env!("CARGO_PKG_VERSION"),
37            self.new_version
38        );
39        let text = Line::from(message).centered().style(self.style);
40
41        // Clear the area behind it and render it
42        frame.render_widget(Clear, error_overlay_rect);
43        frame.render_widget(text, error_overlay_rect);
44    }
45}