Backport more features needed for ytop

Signed-off-by: Igor Raits <ignatenkobrain@fedoraproject.org>
epel9
Igor Raits 5 years ago
parent 6e0167d1a9
commit 7d9f0af0f4

@ -1,7 +1,7 @@
From 4493e4035354ad221d35c99829b7b7678312dbb7 Mon Sep 17 00:00:00 2001
From: Caleb Bassi <calebjbassi@gmail.com>
Date: Sun, 12 Jan 2020 14:13:28 -0800
Subject: [PATCH 1/3] Add header_gap field to Table
Subject: [PATCH 1/6] Add header_gap field to Table
(cherry picked from commit 7aae9b380eef239f5eec227868ca42438aa7f12f)
---

@ -1,7 +1,7 @@
From 915aeba393c139dade33b215a3fc975901d5aa7e Mon Sep 17 00:00:00 2001
From: Caleb Bassi <calebjbassi@gmail.com>
Date: Fri, 10 Jan 2020 15:58:44 -0800
Subject: [PATCH 2/3] Add linechart support
Subject: [PATCH 2/6] Add linechart support
Closes #73

@ -1,7 +1,7 @@
From 3dff2a48a7e253216d72f412019d84733a60f96a Mon Sep 17 00:00:00 2001
From: Caleb Bassi <calebjbassi@gmail.com>
Date: Tue, 14 Jan 2020 09:47:07 -0800
Subject: [PATCH 3/3] Change linechart to draw the points also
Subject: [PATCH 3/6] Change linechart to draw the points also
(cherry picked from commit 829b7b6b70274053442bd4910ac4fac1d30de2a8)
---

@ -0,0 +1,78 @@
From 911f839151801be3301ffe92ea15ccb9b1f94736 Mon Sep 17 00:00:00 2001
From: Joseph Price <pricejosephd@gmail.com>
Date: Sat, 11 Jan 2020 12:10:57 -0500
Subject: [PATCH 4/6] allow controlling sparkline direction
---
src/widgets/mod.rs | 2 +-
src/widgets/sparkline.rs | 20 +++++++++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs
index 8a89c42..b94e2d0 100644
--- a/src/widgets/mod.rs
+++ b/src/widgets/mod.rs
@@ -19,7 +19,7 @@ pub use self::chart::{Axis, Chart, Dataset, GraphType, Marker};
pub use self::gauge::Gauge;
pub use self::list::{List, SelectableList};
pub use self::paragraph::Paragraph;
-pub use self::sparkline::Sparkline;
+pub use self::sparkline::{Sparkline, RenderDirection};
pub use self::table::{Row, Table};
pub use self::tabs::Tabs;
diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs
index 46a5146..8a1b70a 100644
--- a/src/widgets/sparkline.rs
+++ b/src/widgets/sparkline.rs
@@ -31,6 +31,13 @@ pub struct Sparkline<'a> {
/// The maximum value to take to compute the maximum bar height (if nothing is specified, the
/// widget uses the max of the dataset)
max: Option<u64>,
+ // The direction to render the sparkine, either from left to right, or from right to left
+ direction: RenderDirection,
+}
+
+pub enum RenderDirection {
+ LTR,
+ RTL
}
impl<'a> Default for Sparkline<'a> {
@@ -40,6 +47,7 @@ impl<'a> Default for Sparkline<'a> {
style: Default::default(),
data: &[],
max: None,
+ direction: RenderDirection::LTR,
}
}
}
@@ -64,6 +72,12 @@ impl<'a> Sparkline<'a> {
self.max = Some(max);
self
}
+
+ pub fn direction(mut self, direction: RenderDirection) -> Sparkline<'a> {
+ self.direction = direction;
+ self
+ }
+
}
impl<'a> Widget for Sparkline<'a> {
@@ -110,7 +124,11 @@ impl<'a> Widget for Sparkline<'a> {
7 => bar::SEVEN_EIGHTHS,
_ => bar::FULL,
};
- buf.get_mut(spark_area.left() + i as u16, spark_area.top() + j)
+ let x = match self.direction {
+ RenderDirection::LTR => spark_area.left() + i as u16,
+ RenderDirection::RTL => spark_area.right() - i as u16 - 1
+ };
+ buf.get_mut(x, spark_area.top() + j)
.set_symbol(symbol)
.set_fg(self.style.fg)
.set_bg(self.style.bg);
--
2.25.1

@ -0,0 +1,56 @@
From cde0592ddcf5748b228f8aaa26ef36da2cc13093 Mon Sep 17 00:00:00 2001
From: Joseph Price <pricejosephd@gmail.com>
Date: Sat, 11 Jan 2020 12:29:56 -0500
Subject: [PATCH 5/6] fix format
---
src/widgets/mod.rs | 2 +-
src/widgets/sparkline.rs | 5 ++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs
index b94e2d0..5d0da6d 100644
--- a/src/widgets/mod.rs
+++ b/src/widgets/mod.rs
@@ -19,7 +19,7 @@ pub use self::chart::{Axis, Chart, Dataset, GraphType, Marker};
pub use self::gauge::Gauge;
pub use self::list::{List, SelectableList};
pub use self::paragraph::Paragraph;
-pub use self::sparkline::{Sparkline, RenderDirection};
+pub use self::sparkline::{RenderDirection, Sparkline};
pub use self::table::{Row, Table};
pub use self::tabs::Tabs;
diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs
index 8a1b70a..33af6cb 100644
--- a/src/widgets/sparkline.rs
+++ b/src/widgets/sparkline.rs
@@ -37,7 +37,7 @@ pub struct Sparkline<'a> {
pub enum RenderDirection {
LTR,
- RTL
+ RTL,
}
impl<'a> Default for Sparkline<'a> {
@@ -77,7 +77,6 @@ impl<'a> Sparkline<'a> {
self.direction = direction;
self
}
-
}
impl<'a> Widget for Sparkline<'a> {
@@ -126,7 +125,7 @@ impl<'a> Widget for Sparkline<'a> {
};
let x = match self.direction {
RenderDirection::LTR => spark_area.left() + i as u16,
- RenderDirection::RTL => spark_area.right() - i as u16 - 1
+ RenderDirection::RTL => spark_area.right() - i as u16 - 1,
};
buf.get_mut(x, spark_area.top() + j)
.set_symbol(symbol)
--
2.25.1

@ -0,0 +1,75 @@
From 3b0f769584cce48c398ead3a1698f7655c32de2b Mon Sep 17 00:00:00 2001
From: Caleb Bassi <calebjbassi@gmail.com>
Date: Tue, 14 Jan 2020 08:18:18 -0800
Subject: [PATCH 6/6] Add show_baseline field to sparkline
---
src/widgets/sparkline.rs | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs
index 33af6cb..0ae28c9 100644
--- a/src/widgets/sparkline.rs
+++ b/src/widgets/sparkline.rs
@@ -33,6 +33,8 @@ pub struct Sparkline<'a> {
max: Option<u64>,
// The direction to render the sparkine, either from left to right, or from right to left
direction: RenderDirection,
+ /// If true, draws a baseline of `bar::ONE_EIGHTH` spanning the bottom of the sparkline graph
+ show_baseline: bool,
}
pub enum RenderDirection {
@@ -48,6 +50,7 @@ impl<'a> Default for Sparkline<'a> {
data: &[],
max: None,
direction: RenderDirection::LTR,
+ show_baseline: false,
}
}
}
@@ -77,6 +80,10 @@ impl<'a> Sparkline<'a> {
self.direction = direction;
self
}
+ pub fn show_baseline(mut self, show_baseline: bool) -> Sparkline<'a> {
+ self.show_baseline = show_baseline;
+ self
+ }
}
impl<'a> Widget for Sparkline<'a> {
@@ -93,6 +100,15 @@ impl<'a> Widget for Sparkline<'a> {
return;
}
+ if self.show_baseline {
+ for i in spark_area.left()..spark_area.right() {
+ buf.get_mut(i, spark_area.bottom() - 1)
+ .set_symbol(bar::ONE_EIGHTH)
+ .set_fg(self.style.fg)
+ .set_bg(self.style.bg);
+ }
+ }
+
let max = match self.max {
Some(v) => v,
None => *self.data.iter().max().unwrap_or(&1u64),
@@ -113,7 +129,13 @@ impl<'a> Widget for Sparkline<'a> {
for j in (0..spark_area.height).rev() {
for (i, d) in data.iter_mut().enumerate() {
let symbol = match *d {
- 0 => " ",
+ 0 => {
+ if self.show_baseline && j == spark_area.height - 1 {
+ bar::ONE_EIGHTH
+ } else {
+ " "
+ }
+ }
1 => bar::ONE_EIGHTH,
2 => bar::ONE_QUARTER,
3 => bar::THREE_EIGHTHS,
--
2.25.1

@ -7,7 +7,7 @@
Name: rust-%{crate}
Version: 0.8.0
Release: 4%{?dist}
Release: 5%{?dist}
Summary: Library to build rich terminal user interfaces or dashboards
# Upstream license specification: MIT
@ -23,6 +23,11 @@ Patch0001: 0001-Add-header_gap-field-to-Table.patch
Patch0002: 0002-Add-linechart-support.patch
# https://github.com/fdehau/tui-rs/commit/829b7b6b70274053442bd4910ac4fac1d30de2a8
Patch0003: 0003-Change-linechart-to-draw-the-points-also.patch
# https://github.com/fdehau/tui-rs/pull/218
Patch0004: 0004-allow-controlling-sparkline-direction.patch
Patch0005: 0005-fix-format.patch
# https://github.com/fdehau/tui-rs/pull/220
Patch0006: 0006-Add-show_baseline-field-to-sparkline.patch
ExclusiveArch: %{rust_arches}
%if %{__cargo_skip_build}
@ -153,6 +158,9 @@ which use "termion" feature of "%{crate}" crate.
%endif
%changelog
* Thu Mar 19 2020 Igor Raits <ignatenkobrain@fedoraproject.org> - 0.8.0-5
- Backport more features needed for ytop
* Wed Mar 18 2020 Josh Stone <jistone@redhat.com> - 0.8.0-4
- Bump crossterm to 0.16.

Loading…
Cancel
Save