Use cfg-if for to define Cursive::default()

And update other dependencies
This commit is contained in:
Alexandre Bury 2019-04-15 15:17:21 -07:00
parent 51c6450688
commit ac28309b3b
3 changed files with 50 additions and 46 deletions

View File

@ -20,19 +20,20 @@ repository = "gyscos/Cursive"
[dependencies]
enum-map = "0.5.0"
enumset = "0.3.15"
enumset = "0.3.17"
log = "0.4.6"
owning_ref = "0.4.0"
toml = "0.4.10"
toml = "0.5.0"
unicode-segmentation = "1.2.1"
unicode-width = "0.1.5"
xi-unicode = "0.1.0"
libc = "0.2.47"
libc = "0.2.51"
term_size = { version = "0.3.1", optional = true }
crossbeam-channel = "0.3.6"
lazy_static = "1.2.0"
crossbeam-channel = "0.3.8"
lazy_static = "1.3.0"
chrono = "0.4.6"
hashbrown = "0.1.8"
hashbrown = "0.2.1"
cfg-if = "0.1.7"
[dependencies.num]
default-features = false
@ -59,17 +60,17 @@ version = "0.16.1"
[dependencies.pulldown-cmark]
default-features = false
optional = true
version = "0.2.0"
version = "0.4.1"
[dependencies.termion]
optional = true
version = "1.5.1"
[target.'cfg(unix)'.dependencies]
signal-hook = "0.1.7"
signal-hook = "0.1.8"
[dev-dependencies]
rand = "0.6.4"
rand = "0.6.5"
pretty-bytes = "0.2.2"
[features]

View File

@ -77,41 +77,33 @@ impl<F: FnOnce(&mut Cursive) -> () + Send> CbFunc for F {
}
}
#[cfg(feature = "termion-backend")]
impl Default for Cursive {
fn default() -> Self {
Self::termion().unwrap()
}
}
#[cfg(all(not(feature = "termion-backend"), feature = "pancurses-backend"))]
impl Default for Cursive {
fn default() -> Self {
Self::pancurses().unwrap()
}
}
#[cfg(all(
not(feature = "termion-backend"),
not(feature = "pancurses-backend"),
feature = "blt-backend"
))]
impl Default for Cursive {
fn default() -> Self {
Self::blt()
}
}
#[cfg(all(
not(feature = "termion-backend"),
not(feature = "pancurses-backend"),
not(feature = "blt-backend"),
feature = "ncurses-backend"
))]
impl Default for Cursive {
fn default() -> Self {
Self::ncurses().unwrap()
cfg_if::cfg_if! {
if #[cfg(feature = "blt-backend")] {
impl Default for Cursive {
fn default() -> Self {
Self::blt()
}
}
} else if #[cfg(feature = "termion-backend")] {
impl Default for Cursive {
fn default() -> Self {
Self::termion().unwrap()
}
}
} else if #[cfg(feature = "pancurses-backend")] {
impl Default for Cursive {
fn default() -> Self {
Self::pancurses().unwrap()
}
}
} else if #[cfg(feature = "ncurses-backend")] {
impl Default for Cursive {
fn default() -> Self {
Self::ncurses().unwrap()
}
}
}
// No Default implementation otherwise.
}
impl Cursive {

View File

@ -2,11 +2,13 @@
//!
//! Needs the `markdown` feature to be enabled.
use std::borrow::Cow;
use crate::theme::{Effect, Style};
use crate::utils::markup::{StyledIndexedSpan, StyledString};
use crate::utils::span::IndexedCow;
use pulldown_cmark::{self, Event, Tag};
use pulldown_cmark::{self, CowStr, Event, Tag};
use unicode_width::UnicodeWidthStr;
/// Parses the given string as markdown text.
@ -79,7 +81,7 @@ impl<'a> Iterator for Parser<'a> {
}
Tag::Rule => return Some(self.literal("---")),
Tag::BlockQuote => return Some(self.literal("> ")),
Tag::Link(_, _) => return Some(self.literal("[")),
Tag::Link(_, _, _) => return Some(self.literal("[")),
Tag::Code => return Some(self.literal("```")),
Tag::Strong => self.stack.push(Style::from(Effect::Bold)),
Tag::Paragraph if !self.first => {
@ -91,7 +93,7 @@ impl<'a> Iterator for Parser<'a> {
// Remove from stack!
Tag::Paragraph if self.first => self.first = false,
Tag::Header(_) => return Some(self.literal("\n\n")),
Tag::Link(link, _) => {
Tag::Link(_, link, _) => {
return Some(self.literal(format!("]({})", link)))
}
Tag::Code => return Some(self.literal("```")),
@ -107,6 +109,11 @@ impl<'a> Iterator for Parser<'a> {
| Event::InlineHtml(text)
| Event::Html(text)
| Event::Text(text) => {
let text = match text {
CowStr::Boxed(text) => Cow::Owned(text.into()),
CowStr::Borrowed(text) => Cow::Borrowed(text),
CowStr::Inlined(text) => Cow::Owned(text.to_string()),
};
let width = text.width();
// Return something!
return Some(StyledIndexedSpan {
@ -115,6 +122,10 @@ impl<'a> Iterator for Parser<'a> {
width,
});
}
Event::TaskListMarker(checked) => {
let mark = if checked { "[x]" } else { "[ ]" };
return Some(self.literal(mark));
}
}
}
}