Skip to content

Commit

Permalink
Change fast-mode way work
Browse files Browse the repository at this point in the history
  • Loading branch information
rikonaka committed Feb 13, 2024
1 parent 23f996d commit 9ac5b6c
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "translator-rs"
version = "0.3.6"
version = "0.3.7"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ translator-rs -s Engligh -t French

### Faster sampling speed

If you think the translation speed is slow, you can use `fast` mode (power consumption may be higher than `slow` mode, the default is `slow` mode).
If you think the translation speed is slow, you can use `fast` mode (power consumption may be higher than default mode, default interval is `1.0` sec, you can change it to `0.1` sec).

```bash
translator-rs -f
translator-rs -f 0.1
```

### Clear screen mode
Expand Down
4 changes: 2 additions & 2 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ translator-rs -s Engligh -t French

### 加快翻译速度

如果觉得翻译速度慢可以使用 `fast` 模式(功耗可能会比 `slow` 模式高,默认是 `slow` 模式):
如果觉得翻译速度慢可以使用 `fast` 模式(功耗可能会比模式高,默认间隔为1.0秒,可以改成0.1秒):

```bash
translator-rs -f
translator-rs -f 0.1
```

新增对 Linux 上某些无法自动获得选取文字应用上的支持。某些无法自动获得选取文字的 Linux 应用现在可以通过 `ctrl-c` 来复制文字之后自动翻译。
Expand Down
1 change: 0 additions & 1 deletion release.bat

This file was deleted.

18 changes: 0 additions & 18 deletions src/deepl_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,3 @@ pub async fn translate_pro(
let translate_url = format!("https://api.deepl.com/v2/translate");
tranlate(sl, tl, content, proxy_str, auth_key, &translate_url).await
}

// #[cfg(test)]
// mod tests {
// use super::*;
// #[tokio::test]
// async fn test_deepl_free() {
// use crate::utils::convert_language;
// let sl = "English";
// let tl = "Chinese";
// let api = "deepl";
// let (sl, tl) = convert_language(sl, tl, api);
// let translate_string = "Hello";
// let auth_key = "null";
// let proxy_str = "null";
// let v = translate_free(sl, tl, translate_string, proxy_str, auth_key).await;
// println!("{:?}", v);
// }
// }
4 changes: 2 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fmt;
pub struct UnsupportApiError;
impl fmt::Display for UnsupportApiError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", "unsupport api")
write!(f, "{}", "unsupported api")
}
}
impl Error for UnsupportApiError {}
Expand All @@ -16,7 +16,7 @@ impl Error for UnsupportApiError {}
pub struct UnsupportOsError;
impl fmt::Display for UnsupportOsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", "unsupport os")
write!(f, "{}", "unsupported os")
}
}
impl Error for UnsupportOsError {}
Expand Down
25 changes: 0 additions & 25 deletions src/google_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,28 +134,3 @@ pub async fn translate_shortword(
result_vec.push(item);
Ok(result_vec)
}

// #[cfg(test)]
// mod tests {
// use super::*;
// #[tokio::test]
// async fn test_google_long() {
// use crate::utils::convert_language;
// let sl = "English";
// let tl = "Chinese";
// let api = "deepl";
// let (sl, tl) = convert_language(sl, tl, api);
// let translate_string = "Hello World!";
// let proxy_str = "socks5://192.168.1.5:1080";
// // let proxy_str = "null";
// let v = translate_longstring(sl, tl, translate_string, proxy_str)
// .await
// .unwrap();
// println!("{:?}", v);
// let translate_string = "Hello!";
// let v = translate_shortword(sl, tl, translate_string, proxy_str)
// .await
// .unwrap();
// println!("{:?}", v);
// }
// }
17 changes: 5 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ mod deepl_api;
mod errors;
mod google_api;
mod utils;
// mod youdao_api;

use deepl_api::{translate_free, translate_pro};
use errors::{UnsupportApiError, UnsupportOsError};
Expand All @@ -29,8 +28,8 @@ struct Args {
#[clap(short, long, default_value = "Chinese (Simplified)")]
tl: String,
/// Fast mode or slow mode
#[clap(short, long, action)]
fast_mode: bool,
#[clap(short, long, default_value_t = 1.0)]
fast_mode: f32,
/// Proxy set (socks5://192.168.1.1:9000)
#[clap(short, long, default_value = "null")]
proxy: String,
Expand Down Expand Up @@ -238,19 +237,14 @@ mod tests {

#[tokio::main]
async fn main() -> Result<()> {
if cfg!(target_os = "windows") {
if cfg!(not(target_os = "linux")) {
// only support linux now
return Err(UnsupportOsError.into());
}

let args = Args::parse();

let (sl, tl) = standardized_lang(&args.sl, &args.tl, &args.api)?;
let sleep_time = match args.fast_mode {
true => Duration::from_secs_f32(0.3),
_ => Duration::from_secs(1),
};
// println!("c: {}", clear_times);
let fast_mode_sleep_time = Duration::from_secs_f32(args.fast_mode);
let clear_mode = match args.clear {
0 => false,
_ => true,
Expand All @@ -265,7 +259,6 @@ async fn main() -> Result<()> {
);

let mut clear_count = args.clear;
// let mut last_selected_text = String::from("");
let mut last_text: String = String::from("");

let mut index: usize = 1;
Expand Down Expand Up @@ -312,6 +305,6 @@ async fn main() -> Result<()> {
translate_result.show(args.no_original, args.disable_auto_break);
index += 1;
}
thread::sleep(sleep_time);
thread::sleep(fast_mode_sleep_time);
}
}

0 comments on commit 9ac5b6c

Please sign in to comment.