From 2399023db308edba9e1edc694df09a60255dcb23 Mon Sep 17 00:00:00 2001
From: veeso
Date: Mon, 2 Aug 2021 22:22:36 +0200
Subject: [PATCH] tui-realm 0.5.0 compatibility
---
CHANGELOG.md | 7 +++++
Cargo.toml | 6 ++---
README.md | 6 ++---
examples/demo.rs | 10 +++----
src/lib.rs | 70 +++++++++++++++++++++++++++++++-----------------
5 files changed, 63 insertions(+), 36 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 37bdaa0..fb1752f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,12 +1,19 @@
# Changelog
- [Changelog](#changelog)
+ - [0.2.1](#021)
- [0.2.0](#020)
- [0.1.1](#011)
- [0.1.0](#010)
---
+## 0.2.1
+
+Released on 02/08/2021
+
+- tui-realm 0.5.1 compatibility
+
## 0.2.0
Released on 07/06/2021
diff --git a/Cargo.toml b/Cargo.toml
index c25a96c..07fc5ab 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "tui-realm-treeview"
-version = "0.2.0"
+version = "0.2.1"
authors = ["Christian Visintin"]
edition = "2018"
categories = ["command-line-utilities"]
@@ -14,13 +14,13 @@ readme = "README.md"
repository = "https://github.com/veeso/tui-realm-treeview"
[dependencies]
-tuirealm = "^0.4.0"
+tuirealm = "0.5.1"
tui-tree-widget = "^0.6.0"
[dev-dependencies]
crossterm = "0.19.0"
pretty_assertions = "0.7.2"
-tuirealm = { version = "^0.4.0", features = [ "with-components" ] }
+tui-realm-stdlib = "0.5.0"
[[example]]
name = "demo"
diff --git a/README.md b/README.md
index a1570d5..aa53c0a 100644
--- a/README.md
+++ b/README.md
@@ -4,12 +4,12 @@
-[![License: MIT](https://img.shields.io/badge/License-MIT-teal.svg)](https://opensource.org/licenses/MIT) [![Stars](https://img.shields.io/github/stars/veeso/tui-realm-treeview.svg)](https://github.com/veeso/tui-realm-treeview) [![Downloads](https://img.shields.io/crates/d/tui-realm-treeview.svg)](https://crates.io/crates/tui-realm-treeview) [![Crates.io](https://img.shields.io/badge/crates.io-v0.2.0-orange.svg)](https://crates.io/crates/tui-realm-treeview) [![Docs](https://docs.rs/tui-realm-treeview/badge.svg)](https://docs.rs/tui-realm-treeview)
+[![License: MIT](https://img.shields.io/badge/License-MIT-teal.svg)](https://opensource.org/licenses/MIT) [![Stars](https://img.shields.io/github/stars/veeso/tui-realm-treeview.svg)](https://github.com/veeso/tui-realm-treeview) [![Downloads](https://img.shields.io/crates/d/tui-realm-treeview.svg)](https://crates.io/crates/tui-realm-treeview) [![Crates.io](https://img.shields.io/badge/crates.io-v0.2.1-orange.svg)](https://crates.io/crates/tui-realm-treeview) [![Docs](https://docs.rs/tui-realm-treeview/badge.svg)](https://docs.rs/tui-realm-treeview)
[![Build](https://github.com/veeso/tui-realm-treeview/workflows/Linux/badge.svg)](https://github.com/veeso/tui-realm-treeview/actions) [![Build](https://github.com/veeso/tui-realm-treeview/workflows/MacOS/badge.svg)](https://github.com/veeso/tui-realm-treeview/actions) [![Build](https://github.com/veeso/tui-realm-treeview/workflows/Windows/badge.svg)](https://github.com/veeso/tui-realm-treeview/actions) [![Coverage Status](https://coveralls.io/repos/github/veeso/tui-realm-treeview/badge.svg?branch=main)](https://coveralls.io/github/veeso/tui-realm-treeview?branch=main)
Developed by Christian Visintin
-Current version: 0.2.0 (07/06/2021)
+Current version: 0.2.1 (02/08/2021)
---
@@ -41,7 +41,7 @@ tui-realm-treeview is an implementation of a **treeview component** for [tui-rea
### Add tui-realm-treeview to your Cargo.toml 🦀
```toml
-tui-realm-treeview = "0.2.0"
+tui-realm-treeview = "0.2.1"
```
### Use the treeview component
diff --git a/examples/demo.rs b/examples/demo.rs
index 6707732..0c69aae 100644
--- a/examples/demo.rs
+++ b/examples/demo.rs
@@ -28,7 +28,7 @@ use utils::keymap::*;
use std::path::{Path, PathBuf};
use std::thread::sleep;
use std::time::Duration;
-use tuirealm::components::{input, label};
+use tui_realm_stdlib::{input, label};
use tuirealm::props::borders::{BorderType, Borders};
use tuirealm::{Msg, Payload, PropsBuilder, Update, Value, View};
// tui
@@ -158,7 +158,7 @@ fn main() {
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightYellow)
.with_foreground(Color::LightYellow)
.with_background(Color::Black)
- .with_title(Some(title))
+ .with_title(title)
.with_tree(model.tree.root())
.with_highlighted_str("🚀")
.keep_state(true)
@@ -240,7 +240,7 @@ impl Update for Model {
self.view.get_props(COMPONENT_TREEVIEW).unwrap(),
)
.with_tree(self.tree.root())
- .with_title(Some(String::from(self.path.to_string_lossy())))
+ .with_title(self.path.to_string_lossy())
.build();
let msg = self.view.update(COMPONENT_TREEVIEW, props);
self.update(msg)
@@ -257,7 +257,7 @@ impl Update for Model {
self.view.get_props(COMPONENT_TREEVIEW).unwrap(),
)
.with_tree(self.tree.root())
- .with_title(Some(String::from(self.path.to_string_lossy())))
+ .with_title(self.path.to_string_lossy())
.build();
let msg = self.view.update(COMPONENT_TREEVIEW, props);
self.update(msg)
@@ -272,7 +272,7 @@ impl Update for Model {
self.view.get_props(COMPONENT_TREEVIEW).unwrap(),
)
.with_tree(self.tree.root())
- .with_title(Some(String::from(self.path.to_string_lossy())))
+ .with_title(self.path.to_string_lossy())
.build();
let msg = self.view.update(COMPONENT_TREEVIEW, props);
self.update(msg)
diff --git a/src/lib.rs b/src/lib.rs
index 302be33..87bfdbd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -8,7 +8,7 @@
//! ### Adding `tui-realm-treeview` as dependency
//!
//! ```toml
-//! tui-realm-treeview = "0.2.0"
+//! tui-realm-treeview = "0.2.1"
//! ```
//!
//! ## Setup a tree component
@@ -49,7 +49,7 @@
//! .with_borders(Borders::ALL, BorderType::Double, Color::LightYellow)
//! .with_background(Color::Black)
//! .with_foreground(Color::LightYellow)
-//! .with_title(Some(String::from("/dev/sda")))
+//! .with_title("/dev/sda")
//! .with_highlighted_str("🚀")
//! .with_tree(tree.root())
//! .build(),
@@ -127,8 +127,8 @@ use tuirealm::tui::{
};
use tuirealm::{
event::{Event, KeyCode},
- props::{BordersProps, TextParts, TextSpan},
- Canvas, Component, Msg, Payload, PropPayload, PropValue, Props, PropsBuilder, Value,
+ props::BordersProps,
+ Component, Frame, Msg, Payload, PropPayload, PropValue, Props, PropsBuilder, Value,
};
// -- structs
@@ -634,6 +634,8 @@ const PROP_TREE: &str = "tree";
const PROP_INITIAL_NODE: &str = "initial_node";
const PROP_KEEP_STATE: &str = "keep_state";
const PROP_MAX_STEPS: &str = "max_steps";
+const PROP_TITLE: &str = "title";
+const PROP_HG_STR: &str = "hg-str";
/// ## TreeViewPropsBuilder
///
@@ -720,10 +722,12 @@ impl TreeViewPropsBuilder {
/// ### with_title
///
/// Set box title
- pub fn with_title(&mut self, title: Option) -> &mut Self {
+ pub fn with_title>(&mut self, title: S) -> &mut Self {
if let Some(props) = self.props.as_mut() {
- let spans = props.texts.spans.clone();
- props.texts = TextParts::new(title, spans);
+ props.own.insert(
+ PROP_TITLE,
+ PropPayload::One(PropValue::Str(title.as_ref().to_string())),
+ );
}
self
}
@@ -731,11 +735,12 @@ impl TreeViewPropsBuilder {
/// ### with_highlighted_str
///
/// The provided string will be displayed on the left side of the selected entry in the tree
- pub fn with_highlighted_str(&mut self, s: &str) -> &mut Self {
+ pub fn with_highlighted_str>(&mut self, s: S) -> &mut Self {
if let Some(props) = self.props.as_mut() {
- let title = props.texts.title.clone();
- let spans = vec![TextSpan::from(s)];
- props.texts = TextParts::new(title, Some(spans));
+ props.own.insert(
+ PROP_HG_STR,
+ PropPayload::One(PropValue::Str(s.as_ref().to_string())),
+ );
}
self
}
@@ -839,9 +844,9 @@ impl<'a> TreeView<'a> {
})
.border_type(self.props.borders.variant);
// Set title
- match self.props.texts.title.as_ref() {
- Some(t) => div.title(t.to_string()),
- None => div,
+ match self.props.own.get(PROP_TITLE).as_ref() {
+ Some(PropPayload::One(PropValue::Str(t))) => div.title(t.to_string()),
+ _ => div,
}
}
}
@@ -851,7 +856,7 @@ impl<'a> Component for TreeView<'a> {
///
/// Based on the current properties and states, renders a widget using the provided render engine in the provided Area
/// If focused, cursor is also set (if supported by widget)
- fn render(&self, render: &mut Canvas, area: Rect) {
+ fn render(&self, render: &mut Frame, area: Rect) {
if self.props.visible {
// Make colors
let (bg, fg): (Color, Color) = match &self.states.focus {
@@ -865,10 +870,10 @@ impl<'a> Component for TreeView<'a> {
.block(block)
.highlight_style(Style::default().fg(fg).bg(bg).add_modifier(Modifier::BOLD));
// Highlighted symbol
- if let Some(spans) = self.props.texts.spans.as_ref() {
- if let Some(span) = spans.get(0) {
- tree = tree.highlight_symbol(&span.content);
- }
+ if let Some(PropPayload::One(PropValue::Str(s))) =
+ self.props.own.get(PROP_HG_STR).as_ref()
+ {
+ tree = tree.highlight_symbol(s);
}
render.render_stateful_widget(tree, area, &mut self.states.get_tui_tree_state());
}
@@ -1309,7 +1314,7 @@ mod tests {
.with_borders(Borders::ALL, BorderType::Double, Color::Red)
.with_background(Color::White)
.with_foreground(Color::Red)
- .with_title(Some(String::from("C:\\")))
+ .with_title("C:\\")
.with_highlighted_str(">>")
.with_tree(tree.root())
.keep_state(false)
@@ -1339,7 +1344,7 @@ mod tests {
// Update
let props = TreeViewPropsBuilder::from(component.get_props())
.with_foreground(Color::Yellow)
- .with_title(Some(String::from("aaa")))
+ .with_title("aaa")
.hidden()
.with_node(None)
.build();
@@ -1349,15 +1354,30 @@ mod tests {
);
assert_eq!(component.props.visible, false);
assert_eq!(component.props.foreground, Color::Yellow);
- assert_eq!(component.props.texts.title.as_ref().unwrap(), "aaa");
+ assert_eq!(
+ *component
+ .props
+ .own
+ .get(PROP_TITLE)
+ .as_ref()
+ .unwrap()
+ .unwrap_one()
+ .unwrap_str(),
+ "aaa"
+ );
assert_eq!(
component.get_state(),
Payload::One(Value::Str(String::from("/")))
);
assert_eq!(
- component.props.texts.spans.as_ref().unwrap()[0]
- .content
- .as_str(),
+ *component
+ .props
+ .own
+ .get(PROP_HG_STR)
+ .as_ref()
+ .unwrap()
+ .unwrap_one()
+ .unwrap_str(),
">>"
);
// Events