commit aaa849da8d9f6ebc6c35abffc1566e9e8273a6c6
parent 417dcefcf83a3ff6e098fe0c18f85861327b0a3e
Author: Strange <StrangeGuy6228@protonmail.com>
Date: Fri, 29 Mar 2024 00:43:52 +0530
added shift + T to translate to eng with translate-shell program
Diffstat:
2 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
@@ -40,11 +40,13 @@ Pre-buit binaries can be found on the [official website](http://git.dkforestseea
[ Only for members+ users ]
> This is your warning @username, will be kicked next !rules
- Can hide messages with `backspace`, hidden messages can be viewed by toggling
- `ctrl+H`.
+ `ctrl+ H`.
> - Hidden messages are just hidden from the view, they are not deleted
> - Deleted messages once hidden can't be viewed again
- Download an embedded file into cwd with `d`
- Download an embedded file and open it with xdg-open into cwd with `D`
+- `shift + T` for translating text to english. [ must have translate-shell installed on arch or debain ]
+ > pacman -S translate-shell
### Editing mode
diff --git a/src/main.rs b/src/main.rs
@@ -789,14 +789,14 @@ impl LeChatPHPClient {
..
} => self.handle_normal_mode_key_event_yank_link(app),
- //straneEdit
+ //Strange
KeyEvent {
code: KeyCode::Char('D'),
modifiers: KeyModifiers::SHIFT,
..
} => self.handle_normal_mode_key_event_download_link(app),
- //StrangeEdit
+ //Strange
KeyEvent {
code: KeyCode::Char('d'),
modifiers: KeyModifiers::NONE,
@@ -874,6 +874,11 @@ impl LeChatPHPClient {
..
} => self.handle_normal_mode_key_event_warn(app),
KeyEvent {
+ code: KeyCode::Char('T'),
+ modifiers: KeyModifiers::SHIFT,
+ ..
+ } => self.handle_normal_mode_key_event_translate(app, messages),
+ KeyEvent {
code: KeyCode::Char('u'),
modifiers: KeyModifiers::CONTROL,
..
@@ -1136,7 +1141,7 @@ impl LeChatPHPClient {
}
}
- //StrangeEdit
+ //Strange
fn handle_normal_mode_key_event_download_link(&mut self, app: &mut App) {
if let Some(idx) = app.items.state.selected() {
if let Some(item) = app.items.items.get(idx) {
@@ -1337,6 +1342,40 @@ impl LeChatPHPClient {
}
}
+ //Strange
+ fn handle_normal_mode_key_event_translate(
+ &mut self,
+ app: &mut App,
+ messages: &Arc<Mutex<Vec<Message>>>,
+ ) {
+ log::error!("translate running");
+ if let Some(idx) = app.items.state.selected() {
+ log::error!("1353");
+ let mut message_lock = messages.lock().unwrap();
+ if let Some(message) = message_lock.get_mut(idx) {
+ log::error!("1356");
+ let original_text = &mut message.text;
+ let output = Command::new("trans")
+ .arg("-b")
+ .arg(&original_text.text())
+ .output()
+ .expect("Failed to execute translation command");
+
+ if output.status.success() {
+ if let Ok(new_text) = String::from_utf8(output.stdout) {
+ *original_text = StyledText::Text(new_text.trim().to_owned());
+ log::error!("Translation successful: {}", new_text);
+ } else {
+ log::error!("Failed to decode translation output as UTF-8");
+ }
+ } else {
+ log::error!("Translation command failed with error: {:?}", output.status);
+ }
+ }
+ }
+ }
+
+ //Strange
fn handle_normal_mode_key_event_warn(&mut self, app: &mut App) {
if let Some(idx) = app.items.state.selected() {
if let Some(username) = get_username(
@@ -1478,7 +1517,7 @@ impl LeChatPHPClient {
self.post_msg(PostType::Upload(file_path, send_to, msg))
.unwrap();
} else if input.starts_with("!warn") {
- // StrangeEdit
+ // Strange
let msg: String = input
.find('@')
.map(|index| input[index..].to_string())