ratatui_command_palette/render/
fullscreen.rs1use ratatui::buffer::Buffer;
2use ratatui::layout::{Constraint, Direction, Layout, Rect};
3use ratatui::style::{Color, Modifier, Style};
4use ratatui::text::{Line, Span};
5use ratatui::widgets::{Clear, Paragraph, Widget};
6
7use super::PaletteRenderer;
8use super::parts::{render_footer, render_query, render_rows};
9use crate::view::PaletteView;
10
11#[derive(Clone, Debug)]
20pub struct FullscreenRenderer {
21 title: String,
22}
23
24impl Default for FullscreenRenderer {
25 fn default() -> Self {
26 Self::new()
27 }
28}
29
30impl FullscreenRenderer {
31 pub fn new() -> Self {
33 Self {
34 title: "Command Palette".into(),
35 }
36 }
37
38 pub fn title(mut self, title: impl Into<String>) -> Self {
50 self.title = title.into();
51 self
52 }
53}
54
55impl PaletteRenderer for FullscreenRenderer {
56 fn render(&self, area: Rect, buf: &mut Buffer, view: &PaletteView) {
57 Clear.render(area, buf);
58
59 let sections = Layout::default()
60 .direction(Direction::Vertical)
61 .constraints([
62 Constraint::Length(2),
63 Constraint::Length(1),
64 Constraint::Min(0),
65 Constraint::Length(1),
66 ])
67 .split(area);
68
69 let title = Line::from(vec![
70 Span::styled(
71 self.title.as_str(),
72 Style::new().fg(Color::Cyan).add_modifier(Modifier::BOLD),
73 ),
74 Span::raw(" "),
75 Span::styled("fullscreen", Style::new().fg(Color::DarkGray)),
76 ]);
77 Paragraph::new(title).render(sections[0], buf);
78 render_query(sections[1], buf, view);
79 render_rows(sections[2], buf, view);
80 render_footer(sections[3], buf, view);
81 }
82}