Move Text to widgets/mod.rs

pull/74/head
Antoine Büsch 6 years ago committed by Florian Dehau
parent 0544c023f5
commit e42ab1fed8

@ -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<D: Into<Cow<'b, str>>>(data: D) -> Text<'b> {
Text::Raw(data.into())
}
pub fn styled<D: Into<Cow<'b, str>>>(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

@ -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<D: Into<Cow<'b, str>>>(data: D) -> Text<'b> {
Text::Raw(data.into())
}
pub fn styled<D: Into<Cow<'b, str>>>(data: D, style: Style) -> Text<'b> {
Text::Styled(data.into(), style)
}
}
impl<'a, 't, T> Paragraph<'a, 't, T>
where
T: Iterator<Item = &'t Text<'t>>,

Loading…
Cancel
Save