diff --git a/src/chat.rs b/src/chat.rs index dc3e3ef..e659a23 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -8,13 +8,24 @@ use colored::{Color, Colorize}; use super::{ proto::{connect, read_messages, send_message, send_message_spoof_auth}, - IP_REGEX, util::sanitize_text, - COLORED_USERNAMES, - DATE_REGEX, config::Context }; +use lazy_static::lazy_static; +use regex::Regex; + +lazy_static! { + pub static ref DATE_REGEX: Regex = Regex::new(r"\[(.*?)\] (.*)").unwrap(); + pub static ref IP_REGEX: Regex = Regex::new(r"\{(.*?)\} (.*)").unwrap(); + pub static ref COLORED_USERNAMES: Vec<(Regex, Color)> = vec![ + (Regex::new(r"\u{B9AC}\u{3E70}<(.*?)> (.*)").unwrap(), Color::Green), // bRAC + (Regex::new(r"\u{2550}\u{2550}\u{2550}<(.*?)> (.*)").unwrap(), Color::BrightRed), // CRAB + (Regex::new(r"\u{00B0}\u{0298}<(.*?)> (.*)").unwrap(), Color::Magenta), // Mefidroniy + (Regex::new(r"<(.*?)> (.*)").unwrap(), Color::Cyan), // clRAC + ]; +} + #[cfg(not(feature = "pretty"))] pub mod minimal_tui; #[cfg(not(feature = "pretty"))] @@ -249,7 +260,7 @@ pub fn format_message(ctx: Arc, message: String) -> Option { }) } -fn find_username_color(message: &str) -> Option<(String, String, Color)> { +pub fn find_username_color(message: &str) -> Option<(String, String, Color)> { for (re, color) in COLORED_USERNAMES.iter() { if let Some(captures) = re.captures(message) { return Some((captures[1].to_string(), captures[2].to_string(), color.clone())) diff --git a/src/chat/pretty_tui.rs b/src/chat/pretty_tui.rs index b08bb8e..c9f7de8 100644 --- a/src/chat/pretty_tui.rs +++ b/src/chat/pretty_tui.rs @@ -17,7 +17,9 @@ use std::{ use super::{ super::{ - config::Context, proto::{connect, read_messages}, util::{char_index_to_byte_index, string_chunks} + config::Context, + proto::{connect, read_messages}, + util::{char_index_to_byte_index, string_chunks} }, format_message, on_send_message }; diff --git a/src/lib.rs b/src/lib.rs index 31e6b14..1d108fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![allow(non_snake_case)] -mod proto; - -pub use proto::*; \ No newline at end of file +pub mod config; +pub mod chat; +pub mod util; +pub mod proto; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 19b613c..d842638 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,30 +1,9 @@ use std::sync::Arc; use clap::Parser; -use colored::Color; -use config::{configure, get_config_path, load_config, Args, Context}; -use proto::{connect, read_messages, send_message}; -use regex::Regex; -use lazy_static::lazy_static; -use chat::run_main_loop; - - -lazy_static! { - static ref DATE_REGEX: Regex = Regex::new(r"\[(.*?)\] (.*)").unwrap(); - static ref IP_REGEX: Regex = Regex::new(r"\{(.*?)\} (.*)").unwrap(); - static ref COLORED_USERNAMES: Vec<(Regex, Color)> = vec![ - (Regex::new(r"\u{B9AC}\u{3E70}<(.*?)> (.*)").unwrap(), Color::Green), // bRAC - (Regex::new(r"\u{2550}\u{2550}\u{2550}<(.*?)> (.*)").unwrap(), Color::BrightRed), // CRAB - (Regex::new(r"\u{00B0}\u{0298}<(.*?)> (.*)").unwrap(), Color::Magenta), // Mefidroniy - (Regex::new(r"<(.*?)> (.*)").unwrap(), Color::Cyan), // clRAC - ]; -} - - -mod config; -mod chat; -mod proto; -mod util; +use bRAC::config::{configure, get_config_path, load_config, Args, Context}; +use bRAC::proto::{connect, read_messages, send_message}; +use bRAC::chat::run_main_loop; fn main() {