No known key found for this signature in database
GPG Key ID: 1F45A7C4BFB41607
3 changed files with
26 additions and
4 deletions
-
server/Cargo.toml
-
server/src/logger/color_message.rs
|
|
|
@ -14,6 +14,8 @@ uuid = {version = "0.8.1", features = ["v4"]} |
|
|
|
tokio = {version = "0.2", features = ["full"]} |
|
|
|
server_client = {git = "https://github.com/Mr-Llama-s-Wonderful-Soundboard/server_client.git", branch = "main", features = ["tokio2"]} |
|
|
|
fallible-iterator = "0.2.0" |
|
|
|
regex = "1.4.2" |
|
|
|
lazy_static = "1.4.0" |
|
|
|
|
|
|
|
# Game loading |
|
|
|
rhai = {version = "0.19.4", features = ["serde"]} |
|
|
|
|
|
|
|
@ -1,19 +1,31 @@ |
|
|
|
use lazy_static::lazy_static; |
|
|
|
use regex::Regex; |
|
|
|
use crossterm::{queue, style::Print}; |
|
|
|
|
|
|
|
use std::io::Write; |
|
|
|
|
|
|
|
pub const ANSI_RE: &str = |
|
|
|
r"[\x1b\x9b]\[[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]"; |
|
|
|
|
|
|
|
lazy_static! { |
|
|
|
pub static ref ANSI_REGEX: Regex = Regex::new(ANSI_RE).unwrap(); |
|
|
|
} |
|
|
|
|
|
|
|
pub fn print_line(message: &String, use_colors: bool, stdout: &mut std::io::Stdout) { |
|
|
|
if use_colors { |
|
|
|
let mut s = String::new(); |
|
|
|
let mut highlight = false; |
|
|
|
let mut i = 0; |
|
|
|
let mut current = "\x1B[0m".to_string(); |
|
|
|
for c in message.chars() { |
|
|
|
if c == '`' { |
|
|
|
// queue!(stdout, Print(format!("{}`", highlight))).unwrap();
|
|
|
|
if highlight { |
|
|
|
let styled = format!( |
|
|
|
"\x1B[{}m{}\x1B[0m", |
|
|
|
"\x1B[{}m{}{}", |
|
|
|
fern::colors::Color::Blue.to_fg_str(), |
|
|
|
s |
|
|
|
s, |
|
|
|
current |
|
|
|
); |
|
|
|
queue!(stdout, Print(styled)).unwrap(); |
|
|
|
s = String::new(); |
|
|
|
@ -23,8 +35,16 @@ pub fn print_line(message: &String, use_colors: bool, stdout: &mut std::io::Stdo |
|
|
|
} |
|
|
|
highlight = !highlight; |
|
|
|
continue; |
|
|
|
}else{ |
|
|
|
if !highlight { |
|
|
|
if let Some(m) = ANSI_REGEX.find_at(message.as_str(), i) { |
|
|
|
if i == m.start() { |
|
|
|
current = m.as_str().to_string(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
i += 1; |
|
|
|
s.push(c); |
|
|
|
} |
|
|
|
queue!(stdout, Print(&s)).unwrap(); |
|
|
|
|