|
|
|
|
@ -256,75 +256,78 @@ fn draw_content(s: &mut Cursive, url: &Url, content: Option<Vec<u8>>) {
|
|
|
|
|
// draw new content lines
|
|
|
|
|
for line in content_str.lines() { |
|
|
|
|
match Link::from_str(line) { |
|
|
|
|
Ok(link) => match link { |
|
|
|
|
Link::Http(url, label) => { |
|
|
|
|
let mut formatted = StyledString::new(); |
|
|
|
|
let www_label = format!("{} [WWW]", label); |
|
|
|
|
formatted.append(StyledString::styled( |
|
|
|
|
www_label, |
|
|
|
|
Style::from(Color::Dark(BaseColor::Green)).combine(Effect::Bold), |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
let data = object! { |
|
|
|
|
"type" => "www", |
|
|
|
|
"url" => url.to_string() |
|
|
|
|
}; |
|
|
|
|
main_view.add_item(formatted, json::stringify(data)) |
|
|
|
|
Ok(link) => { |
|
|
|
|
match link { |
|
|
|
|
Link::Http(url, label) => { |
|
|
|
|
let mut formatted = StyledString::new(); |
|
|
|
|
let www_label = format!("{} [WWW]", label); |
|
|
|
|
formatted.append(StyledString::styled( |
|
|
|
|
www_label, |
|
|
|
|
Style::from(Color::Dark(BaseColor::Green)).combine(Effect::Bold), |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
let data = object! { |
|
|
|
|
"type" => "www", |
|
|
|
|
"url" => url.to_string() |
|
|
|
|
}; |
|
|
|
|
main_view.add_item(formatted, json::stringify(data)) |
|
|
|
|
} |
|
|
|
|
Link::Gopher(url, label) => { |
|
|
|
|
let mut formatted = StyledString::new(); |
|
|
|
|
let gopher_label = format!("{} [Gopher]", label); |
|
|
|
|
formatted.append(StyledString::styled( |
|
|
|
|
gopher_label, |
|
|
|
|
Style::from(Color::Light(BaseColor::Magenta)).combine(Effect::Bold), |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
let data = object! { |
|
|
|
|
"type" => "gopher", |
|
|
|
|
"url" => url.to_string() |
|
|
|
|
}; |
|
|
|
|
main_view.add_item(formatted, json::stringify(data)) |
|
|
|
|
} |
|
|
|
|
Link::Gemini(url, label) => { |
|
|
|
|
let mut formatted = StyledString::new(); |
|
|
|
|
formatted.append(StyledString::styled( |
|
|
|
|
label, |
|
|
|
|
Style::from(Color::Light(BaseColor::Blue)).combine(Effect::Bold), |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
let data = object! { |
|
|
|
|
"type" => "gemini", |
|
|
|
|
"url" => url.to_string() |
|
|
|
|
}; |
|
|
|
|
main_view.add_item(formatted, json::stringify(data)) |
|
|
|
|
} |
|
|
|
|
Link::Relative(url, label) => { |
|
|
|
|
let mut formatted = StyledString::new(); |
|
|
|
|
formatted.append(StyledString::styled( |
|
|
|
|
label, |
|
|
|
|
Style::from(Color::Light(BaseColor::Blue)).combine(Effect::Bold), |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
let data = object! { |
|
|
|
|
"type" => "gemini", |
|
|
|
|
"url" => url.to_string() |
|
|
|
|
}; |
|
|
|
|
main_view.add_item(formatted, json::stringify(data)) |
|
|
|
|
} |
|
|
|
|
Link::Unknown(_, _) => (), |
|
|
|
|
} |
|
|
|
|
Link::Gopher(url, label) => { |
|
|
|
|
let mut formatted = StyledString::new(); |
|
|
|
|
let gopher_label = format!("{} [Gopher]", label); |
|
|
|
|
formatted.append(StyledString::styled( |
|
|
|
|
gopher_label, |
|
|
|
|
Style::from(Color::Light(BaseColor::Magenta)).combine(Effect::Bold), |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
let data = object! { |
|
|
|
|
"type" => "gopher", |
|
|
|
|
"url" => url.to_string() |
|
|
|
|
}; |
|
|
|
|
main_view.add_item(formatted, json::stringify(data)) |
|
|
|
|
} |
|
|
|
|
Link::Gemini(url, label) => { |
|
|
|
|
let mut formatted = StyledString::new(); |
|
|
|
|
formatted.append(StyledString::styled( |
|
|
|
|
label, |
|
|
|
|
Style::from(Color::Light(BaseColor::Blue)).combine(Effect::Bold), |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
let data = object! { |
|
|
|
|
"type" => "gemini", |
|
|
|
|
"url" => url.to_string() |
|
|
|
|
}; |
|
|
|
|
main_view.add_item(formatted, json::stringify(data)) |
|
|
|
|
} |
|
|
|
|
Link::Relative(url, label) => { |
|
|
|
|
let mut formatted = StyledString::new(); |
|
|
|
|
formatted.append(StyledString::styled( |
|
|
|
|
label, |
|
|
|
|
Style::from(Color::Light(BaseColor::Blue)).combine(Effect::Bold), |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
let data = object! { |
|
|
|
|
"type" => "gemini", |
|
|
|
|
"url" => url.to_string() |
|
|
|
|
}; |
|
|
|
|
main_view.add_item(formatted, json::stringify(data)) |
|
|
|
|
} |
|
|
|
|
Link::Unknown(_, _) => (), |
|
|
|
|
continue; |
|
|
|
|
}, |
|
|
|
|
Err(_) => { |
|
|
|
|
let line = str::replace(line, "\t", " "); |
|
|
|
|
let max_size = screen_size.x - 10; |
|
|
|
|
if line.len() > max_size { |
|
|
|
|
let lines = textwrap::fill(&line, max_size); |
|
|
|
|
for l in lines.lines() { |
|
|
|
|
main_view.add_item(l, String::from("0")); |
|
|
|
|
}; |
|
|
|
|
} else { |
|
|
|
|
main_view.add_item(line, String::from("0")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Err(_) => {} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let line = str::replace(line, "\t", " "); |
|
|
|
|
let max_size = screen_size.x - 10; |
|
|
|
|
if line.len() > max_size { |
|
|
|
|
let lines = textwrap::fill(&line, max_size); |
|
|
|
|
for l in lines.lines() { |
|
|
|
|
main_view.add_item(l, String::from("0")); |
|
|
|
|
}; |
|
|
|
|
} else { |
|
|
|
|
main_view.add_item(line, String::from("0")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|