RGB support
This commit is contained in:
parent
9caa3c168e
commit
cfc052a65a
@ -19,6 +19,8 @@
|
||||
#WHITE
|
||||
#CYAN
|
||||
#LBLACK (light black, a dark gray in fact)
|
||||
#Will definitely add RGB support, stay tuned.
|
||||
prompt: "$COLORLBLACK_ !$HISTNUMBER_$COLORCYAN_[$USER_@$HOSTNAME_] $DIR_> $COLORRESET_"
|
||||
#RGB !
|
||||
#RGB is defined as $RGB|red|green|blue_
|
||||
#For example $RGB|108|84|30_ gives you an ugly shade of brown
|
||||
prompt: "$COLORLBLACK_ !$HISTNUMBER_$COLORCYAN_[$USER_@$HOSTNAME_]$RGB|125|0|125_$DIR_> $COLORRESET_"
|
||||
|
||||
|
@ -2,6 +2,7 @@ use users::{get_user_by_uid, get_current_uid};
|
||||
use termion::color;
|
||||
use std::{env, fs};
|
||||
use std::collections::HashMap;
|
||||
use regex::Regex;
|
||||
|
||||
extern crate dirs;
|
||||
|
||||
@ -50,6 +51,7 @@ impl SqishConf {
|
||||
hotkeys: HashMap::new(),
|
||||
};
|
||||
|
||||
out_conf.handle_rgb();
|
||||
out_conf.handle_colors();
|
||||
|
||||
return Ok(out_conf);
|
||||
@ -94,6 +96,7 @@ impl SqishConf {
|
||||
prompt = prompt.to_owned();
|
||||
self.promptline = prompt;
|
||||
self.handle_colors();
|
||||
self.handle_rgb();
|
||||
}
|
||||
|
||||
|
||||
@ -117,7 +120,49 @@ impl SqishConf {
|
||||
prompt = prompt.replace("$COLORRESET_", &reset);
|
||||
let promptown = prompt.to_owned();
|
||||
self.promptline = promptown;
|
||||
|
||||
}
|
||||
|
||||
fn handle_rgb(&mut self) {
|
||||
let re = Regex::new(r"\$RGB[^_]*_").unwrap();
|
||||
let promptline_copy = &self.promptline.clone();
|
||||
let matches = re.find_iter(promptline_copy);
|
||||
//println!("Matches : {:?}", &matches.count());
|
||||
|
||||
for m in matches {
|
||||
//Copy of the text used for parsing by replacement
|
||||
let mut matchtext = String::from(m.as_str());
|
||||
//Keep a copy of the original...
|
||||
let matchtext_copy = matchtext.clone();
|
||||
|
||||
//Start replacing...
|
||||
matchtext = matchtext.replace("$RGB", "");
|
||||
matchtext = matchtext.replace("_", "");
|
||||
matchtext = matchtext.replace("|", " ");
|
||||
matchtext = String::from(matchtext.trim());
|
||||
let matchvalues = matchtext
|
||||
.split_whitespace()
|
||||
.collect::<Vec<&str>>();
|
||||
//We now have a Vector of values that must
|
||||
//converted to u8 before being used by termion
|
||||
//println!("MATCH {:?}", matchvalues);
|
||||
|
||||
//Get the color...
|
||||
let red: u8 = matchvalues[0].parse().unwrap_or(108);
|
||||
let green: u8 = matchvalues[1].parse().unwrap_or(84);
|
||||
let blue: u8 = matchvalues[0].parse().unwrap_or(30);
|
||||
|
||||
let color = color::Fg(color::Rgb {
|
||||
0: red,
|
||||
1: green,
|
||||
2: blue,
|
||||
});
|
||||
let color_display = format!("{}", color);
|
||||
//...and replace in promptline
|
||||
let out_str = self.promptline.replace(&matchtext_copy, &color_display);
|
||||
let out_str = out_str.to_owned();
|
||||
*&mut self.promptline = out_str;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user