Skip to content

Commit 07aa0f5

Browse files
committed
添加ldoceonline在线释义
1 parent 009100c commit 07aa0f5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ fn get_remote_json_translation(query: &str, cache_db: &DB, update_cache: bool, l
4848

4949
slog_debug!(logger, "开始从网络获取翻译结果");
5050

51-
let mut res = try!(client.get(&request_url).header(Connection::close()).send());
51+
let mut res = client.get(&request_url).header(Connection::close()).send()?;
5252

5353
let mut body = String::new();
5454
res.read_to_string(&mut body)?;
5555

5656
slog_debug!(logger, "json content: {}", body);
5757

58-
let mut trans_result: trans_type::Translation = try!(serde_json::from_str(body.as_str()));
58+
let mut trans_result: trans_type::Translation = serde_json::from_str(body.as_str())?;
5959
trans_result.logger = Some(logger);
6060

6161
if update_cache {

src/trans_type.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ impl<'a> YDCVFormatter for Translation<'a> {
4040
if let Some(ref logger) = self.logger {
4141
slog_info!(logger, "yellow_star: {:?}", yellow_star);
4242
};
43+
4344
let mut header_str = String::new();
4445
if let Some(ref translations) = self.translation {
45-
header_str.push_str(&format!(" {}\n\t{} ", colour_purple.paint("Translation:"), yellow_star));
46+
header_str.push_str(&format!("{}\n {}\n\t{} ", style_underline.paint(self.query.as_str()), colour_purple.paint("Translation:"), yellow_star));
4647
if let Some(ref logger) = self.logger {
4748
slog_info!(logger, "current header_str: {:?}", header_str);
4849
};
@@ -91,6 +92,10 @@ impl<'a> YDCVFormatter for Translation<'a> {
9192
}
9293
}
9394

95+
let mut online_str = String::new();
96+
online_str.push_str(&format!("\n {}", colour_purple.paint("Online Resource:")));
97+
online_str.push_str(&format!("\n\t* {}{}\n", style_underline.paint("http://www.ldoceonline.com/search/?q="), style_underline.paint(self.query.as_str())));
98+
9499
if !header_str.is_empty() {
95100
header_str.push_str("\n");
96101
}
@@ -99,6 +104,7 @@ impl<'a> YDCVFormatter for Translation<'a> {
99104
header_str.push_str("\n");
100105
}
101106
header_str.push_str(&reference_str);
107+
header_str.push_str(&online_str);
102108
header_str
103109
}
104110
}

0 commit comments

Comments
 (0)