more library tricks

This commit is contained in:
MeexReay 2025-04-14 20:35:57 +03:00
parent e548d85841
commit 17b2511217
4 changed files with 25 additions and 32 deletions

View File

@ -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<Context>, message: String) -> Option<String> {
})
}
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()))

View File

@ -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
};

View File

@ -1,5 +1,6 @@
#![allow(non_snake_case)]
mod proto;
pub use proto::*;
pub mod config;
pub mod chat;
pub mod util;
pub mod proto;

View File

@ -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() {