line.name => line.text

pull/14/head
chris west 4 years ago
parent 61e4942ecb
commit 999171e0e5

@ -56,7 +56,7 @@ pub struct Menu {
/// field will point to its index in the Menu's `links` Vec. /// field will point to its index in the Menu's `links` Vec.
pub struct Line { pub struct Line {
/// Text of the line. /// Text of the line.
pub name: String, pub text: String,
/// URL, if it's a link. /// URL, if it's a link.
pub url: String, pub url: String,
/// Gopher Item Type. /// Gopher Item Type.
@ -228,23 +228,23 @@ impl Menu {
} }
// truncate long lines, instead of wrapping // truncate long lines, instead of wrapping
let name = if line.name.len() > MAX_COLS { let text = if line.text.len() > MAX_COLS {
line.name.chars().take(MAX_COLS).collect::<String>() line.text.chars().take(MAX_COLS).collect::<String>()
} else { } else {
line.name.to_string() line.text.to_string()
}; };
// color the line // color the line
out.push_str(&match line.typ { out.push_str(&match line.typ {
Type::Text => color!(name, Cyan), Type::Text => color!(text, Cyan),
Type::Menu => color!(name, Blue), Type::Menu => color!(text, Blue),
Type::Info => color!(name, Yellow), Type::Info => color!(text, Yellow),
Type::HTML => color!(name, Green), Type::HTML => color!(text, Green),
Type::Error => color!(name, Red), Type::Error => color!(text, Red),
Type::Telnet => color!(name, Grey), Type::Telnet => color!(text, Grey),
typ if typ.is_download() => color!(name, Underline, White), typ if typ.is_download() => color!(text, Underline, White),
typ if !typ.is_supported() => color!(name, Red, WhiteBG), typ if !typ.is_supported() => color!(text, Red, WhiteBG),
_ => name, _ => text,
}); });
// clear rest of line // clear rest of line
@ -490,7 +490,7 @@ impl Menu {
let pattern = pattern.to_ascii_lowercase(); let pattern = pattern.to_ascii_lowercase();
for &pos in it { for &pos in it {
let line = self.lines.get(pos)?; let line = self.lines.get(pos)?;
if line.name.to_ascii_lowercase().contains(&pattern) { if line.text.to_ascii_lowercase().contains(&pattern) {
return Some(line.link); return Some(line.link);
} }
} }
@ -635,7 +635,7 @@ impl Menu {
let (typ, _, _, _) = gopher::parse_url(&url); let (typ, _, _, _) = gopher::parse_url(&url);
match typ { match typ {
Type::Search => { Type::Search => {
let prompt = format!("{}> ", line.name); let prompt = format!("{}> ", line.text);
Action::Prompt( Action::Prompt(
prompt.clone(), prompt.clone(),
Box::new(move |query| { Box::new(move |query| {
@ -646,9 +646,9 @@ impl Menu {
}), }),
) )
} }
Type::Error => Action::Error(line.name.to_string()), Type::Error => Action::Error(line.text.to_string()),
t if !t.is_supported() => Action::Error(format!("{:?} not supported", t)), t if !t.is_supported() => Action::Error(format!("{:?} not supported", t)),
_ => Action::Open(line.name.to_string(), url), _ => Action::Open(line.text.to_string(), url),
} }
} else { } else {
Action::None Action::None
@ -772,8 +772,8 @@ impl Menu {
} }
if let Some(mut line) = parse_line(line) { if let Some(mut line) = parse_line(line) {
if line.name.len() > longest { if line.text.len() > longest {
longest = line.name.len(); longest = line.text.len();
} }
if line.typ.is_link() { if line.typ.is_link() {
line.link = links.len(); line.link = links.len();
@ -817,20 +817,20 @@ pub fn parse_line(line: &str) -> Option<Line> {
line.len() line.len()
}; };
return Some(Line { return Some(Line {
name: line[1..end].into(), text: line[1..end].into(),
url: "".to_string(), url: "".to_string(),
typ, typ,
link: 0, link: 0,
}); });
} }
let mut name = "n/a"; let mut text = "n/a";
let mut sel = "(null)"; let mut sel = "(null)";
let mut host = "localhost"; let mut host = "localhost";
let mut port = "70"; let mut port = "70";
for (i, chunk) in line[1..].trim_end_matches('\r').split('\t').enumerate() { for (i, chunk) in line[1..].trim_end_matches('\r').split('\t').enumerate() {
match i { match i {
0 => name = chunk, 0 => text = chunk,
1 => sel = chunk, 1 => sel = chunk,
2 => host = chunk, 2 => host = chunk,
3 => port = chunk, 3 => port = chunk,
@ -858,7 +858,7 @@ pub fn parse_line(line: &str) -> Option<Line> {
}; };
Some(Line { Some(Line {
name: name.into(), text: text.into(),
url, url,
typ, typ,
link: 0, link: 0,
@ -896,11 +896,11 @@ i---------------------------------------------------------
assert_eq!(menu.lines[1].url, "gopher://gopher.club/1/phlogs/"); assert_eq!(menu.lines[1].url, "gopher://gopher.club/1/phlogs/");
assert_eq!(menu.lines[2].url, "gopher://sdf.org/1/maps/"); assert_eq!(menu.lines[2].url, "gopher://sdf.org/1/maps/");
assert_eq!(menu.lines[3].url, "gopher://earth.rice.edu/1Geosphere"); assert_eq!(menu.lines[3].url, "gopher://earth.rice.edu/1Geosphere");
assert_eq!(menu.lines[4].name, "wacky links"); assert_eq!(menu.lines[4].text, "wacky links");
assert_eq!(menu.lines[5].name, "-----------"); assert_eq!(menu.lines[5].text, "-----------");
assert_eq!(menu.lines[6].url, "telnet://bbs.impakt.net:6502"); assert_eq!(menu.lines[6].url, "telnet://bbs.impakt.net:6502");
assert_eq!(menu.lines[7].url, "https://github.com/my/code"); assert_eq!(menu.lines[7].url, "https://github.com/my/code");
assert_eq!(menu.lines[8].name, "-----------"); assert_eq!(menu.lines[8].text, "-----------");
} }
#[test] #[test]

Loading…
Cancel
Save