Added 'Type help for instructions' text, and fixed ansi_colors for windows

This commit is contained in:
PaddiM8 2020-12-14 11:25:08 +01:00
parent a3bae36810
commit 562b232120
4 changed files with 11 additions and 7 deletions

View File

@ -18,7 +18,7 @@ name = "kalk"
[dependencies] [dependencies]
kalk = { path = "../kalk", version = "^1.2.6" } kalk = { path = "../kalk", version = "^1.2.6" }
rustyline = "7.0.0" rustyline = "7.0.0"
ansi_term = "0.12" ansi_term = "0.12.1"
regex = "1" regex = "1"
lazy_static = "1.4.0" lazy_static = "1.4.0"
seahorse = "1.1.1" seahorse = "1.1.1"

View File

@ -36,6 +36,9 @@ fn main() {
} }
fn default_action(context: &Context) { fn default_action(context: &Context) {
#[cfg(windows)]
ansi_term::enable_ansi_support().unwrap_or_default();
let angle_unit = if let Ok(angle_unit) = context.string_flag("angle-unit") { let angle_unit = if let Ok(angle_unit) = context.string_flag("angle-unit") {
match angle_unit.as_ref() { match angle_unit.as_ref() {
"rad" | "deg" => angle_unit, "rad" | "deg" => angle_unit,

View File

@ -22,11 +22,7 @@ pub fn eval(parser: &mut parser::Context, input: &str, precision: u32) {
} }
pub fn print_err(msg: &str) { pub fn print_err(msg: &str) {
let msg = if cfg!(windows) { Red.paint(msg).to_string();
msg.to_string()
} else {
Red.paint(msg).to_string()
};
println!("{}", msg); println!("{}", msg);
} }

View File

@ -24,6 +24,11 @@ pub fn start(mut parser: &mut parser::Context, precision: u32) {
highlighter: LineHighlighter {}, highlighter: LineHighlighter {},
validator: MatchingBracketValidator::new(), validator: MatchingBracketValidator::new(),
})); }));
println!("kalk");
println!(
"{}",
ansi_term::Color::Fixed(246).paint("Type 'help' for instructions.")
);
loop { loop {
let prompt = if cfg!(windows) { let prompt = if cfg!(windows) {
@ -77,7 +82,7 @@ impl Highlighter for LineHighlighter {
if let Some(cap) = caps.name("identifier") { if let Some(cap) = caps.name("identifier") {
match cap.as_str() { match cap.as_str() {
"rad" | "deg" | "°" => Colour::Yellow.paint(cap.as_str()).to_string(), "rad" | "deg" | "°" => Colour::Yellow.paint(cap.as_str()).to_string(),
_ => Colour::Blue.paint(cap.as_str()).to_string(), _ => Colour::Fixed(32).paint(cap.as_str()).to_string(),
} }
} else if let Some(cap) = caps.name("op") { } else if let Some(cap) = caps.name("op") {
Colour::Fixed(172).paint(cap.as_str()).to_string() Colour::Fixed(172).paint(cap.as_str()).to_string()