Browse Source

majc: fix rendering of gemlog.blue

karnycukta
Cadey Ratio 6 months ago
parent
commit
93a5dd445a
7 changed files with 37 additions and 9 deletions
  1. +1
    -1
      Cargo.toml
  2. +1
    -1
      majc/Cargo.toml
  3. +10
    -0
      majc/src/commands.rs
  4. +6
    -3
      majc/src/gemini.rs
  5. +3
    -3
      majc/src/main.rs
  6. +12
    -1
      src/gemini.rs
  7. +4
    -0
      testdata/ambig_preformatted.gmi

+ 1
- 1
Cargo.toml View File

@ -1,6 +1,6 @@
[package]
name = "maj"
version = "0.4.1"
version = "0.4.2"
authors = ["Christine Dodrill <[email protected]>"]
edition = "2018"
license = "0BSD"


+ 1
- 1
majc/Cargo.toml View File

@ -1,6 +1,6 @@
[package]
name = "majc"
version = "0.2.0"
version = "0.2.1"
authors = ["Christine Dodrill <[email protected]>"]
edition = "2018"


+ 10
- 0
majc/src/commands.rs View File

@ -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");


+ 6
- 3
majc/src/gemini.rs View File

@ -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"));
}


+ 3
- 3
majc/src/main.rs View File

@ -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);


+ 12
- 1
src/gemini.rs View File

@ -162,7 +162,7 @@ pub fn parse(doc: &str) -> Vec<Node> {
let mut preformatted_buffer: Vec<u8> = 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<Node> = vec![
Node::Preformatted("FOO".to_string()),
Node::Text("Foo bar".to_string()),
];
assert_eq!(expected, parse(msg));
}
}

+ 4
- 0
testdata/ambig_preformatted.gmi View File

@ -0,0 +1,4 @@
``` foo
FOO
```
Foo bar

Loading…
Cancel
Save