intelli_shell/widgets/items/
completion.rs

1use std::ops::{Deref, DerefMut};
2
3use ratatui::layout::Size;
4
5use crate::{
6    config::Theme,
7    model::VariableCompletion,
8    widgets::{CustomListItem, VariableCompletionWidget},
9};
10
11/// Wrapper around `VariableCompletion` to be rendered on a plain style
12#[derive(Clone)]
13pub struct PlainStyleVariableCompletion(VariableCompletion);
14
15impl CustomListItem for VariableCompletion {
16    type Widget<'w> = VariableCompletionWidget<'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 = VariableCompletionWidget::new(self, theme, is_highlighted, is_discarded, false, false);
26        let size = widget.size();
27        (widget, size)
28    }
29}
30
31impl CustomListItem for PlainStyleVariableCompletion {
32    type Widget<'w> = VariableCompletionWidget<'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 = VariableCompletionWidget::new(self, theme, is_highlighted, is_discarded, true, true);
42        let size = widget.size();
43        (widget, size)
44    }
45}
46
47impl Deref for PlainStyleVariableCompletion {
48    type Target = VariableCompletion;
49
50    fn deref(&self) -> &Self::Target {
51        &self.0
52    }
53}
54impl DerefMut for PlainStyleVariableCompletion {
55    fn deref_mut(&mut self) -> &mut Self::Target {
56        &mut self.0
57    }
58}
59impl From<VariableCompletion> for PlainStyleVariableCompletion {
60    fn from(value: VariableCompletion) -> Self {
61        PlainStyleVariableCompletion(value)
62    }
63}
64impl From<PlainStyleVariableCompletion> for VariableCompletion {
65    fn from(value: PlainStyleVariableCompletion) -> Self {
66        value.0
67    }
68}