Skip to content

Commit

Permalink
tui-realm 0.5.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Aug 2, 2021
1 parent df17b5a commit 2399023
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 36 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<img src="docs/images/tui-realm-treeview.svg" width="256" height="256" />
</p>

[![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)

---

Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
70 changes: 45 additions & 25 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -720,22 +722,25 @@ impl TreeViewPropsBuilder {
/// ### with_title
///
/// Set box title
pub fn with_title(&mut self, title: Option<String>) -> &mut Self {
pub fn with_title<S: AsRef<str>>(&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
}

/// ### 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<S: AsRef<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
}
Expand Down Expand Up @@ -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,
}
}
}
Expand All @@ -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 {
Expand All @@ -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());
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit 2399023

Please sign in to comment.