intelli_shell/widgets/items/
command.rs

1use std::ops::{Deref, DerefMut};
2
3use ratatui::layout::Size;
4
5use crate::{
6    config::Theme,
7    model::Command,
8    widgets::{CommandWidget, CustomListItem},
9};
10
11/// Wrapper around `Command` to be rendered on a plain style
12#[derive(Clone)]
13pub struct PlainStyleCommand(Command);
14
15impl CustomListItem for Command {
16    type Widget<'w> = CommandWidget<'w>;
17
18    fn as_widget<'a>(
19        &'a self,
20        theme: &Theme,
21        inline: bool,
22        is_highlighted: bool,
23        is_discarded: bool,
24    ) -> (Self::Widget<'a>, Size) {
25        let widget = CommandWidget::new(self, theme, inline, is_highlighted, is_discarded, false);
26        let size = widget.size();
27        (widget, size)
28    }
29}
30
31impl CustomListItem for PlainStyleCommand {
32    type Widget<'w> = CommandWidget<'w>;
33
34    fn as_widget<'a>(
35        &'a self,
36        theme: &Theme,
37        inline: bool,
38        is_highlighted: bool,
39        is_discarded: bool,
40    ) -> (Self::Widget<'a>, Size) {
41        let widget = CommandWidget::new(self, theme, inline, is_highlighted, is_discarded, true);
42        let size = widget.size();
43        (widget, size)
44    }
45}
46
47impl Deref for PlainStyleCommand {
48    type Target = Command;
49
50    fn deref(&self) -> &Self::Target {
51        &self.0
52    }
53}
54impl DerefMut for PlainStyleCommand {
55    fn deref_mut(&mut self) -> &mut Self::Target {
56        &mut self.0
57    }
58}
59impl From<Command> for PlainStyleCommand {
60    fn from(value: Command) -> Self {
61        PlainStyleCommand(value)
62    }
63}
64impl From<PlainStyleCommand> for Command {
65    fn from(value: PlainStyleCommand) -> Self {
66        value.0
67    }
68}