mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-05-07 14:08:02 +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"
|
name = "bRAC"
|
||||||
version = "1.99.2"
|
version = "1.99.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"colored",
|
||||||
"rand",
|
"rand",
|
||||||
"regex",
|
"regex",
|
||||||
"termion",
|
"termion",
|
||||||
@ -38,6 +39,15 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
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]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
@ -219,6 +229,15 @@ dependencies = [
|
|||||||
"wit-bindgen-rt",
|
"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]]
|
[[package]]
|
||||||
name = "windows-targets"
|
name = "windows-targets"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
|
@ -6,4 +6,5 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
rand = "0.9.0"
|
rand = "0.9.0"
|
||||||
termion = "4.0.3"
|
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
|
error::Error, io::{stdin, stdout, BufRead, Read, Write}, net::TcpStream, sync::{Arc, RwLock}, thread
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use colored::Colorize;
|
||||||
use rand::random;
|
use rand::random;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use termion::{color, event::Key, input::TermRead, raw::IntoRawMode, style};
|
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 nick = &captures[2];
|
||||||
let content = &captures[3];
|
let content = &captures[3];
|
||||||
|
|
||||||
let mut result = String::new();
|
format!(
|
||||||
result.push_str(&format!("{}{}[{}] ", color::Fg(color::White), style::Faint, date));
|
"{} {} {}",
|
||||||
result.push_str(&format!("{}{}{}<{}> ", style::Reset, style::Bold, color::Fg(color::Cyan), nick));
|
format!("[{}]", date).white().dimmed(),
|
||||||
result.push_str(&format!("{}{}{}", color::Fg(color::White), style::Blink, content));
|
format!("<{}>", nick).cyan().bold(),
|
||||||
result.push_str(&style::Reset.to_string());
|
content.white().blink()
|
||||||
result
|
)
|
||||||
} else if let Some(captures) = Regex::new(&format!("\\[(.*?)\\] {}<(.*?)> (.*)", MAGIC_KEY)).unwrap().captures(&message) {
|
} else if let Some(captures) = Regex::new(&format!(r"\[(.*?)\] {}<(.*?)> (.*)", MAGIC_KEY)).unwrap().captures(&message) {
|
||||||
let date = &captures[1];
|
let date = &captures[1];
|
||||||
let nick = &captures[2];
|
let nick = &captures[2];
|
||||||
let content = &captures[3];
|
let content = &captures[3];
|
||||||
|
|
||||||
let mut result = String::new();
|
format!(
|
||||||
result.push_str(&format!("{}{}[{}] ", color::Fg(color::White), style::Faint, date));
|
"{} {} {}",
|
||||||
result.push_str(&format!("{}{}{}<{}> ", style::Reset, style::Bold, color::Fg(color::Green), nick));
|
format!("[{}]", date).white().dimmed(),
|
||||||
result.push_str(&format!("{}{}{}", color::Fg(color::White), style::Blink, content));
|
format!("<{}>", nick).green().bold(),
|
||||||
result.push_str(&style::Reset.to_string());
|
content.white().blink()
|
||||||
result
|
)
|
||||||
} else if let Some(captures) = Regex::new(r"\[(.*?)\] (.*?): (.*)").unwrap().captures(&message) {
|
} else if let Some(captures) = Regex::new(r"\[(.*?)\] (.*?): (.*)").unwrap().captures(&message) {
|
||||||
let date = &captures[1];
|
let date = &captures[1];
|
||||||
let nick = &captures[2];
|
let nick = &captures[2];
|
||||||
let content = &captures[3];
|
let content = &captures[3];
|
||||||
|
|
||||||
let mut result = String::new();
|
format!(
|
||||||
result.push_str(&format!("{}{}[{}] ", color::Fg(color::White), style::Faint, date));
|
"{} {} {}",
|
||||||
result.push_str(&format!("{}{}{}<{}> ", style::Reset, style::Bold, color::Fg(color::LightMagenta), nick));
|
format!("[{}]", date).white().dimmed(),
|
||||||
result.push_str(&format!("{}{}{}", color::Fg(color::White), style::Blink, content));
|
format!("<{}>", nick).magenta().bold(),
|
||||||
result.push_str(&style::Reset.to_string());
|
content.white().blink()
|
||||||
result
|
)
|
||||||
|
} 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) {
|
} else if let Some(captures) = Regex::new(r"\[(.*?)\] (.*)").unwrap().captures(&message) {
|
||||||
let date = &captures[1];
|
let date = &captures[1];
|
||||||
let content = &captures[2];
|
let content = &captures[2];
|
||||||
|
|
||||||
let mut result = String::new();
|
format!(
|
||||||
result.push_str(&format!("{}{}[{}] ", color::Fg(color::White), style::Faint, date));
|
"{} {}",
|
||||||
result.push_str(&format!("{}{}{}{}", style::Reset, color::Fg(color::White), style::Blink, content));
|
format!("[{}]", date).white().dimmed(),
|
||||||
result.push_str(&style::Reset.to_string());
|
content.white().blink()
|
||||||
result
|
)
|
||||||
} else {
|
} else {
|
||||||
message
|
message.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,6 +220,7 @@ fn main() {
|
|||||||
send_message(&host, &format!("{}<{}> {}", MAGIC_KEY, name, message)).expect("Error sending message");
|
send_message(&host, &format!("{}<{}> {}", MAGIC_KEY, name, message)).expect("Error sending message");
|
||||||
input.write().unwrap().clear();
|
input.write().unwrap().clear();
|
||||||
}
|
}
|
||||||
|
print_console(&messages.read().unwrap(), &input.read().unwrap()).expect("Error printing console");
|
||||||
}
|
}
|
||||||
Key::Backspace => {
|
Key::Backspace => {
|
||||||
input.write().unwrap().pop();
|
input.write().unwrap().pop();
|
||||||
@ -221,7 +234,5 @@ fn main() {
|
|||||||
Key::Ctrl('x') => break,
|
Key::Ctrl('x') => break,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
print_console(&messages.read().unwrap(), &input.read().unwrap()).expect("Error printing console");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user