From 93a5dd445ada1c567e376014005210b05798e353 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Tue, 28 Jul 2020 16:02:48 -0400 Subject: [PATCH] majc: fix rendering of gemlog.blue --- Cargo.toml | 2 +- majc/Cargo.toml | 2 +- majc/src/commands.rs | 10 ++++++++++ majc/src/gemini.rs | 9 ++++++--- majc/src/main.rs | 6 +++--- src/gemini.rs | 13 ++++++++++++- testdata/ambig_preformatted.gmi | 4 ++++ 7 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 testdata/ambig_preformatted.gmi diff --git a/Cargo.toml b/Cargo.toml index 9aa1405..5c4e653 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "maj" -version = "0.4.1" +version = "0.4.2" authors = ["Christine Dodrill "] edition = "2018" license = "0BSD" diff --git a/majc/Cargo.toml b/majc/Cargo.toml index 0b7048f..d5b75c9 100644 --- a/majc/Cargo.toml +++ b/majc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "majc" -version = "0.2.0" +version = "0.2.1" authors = ["Christine Dodrill "] edition = "2018" diff --git a/majc/src/commands.rs b/majc/src/commands.rs index 9366fe6..9d76a1d 100644 --- a/majc/src/commands.rs +++ b/majc/src/commands.rs @@ -4,6 +4,16 @@ use cursive::{ Cursive, }; +pub fn quit(siv: &mut Cursive) { + siv.add_layer( + Dialog::text("Are you sure you want to quit?") + .button("No", |s| { + s.pop_layer(); + }) + .button("Yes", Cursive::quit), + ); +} + pub fn help(siv: &mut Cursive) { let content = include_str!("./help.gmi"); diff --git a/majc/src/gemini.rs b/majc/src/gemini.rs index d779b03..95ca816 100644 --- a/majc/src/gemini.rs +++ b/majc/src/gemini.rs @@ -1,13 +1,13 @@ use cursive::{ - theme::{Effect, Style}, + theme::{BaseColor, Color, Effect, Style}, traits::*, utils::markup::StyledString, views::{Dialog, EditView, ResizedView, SelectView, TextView}, Cursive, }; use maj::{self, Response}; -use std::str; use rustls::ClientConfig; +use std::str; /// The state of the browser. #[derive(Clone)] @@ -225,7 +225,10 @@ pub fn render(body: &str) -> StyledString { Style::from(Effect::Bold), )), ListItem(item) => styled.append(StyledString::plain(format!("* {}", item))), - Quote(quote) => styled.append(StyledString::plain(format!("> {}", quote))), + Quote(quote) => styled.append(StyledString::styled( + format!("> {}", quote), + Style::from(Color::Dark(BaseColor::Green)), + )), } styled.append(StyledString::plain("\n")); } diff --git a/majc/src/main.rs b/majc/src/main.rs index 53ae9a3..38e7c15 100644 --- a/majc/src/main.rs +++ b/majc/src/main.rs @@ -1,4 +1,4 @@ -use cursive::{event::Key, menu::MenuTree}; +use cursive::{event::Key, menu::MenuTree, Cursive}; pub(crate) mod commands; pub(crate) mod gemini; @@ -17,8 +17,8 @@ fn main() { siv.add_global_callback('c', |s| { s.pop_layer(); }); - siv.add_global_callback('q', cursive::Cursive::quit); - siv.add_global_callback('~', cursive::Cursive::toggle_debug_console); + siv.add_global_callback('q', commands::quit); + siv.add_global_callback('~', Cursive::toggle_debug_console); siv.add_global_callback('h', gemini::history); siv.add_global_callback('l', gemini::links); siv.add_global_callback('o', gemini::open_prompt); diff --git a/src/gemini.rs b/src/gemini.rs index fee4916..da43635 100644 --- a/src/gemini.rs +++ b/src/gemini.rs @@ -162,7 +162,7 @@ pub fn parse(doc: &str) -> Vec { let mut preformatted_buffer: Vec = vec![]; for line in doc.lines() { - if line == "```" { + if line.starts_with("```") { collect_preformatted = !collect_preformatted; if !collect_preformatted { result.push(Node::Preformatted( @@ -320,4 +320,15 @@ mod tests { ]; assert_eq!(expected, parse(msg)); } + + #[test] + fn ambiguous_preformatted() { + let _ = pretty_env_logger::try_init(); + let msg = include_str!("../testdata/ambig_preformatted.gmi"); + let expected: Vec = vec![ + Node::Preformatted("FOO".to_string()), + Node::Text("Foo bar".to_string()), + ]; + assert_eq!(expected, parse(msg)); + } } diff --git a/testdata/ambig_preformatted.gmi b/testdata/ambig_preformatted.gmi new file mode 100644 index 0000000..83f4431 --- /dev/null +++ b/testdata/ambig_preformatted.gmi @@ -0,0 +1,4 @@ +``` foo +FOO +``` +Foo bar