From e42ab1fed827118bec62b57f2a22d6f1f61b9e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20B=C3=BCsch?= Date: Sat, 8 Sep 2018 15:41:59 +1000 Subject: [PATCH] Move Text to widgets/mod.rs --- src/widgets/mod.rs | 21 +++++++++++++++++++-- src/widgets/paragraph.rs | 19 +------------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index 8746cb59..b4d42ebe 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + mod barchart; mod block; pub mod canvas; @@ -14,7 +16,7 @@ pub use self::block::Block; pub use self::chart::{Axis, Chart, Dataset, Marker}; pub use self::gauge::Gauge; pub use self::list::{Item, List, SelectableList}; -pub use self::paragraph::{Paragraph, Text}; +pub use self::paragraph::Paragraph; pub use self::sparkline::Sparkline; pub use self::table::{Row, Table}; pub use self::tabs::Tabs; @@ -22,7 +24,7 @@ pub use self::tabs::Tabs; use backend::Backend; use buffer::Buffer; use layout::Rect; -use style::Color; +use style::{Color, Style}; use terminal::Frame; /// Bitflags that can be composed to set the visible borders essentially on the block widget. @@ -43,6 +45,21 @@ bitflags! { } } +pub enum Text<'b> { + Raw(Cow<'b, str>), + Styled(Cow<'b, str>, Style), +} + +impl<'b> Text<'b> { + pub fn raw>>(data: D) -> Text<'b> { + Text::Raw(data.into()) + } + + pub fn styled>>(data: D, style: Style) -> Text<'b> { + Text::Styled(data.into(), style) + } +} + /// Base requirements for a Widget pub trait Widget { /// Draws the current state of the widget in the given buffer. That the only method required to diff --git a/src/widgets/paragraph.rs b/src/widgets/paragraph.rs index a108aa32..72b2edb3 100644 --- a/src/widgets/paragraph.rs +++ b/src/widgets/paragraph.rs @@ -1,5 +1,3 @@ -use std::borrow::Cow; - use either::Either; use itertools::{multipeek, MultiPeek}; use unicode_segmentation::UnicodeSegmentation; @@ -8,7 +6,7 @@ use unicode_width::UnicodeWidthStr; use buffer::Buffer; use layout::{Alignment, Rect}; use style::Style; -use widgets::{Block, Widget}; +use widgets::{Block, Text, Widget}; /// A widget to display some text. /// @@ -51,21 +49,6 @@ where alignment: Alignment, } -pub enum Text<'b> { - Raw(Cow<'b, str>), - Styled(Cow<'b, str>, Style), -} - -impl<'b> Text<'b> { - pub fn raw>>(data: D) -> Text<'b> { - Text::Raw(data.into()) - } - - pub fn styled>>(data: D, style: Style) -> Text<'b> { - Text::Styled(data.into(), style) - } -} - impl<'a, 't, T> Paragraph<'a, 't, T> where T: Iterator>,