intelli_shell/widgets/items/
import_export.rs1use ratatui::layout::Size;
2
3use crate::{
4 config::Theme,
5 model::ImportExportItem,
6 widgets::{
7 CustomListItem, ImportExportItemWidget,
8 items::{PlainStyleCommand, PlainStyleVariableCompletion},
9 },
10};
11
12#[derive(Clone)]
14pub enum PlainStyleImportExportItem {
15 Command(PlainStyleCommand),
16 Completion(PlainStyleVariableCompletion),
17}
18
19impl CustomListItem for PlainStyleImportExportItem {
20 type Widget<'w> = ImportExportItemWidget<'w>;
21
22 fn as_widget<'a>(
23 &'a self,
24 theme: &Theme,
25 inline: bool,
26 is_highlighted: bool,
27 is_discarded: bool,
28 ) -> (Self::Widget<'a>, Size) {
29 match self {
30 PlainStyleImportExportItem::Command(command) => {
31 let (widget, size) = command.as_widget(theme, inline, is_highlighted, is_discarded);
32 (ImportExportItemWidget::Command(widget), size)
33 }
34 PlainStyleImportExportItem::Completion(completion) => {
35 let (widget, size) = completion.as_widget(theme, inline, is_highlighted, is_discarded);
36 (ImportExportItemWidget::Completion(widget), size)
37 }
38 }
39 }
40}
41
42impl From<ImportExportItem> for PlainStyleImportExportItem {
43 fn from(value: ImportExportItem) -> Self {
44 match value {
45 ImportExportItem::Command(command) => Self::Command(command.into()),
46 ImportExportItem::Completion(completion) => Self::Completion(completion.into()),
47 }
48 }
49}
50impl From<PlainStyleImportExportItem> for ImportExportItem {
51 fn from(value: PlainStyleImportExportItem) -> Self {
52 match value {
53 PlainStyleImportExportItem::Command(command) => Self::Command(command.into()),
54 PlainStyleImportExportItem::Completion(completion) => Self::Completion(completion.into()),
55 }
56 }
57}