Add Plain markup implementation

This commit is contained in:
Alexandre Bury 2018-01-10 14:44:27 +01:00
parent 59d67e891c
commit 6f468658e1
2 changed files with 17 additions and 2 deletions

View File

@ -5,7 +5,7 @@
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
[![Gitter chat](https://badges.gitter.im/gyscos/cursive.png)](https://gitter.im/cursive-rs/cursive) [![Gitter chat](https://badges.gitter.im/gyscos/cursive.png)](https://gitter.im/cursive-rs/cursive)
Cursive is a TUI (Text User Interface) library for rust. It is currently based on jeaye's [ncurses-rs](https://github.com/jeaye/ncurses-rs), but [other backends are available](https://github.com/gyscos/Cursive/wiki/Backends). Cursive is a TUI (Text User Interface) library for rust. It uses ncurses by default, but [other backends are available](https://github.com/gyscos/Cursive/wiki/Backends).
It allows you to build rich user interfaces for terminal applications. It allows you to build rich user interfaces for terminal applications.

View File

@ -9,8 +9,9 @@ pub mod markdown;
pub use self::markdown::Markdown; pub use self::markdown::Markdown;
use owning_ref::OwningHandle; use owning_ref::OwningHandle;
use owning_ref::StringRef; use owning_ref::StringRef;
use std::marker::PhantomData;
use utils::lines::spans::Span; use utils::lines::spans::Span;
use theme::Style;
use std::borrow::Cow;
/// Trait for parsing text into styled spans. /// Trait for parsing text into styled spans.
pub trait Markup { pub trait Markup {
@ -35,6 +36,20 @@ pub trait Markup {
} }
} }
/// Dummy `Markup` implementation that returns the text as-is.
pub struct Plain;
impl Markup for Plain {
type Error = ();
fn parse<'a>(input: &'a str) -> Result<Vec<Span<'a>>, Self::Error> {
Ok(vec![Span {
text: Cow::Borrowed(input),
style: Style::none(),
}])
}
}
/// Holds both parsed spans, and the input string they borrow. /// Holds both parsed spans, and the input string they borrow.
/// ///
/// This is used to pass around a parsed string. /// This is used to pass around a parsed string.