Skip to content

Commit

Permalink
Add SelectView::add_item_styled
Browse files Browse the repository at this point in the history
  • Loading branch information
gyscos committed Jun 17, 2024
1 parent c173bbf commit 778bec7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cursive-core/src/views/select_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,20 @@ impl SelectView<String> {
self.add_item(label.clone(), label);
}

/// Chainable variant of add_item_str
/// Convenient method to use the label unstyled text as value.
pub fn add_item_styled<S: Into<StyledString>>(&mut self, label: S) {
let label = label.into();

// Accumulate the content of each span.
let mut content = String::new();
for span in label.spans() {
content.push_str(span.content);
}

self.add_item(label, content);
}

/// Chainable variant of `add_item_str`.
///
/// # Examples
///
Expand All @@ -855,6 +868,12 @@ impl SelectView<String> {
self.with(|s| s.add_item_str(label))
}

/// Chainable variant of `add_item_styled`.
#[must_use]
pub fn item_styled<S: Into<StyledString>>(self, label: S) -> Self {
self.with(|s| s.add_item_styled(label))
}

/// Convenient method to use the label as value.
pub fn insert_item_str<S>(&mut self, index: usize, label: S)
where
Expand Down

0 comments on commit 778bec7

Please sign in to comment.