~matthiasbeyer/imag

f6f9734cd8afbbcb43fa65fb4e554c06049c00e9 — Matthias Beyer 10 months ago a3dd212
mdcat: 0.15 -> 0.17, syntect: 3 -> 4

And update the implementation for the new mdcat interface.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2 files changed, 18 insertions(+), 25 deletions(-)

M lib/entry/libimagentryview/Cargo.toml
M lib/entry/libimagentryview/src/builtin/md.rs
M lib/entry/libimagentryview/Cargo.toml => lib/entry/libimagentryview/Cargo.toml +2 -2
@@ 30,7 30,7 @@ libimagstore     = { version = "0.10.0", path = "../../../lib/core/libimagstore"
libimagerror     = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
libimagentryedit = { version = "0.10.0", path = "../../../lib/entry/libimagentryedit" }

mdcat   = { version = "0.15.0", optional = true }
mdcat   = { version = "0.17.0", optional = true }

[dependencies.pulldown-cmark]
version          = "^0.7"


@@ 39,7 39,7 @@ default-features = false
features         = []

[dependencies.syntect]
version          = "3"
version          = "4"
optional         = true
default-features = false
features         = ["parsing", "assets", "dump-load"]

M lib/entry/libimagentryview/src/builtin/md.rs => lib/entry/libimagentryview/src/builtin/md.rs +16 -23
@@ 30,22 30,11 @@ use anyhow::format_err;

use crate::viewer::Viewer;

pub struct MarkdownViewer<'a> {
    rt:                 &'a Runtime<'a>,
    resource_access:    ResourceAccess,
    termsize:           TerminalSize,
}
pub struct MarkdownViewer<'a>(&'a Runtime<'a>);

impl<'a> MarkdownViewer<'a> {
    pub fn new(rt: &'a Runtime) -> Self {
        MarkdownViewer {
            rt,
            resource_access: ResourceAccess::LocalOnly,
            termsize:        TerminalSize::detect().unwrap_or(TerminalSize {
                width: 80,
                height: 20,
            }),
        }
        MarkdownViewer(rt)
    }
}



@@ 53,18 42,22 @@ impl<'a> Viewer for MarkdownViewer<'a> {
    fn view_entry<W>(&self, e: &Entry, sink: &mut W) -> Result<()>
        where W: Write
    {
        let parser          = Parser::new(e.get_content());
        let base_dir        = self.rt.rtp();
        let syntax_set      = SyntaxSet::load_defaults_newlines();
        let capa            = TerminalCapabilities::ansi();
        let parser   = Parser::new(e.get_content());
        let base_dir = self.0.rtp();
        let settings = mdcat::Settings {
            terminal_capabilities: TerminalCapabilities::ansi(),
            syntax_set: SyntaxSet::load_defaults_newlines(),
            resource_access: ResourceAccess::LocalOnly,
            terminal_size: TerminalSize::detect().unwrap_or(TerminalSize {
                width: 80,
                height: 20,
            }),
        };

        ::mdcat::push_tty(sink,
                          &capa,
                          self.termsize,
                          parser,
        ::mdcat::push_tty(&settings,
                          sink,
                          base_dir,
                          self.resource_access,
                          syntax_set)
                          parser)
        .map_err(|_| format_err!("Failed while formatting markdown"))
    }
}