From 03451ae1f5d39e5c4226133879dc2563b19b5cb3 Mon Sep 17 00:00:00 2001 From: Stan Fateev Date: Thu, 30 May 2024 16:50:23 +0100 Subject: [PATCH] Feature #781 menubar to render styledstrings (#784) * bump enumset verstion to 1.1.0 * add menubar's ability to render styledstrings * create example how to use * add record to the examples/Readme.md * add tests * small refactoring --------- Co-authored-by: Alexandre Bury --- cursive-core/Cargo.toml | 2 +- cursive-core/src/menu.rs | 83 +++++++++++++++++++++++++++++- cursive-core/src/utils/span.rs | 31 +++++++++++ cursive-core/src/views/menubar.rs | 23 +++++---- cursive/examples/Readme.md | 4 ++ cursive/examples/menubar_styles.rs | 55 ++++++++++++++++++++ 6 files changed, 186 insertions(+), 12 deletions(-) create mode 100644 cursive/examples/menubar_styles.rs diff --git a/cursive-core/Cargo.toml b/cursive-core/Cargo.toml index 0e6525ce..68558f5f 100644 --- a/cursive-core/Cargo.toml +++ b/cursive-core/Cargo.toml @@ -23,7 +23,7 @@ repository = "gyscos/cursive" [dependencies] enum-map = "2.0" -enumset = "1.0.4" +enumset = "1.1.0" log = "0.4" unicode-segmentation = "1" unicode-width = "0.1" diff --git a/cursive-core/src/menu.rs b/cursive-core/src/menu.rs index d2bdb216..e5ed3767 100644 --- a/cursive-core/src/menu.rs +++ b/cursive-core/src/menu.rs @@ -13,9 +13,26 @@ //! [`Tree`]: struct.Tree.html //! [menubar]: ../struct.Cursive.html#method.menubar -use crate::{event::Callback, utils::markup::StyledString, Cursive, With}; +use crate::utils::span::{IndexedCow, IndexedSpan, SpannedStr}; +use crate::{ + event::Callback, theme::ColorStyle, theme::ColorType, theme::Style, + utils::markup::StyledString, Cursive, With, +}; +use enumset::EnumSet; use std::sync::Arc; +const PLAIN_1CHAR_SPAN: &'static [IndexedSpan