mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-05-06 13:38:04 +03:00
pixtaded and termion fix with colored import
This commit is contained in:
parent
46e1389617
commit
8fcbb01c5a
19
Cargo.lock
generated
19
Cargo.lock
generated
@ -15,6 +15,7 @@ dependencies = [
|
||||
name = "bRAC"
|
||||
version = "1.99.2"
|
||||
dependencies = [
|
||||
"colored",
|
||||
"rand",
|
||||
"regex",
|
||||
"termion",
|
||||
@ -38,6 +39,15 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "colored"
|
||||
version = "3.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.3.1"
|
||||
@ -219,6 +229,15 @@ dependencies = [
|
||||
"wit-bindgen-rt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
|
@ -6,4 +6,5 @@ edition = "2021"
|
||||
[dependencies]
|
||||
rand = "0.9.0"
|
||||
termion = "4.0.3"
|
||||
regex = "1.11.1"
|
||||
regex = "1.11.1"
|
||||
colored = "3.0.0"
|
65
src/main.rs
65
src/main.rs
@ -2,6 +2,7 @@ use std::{
|
||||
error::Error, io::{stdin, stdout, BufRead, Read, Write}, net::TcpStream, sync::{Arc, RwLock}, thread
|
||||
};
|
||||
|
||||
use colored::Colorize;
|
||||
use rand::random;
|
||||
use regex::Regex;
|
||||
use termion::{color, event::Key, input::TermRead, raw::IntoRawMode, style};
|
||||
@ -119,45 +120,56 @@ fn on_message(message: String) -> String {
|
||||
let nick = &captures[2];
|
||||
let content = &captures[3];
|
||||
|
||||
let mut result = String::new();
|
||||
result.push_str(&format!("{}{}[{}] ", color::Fg(color::White), style::Faint, date));
|
||||
result.push_str(&format!("{}{}{}<{}> ", style::Reset, style::Bold, color::Fg(color::Cyan), nick));
|
||||
result.push_str(&format!("{}{}{}", color::Fg(color::White), style::Blink, content));
|
||||
result.push_str(&style::Reset.to_string());
|
||||
result
|
||||
} else if let Some(captures) = Regex::new(&format!("\\[(.*?)\\] {}<(.*?)> (.*)", MAGIC_KEY)).unwrap().captures(&message) {
|
||||
format!(
|
||||
"{} {} {}",
|
||||
format!("[{}]", date).white().dimmed(),
|
||||
format!("<{}>", nick).cyan().bold(),
|
||||
content.white().blink()
|
||||
)
|
||||
} else if let Some(captures) = Regex::new(&format!(r"\[(.*?)\] {}<(.*?)> (.*)", MAGIC_KEY)).unwrap().captures(&message) {
|
||||
let date = &captures[1];
|
||||
let nick = &captures[2];
|
||||
let content = &captures[3];
|
||||
|
||||
let mut result = String::new();
|
||||
result.push_str(&format!("{}{}[{}] ", color::Fg(color::White), style::Faint, date));
|
||||
result.push_str(&format!("{}{}{}<{}> ", style::Reset, style::Bold, color::Fg(color::Green), nick));
|
||||
result.push_str(&format!("{}{}{}", color::Fg(color::White), style::Blink, content));
|
||||
result.push_str(&style::Reset.to_string());
|
||||
result
|
||||
format!(
|
||||
"{} {} {}",
|
||||
format!("[{}]", date).white().dimmed(),
|
||||
format!("<{}>", nick).green().bold(),
|
||||
content.white().blink()
|
||||
)
|
||||
} else if let Some(captures) = Regex::new(r"\[(.*?)\] (.*?): (.*)").unwrap().captures(&message) {
|
||||
let date = &captures[1];
|
||||
let nick = &captures[2];
|
||||
let content = &captures[3];
|
||||
|
||||
let mut result = String::new();
|
||||
result.push_str(&format!("{}{}[{}] ", color::Fg(color::White), style::Faint, date));
|
||||
result.push_str(&format!("{}{}{}<{}> ", style::Reset, style::Bold, color::Fg(color::LightMagenta), nick));
|
||||
result.push_str(&format!("{}{}{}", color::Fg(color::White), style::Blink, content));
|
||||
result.push_str(&style::Reset.to_string());
|
||||
result
|
||||
format!(
|
||||
"{} {} {}",
|
||||
format!("[{}]", date).white().dimmed(),
|
||||
format!("<{}>", nick).magenta().bold(),
|
||||
content.white().blink()
|
||||
)
|
||||
} else if let Some(captures) = Regex::new(r"\[(.*?)\] \u{2550}\u{2550}\u{2550}<(.*?)> (.*)").unwrap().captures(&message) {
|
||||
let date = &captures[1];
|
||||
let nick = &captures[2];
|
||||
let content = &captures[3];
|
||||
|
||||
format!(
|
||||
"{} {} {}",
|
||||
format!("[{}]", date).white().dimmed(),
|
||||
format!("<{}>", nick).bright_red().bold(),
|
||||
content.white().blink()
|
||||
)
|
||||
} else if let Some(captures) = Regex::new(r"\[(.*?)\] (.*)").unwrap().captures(&message) {
|
||||
let date = &captures[1];
|
||||
let content = &captures[2];
|
||||
|
||||
let mut result = String::new();
|
||||
result.push_str(&format!("{}{}[{}] ", color::Fg(color::White), style::Faint, date));
|
||||
result.push_str(&format!("{}{}{}{}", style::Reset, color::Fg(color::White), style::Blink, content));
|
||||
result.push_str(&style::Reset.to_string());
|
||||
result
|
||||
format!(
|
||||
"{} {}",
|
||||
format!("[{}]", date).white().dimmed(),
|
||||
content.white().blink()
|
||||
)
|
||||
} else {
|
||||
message
|
||||
message.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,6 +220,7 @@ fn main() {
|
||||
send_message(&host, &format!("{}<{}> {}", MAGIC_KEY, name, message)).expect("Error sending message");
|
||||
input.write().unwrap().clear();
|
||||
}
|
||||
print_console(&messages.read().unwrap(), &input.read().unwrap()).expect("Error printing console");
|
||||
}
|
||||
Key::Backspace => {
|
||||
input.write().unwrap().pop();
|
||||
@ -221,7 +234,5 @@ fn main() {
|
||||
Key::Ctrl('x') => break,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
print_console(&messages.read().unwrap(), &input.read().unwrap()).expect("Error printing console");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user