mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-11-07 08:24:33 +01:00
cli: Add --raw flag
This commit is contained in:
parent
676f637bda
commit
18d682c5b8
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -163,7 +163,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "kalk"
|
||||
version = "3.2.0"
|
||||
version = "3.2.1"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"regex",
|
||||
@ -175,7 +175,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "kalker"
|
||||
version = "2.2.0"
|
||||
version = "2.2.1"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"atty",
|
||||
|
@ -41,6 +41,11 @@ fn main() {
|
||||
.flag(
|
||||
Flag::new("no-leading-eq", FlagType::Bool)
|
||||
.description("Don't include an equal sign at the start of results")
|
||||
)
|
||||
.flag(
|
||||
Flag::new("raw", FlagType::Bool)
|
||||
.description("Only print a single number as the result, nothing else.")
|
||||
.alias("r")
|
||||
);
|
||||
|
||||
app.run(args);
|
||||
@ -91,7 +96,8 @@ fn default_action(context: &Context) {
|
||||
&mut parser_context,
|
||||
precision,
|
||||
format,
|
||||
context.bool_flag("no-leading-eq")
|
||||
context.bool_flag("no-leading-eq"),
|
||||
context.bool_flag("raw")
|
||||
);
|
||||
} else {
|
||||
// Direct output
|
||||
@ -101,7 +107,8 @@ fn default_action(context: &Context) {
|
||||
precision,
|
||||
10u8,
|
||||
format,
|
||||
context.bool_flag("no-leading-eq")
|
||||
context.bool_flag("no-leading-eq"),
|
||||
context.bool_flag("raw")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ pub fn eval(
|
||||
precision: u32,
|
||||
base: u8,
|
||||
format: ScientificNotationFormat,
|
||||
no_leading_equal: bool
|
||||
no_leading_equal: bool,
|
||||
raw: bool
|
||||
) {
|
||||
match parser::eval(parser, input, precision) {
|
||||
Ok(Some(mut result)) => {
|
||||
@ -19,7 +20,7 @@ pub fn eval(
|
||||
return;
|
||||
}
|
||||
|
||||
if precision == DEFAULT_PRECISION {
|
||||
if precision == DEFAULT_PRECISION && !raw {
|
||||
let mut result_str = result.to_string_pretty_format(format);
|
||||
if no_leading_equal {
|
||||
result_str = result_str
|
||||
|
@ -31,7 +31,8 @@ pub fn start(
|
||||
parser: &mut parser::Context,
|
||||
precision: u32,
|
||||
format: ScientificNotationFormat,
|
||||
no_leading_equal: bool
|
||||
no_leading_equal: bool,
|
||||
raw: bool
|
||||
) {
|
||||
let mut editor = Editor::<RLHelper>::new();
|
||||
editor.set_helper(Some(RLHelper {
|
||||
@ -78,7 +79,7 @@ pub fn start(
|
||||
match readline {
|
||||
Ok(input) => {
|
||||
editor.add_history_entry(input.as_str());
|
||||
eval_repl(&mut repl, parser, &input, precision, no_leading_equal);
|
||||
eval_repl(&mut repl, parser, &input, precision, no_leading_equal, raw);
|
||||
}
|
||||
Err(ReadlineError::Interrupted) => break,
|
||||
_ => break,
|
||||
@ -95,7 +96,8 @@ fn eval_repl(
|
||||
parser: &mut parser::Context,
|
||||
input: &str,
|
||||
precision: u32,
|
||||
no_leading_equal: bool
|
||||
no_leading_equal: bool,
|
||||
raw: bool
|
||||
) {
|
||||
if let Some(file_name) = input.strip_prefix("load ") {
|
||||
if let Some(file_path) = crate::get_input_file_by_name(file_name) {
|
||||
@ -144,7 +146,7 @@ fn eval_repl(
|
||||
"clear" => print!("\x1B[2J"),
|
||||
"exit" => process::exit(0),
|
||||
"help" => print_cli_help(),
|
||||
_ => output::eval(parser, input, precision, repl.base, repl.mode, no_leading_equal),
|
||||
_ => output::eval(parser, input, precision, repl.base, repl.mode, no_leading_equal, raw),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user