Skip to content

Commit

Permalink
remove all calls to crossterm's queue! macro
Browse files Browse the repository at this point in the history
Fix compilation on windows.
Fix #13
See #13 (comment)
  • Loading branch information
Canop committed Dec 16, 2019
1 parent afd55cb commit 242aa57
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,4 +1,8 @@

<a name="v0.8.4"></a>
### v0.8.4 - 2019-12-16
- fix a compilation problem on windows (see https://github.com/Canop/termimad/issues/13#issuecomment-565848039)

<a name="v0.8.3"></a>
### v0.8.3 - 2019-12-15
- port to crossterm 0.14
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "termimad"
version = "0.8.3"
version = "0.8.4"
authors = ["dystroy <denys.seguret@gmail.com>"]
repository = "https://github.com/Canop/termimad"
description = "Markdown Renderer for the Terminal"
Expand Down
27 changes: 15 additions & 12 deletions src/compound_style.rs
@@ -1,14 +1,16 @@
use std::fmt::{self, Display};

use crossterm::{
queue,
style::{
Attribute, Color, ContentStyle, PrintStyledContent, SetBackgroundColor, SetForegroundColor,
StyledContent,
use {
crate::{errors::Result, styled_char::StyledChar},
crossterm::{
QueueableCommand,
style::{
Attribute, Color, ContentStyle, PrintStyledContent, SetBackgroundColor, SetForegroundColor,
StyledContent,
},
},
std::fmt::{self, Display},
};

use crate::{errors::Result, styled_char::StyledChar};

/// A style which may be applied to a compound
#[derive(Default, Clone)]
Expand All @@ -24,9 +26,9 @@ impl From<ContentStyle> for CompoundStyle {

impl CompoundStyle {
/// Apply an `StyledContent` to the passed displayable object.
pub fn apply_to<D: Display>(&self, val: D) -> StyledContent<D>
pub fn apply_to<D>(&self, val: D) -> StyledContent<D>
where
D: Clone,
D: Clone + Display,
{
self.object_style.apply(val)
}
Expand Down Expand Up @@ -146,7 +148,8 @@ impl CompoundStyle {
D: Clone + Display,
W: std::io::Write,
{
Ok(queue!(w, PrintStyledContent(self.apply_to(val)))?)
w.queue(PrintStyledContent(self.apply_to(val)))?;
Ok(())
}

/// write the string with this style on the given
Expand All @@ -163,7 +166,7 @@ impl CompoundStyle {
W: std::io::Write,
{
if let Some(fg) = self.object_style.foreground_color {
queue!(w, SetForegroundColor(fg))?;
w.queue(SetForegroundColor(fg))?;
}
Ok(())
}
Expand All @@ -173,7 +176,7 @@ impl CompoundStyle {
W: std::io::Write,
{
if let Some(bg) = self.object_style.background_color {
queue!(w, SetBackgroundColor(bg))?;
w.queue(SetBackgroundColor(bg))?;
}
Ok(())
}
Expand Down
26 changes: 24 additions & 2 deletions src/events/event.rs
@@ -1,7 +1,12 @@
use crossterm;
use crossterm::{
self,
event::{
KeyCode, KeyModifiers,
},
};

/// a valid user event
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Event {

Key(crossterm::event::KeyEvent),
Expand Down Expand Up @@ -50,5 +55,22 @@ impl Event {
_ => None,
}
}
pub const fn crtl_key(code: KeyCode) -> Self {
Event::Key(
crossterm::event::KeyEvent {
code,
modifiers: KeyModifiers::CONTROL,
}
)
}
pub const fn simple_key(code: KeyCode) -> Self {
Event::Key(
crossterm::event::KeyEvent {
code,
modifiers: KeyModifiers::empty(),
}
)
}
}


21 changes: 12 additions & 9 deletions src/styled_char.rs
@@ -1,13 +1,15 @@
use std::fmt::{self, Display};

use crossterm::{
queue,
style::{Color, PrintStyledContent, StyledContent},
use {
crate::{
compound_style::CompoundStyle,
errors::Result,
},
crossterm::{
QueueableCommand,
style::{Color, PrintStyledContent, StyledContent},
},
std::fmt::{self, Display},
};

use crate::compound_style::CompoundStyle;
use crate::errors::Result;

/// A modifiable character which can be easily written or repeated. Can
/// be used for bullets, horizontal rules or quote marks.
#[derive(Clone)]
Expand Down Expand Up @@ -66,7 +68,8 @@ impl StyledChar {
where
W: std::io::Write,
{
Ok(queue!(w, PrintStyledContent(self.styled_char.clone()))?)
w.queue(PrintStyledContent(self.styled_char.clone()))?;
Ok(())
}
}

Expand Down

0 comments on commit 242aa57

Please sign in to comment.