Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cnx: add separator widget #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cnx/src/widgets/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! Provided widgets and types for creating new widgets.

mod active_window_title;

mod clock;
mod pager;
mod separator;
pub use self::active_window_title::ActiveWindowTitle;
pub use self::clock::Clock;
pub use self::pager::Pager;
pub use self::separator::Separator;
use crate::text::Text;
use anyhow::Result;
use futures::stream::Stream;
Expand Down
32 changes: 32 additions & 0 deletions cnx/src/widgets/separator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use futures::stream;

use crate::text::{Attributes, Text};

use super::Widget;

/// Acts as a separator between widgets
///
/// Supports markup for easy formatting
pub struct Separator {
attr: Attributes,
text: String,
}

impl Separator {
pub fn new(attr: Attributes, text: String) -> Self {
Self { attr, text }
}
}

impl Widget for Separator {
fn into_stream(self: Box<Self>) -> anyhow::Result<super::WidgetStream> {
Ok(Box::pin(stream::once(async {
Ok(vec![Text {
attr: self.attr,
text: self.text,
stretch: false,
markup: true,
}])
})))
}
}