Skip to main content

tau_cli_picker/
item.rs

1/// One selectable row shown by the terminal picker.
2#[derive(Clone, Debug)]
3pub struct PickerItem {
4    /// Text rendered for this row.
5    label: String,
6    /// Whether the cursor can land on and select this row.
7    enabled: bool,
8}
9
10impl PickerItem {
11    /// Creates a row that can be selected.
12    pub fn enabled(label: impl Into<String>) -> Self {
13        Self {
14            label: label.into(),
15            enabled: true,
16        }
17    }
18
19    /// Creates a disabled row that is shown but skipped by navigation.
20    pub fn disabled(label: impl Into<String>) -> Self {
21        Self {
22            label: label.into(),
23            enabled: false,
24        }
25    }
26
27    /// Returns the text rendered for this row.
28    pub fn label(&self) -> &str {
29        &self.label
30    }
31
32    /// Returns whether the cursor can land on and select this row.
33    pub fn is_enabled(&self) -> bool {
34        self.enabled
35    }
36}