terminal output
This commit is contained in:
+138
@@ -0,0 +1,138 @@
|
||||
use clap::{Parser, ValueEnum};
|
||||
use colored::*;
|
||||
|
||||
/// Concentration of plaster slurry
|
||||
/// in parts of water per 100 parts plaster by weight
|
||||
const DEFAULT_CONCENTRATION: f64 = 70.0;
|
||||
/// Density of plaster slurry (g/L).
|
||||
const DEFAULT_DENSITY: f64 = 1674.0;
|
||||
const PERCENT: f64 = 100.0;
|
||||
/// The amount of slack added
|
||||
const SLACK: f64 = 0.10;
|
||||
/// The multiplier for the water that becomes part of the mold
|
||||
///
|
||||
/// 18 parts water for every part plaster becomes part
|
||||
/// of the mold.
|
||||
const DRY_WEIGHT_MULTIPLIER: f64 = 1.18;
|
||||
|
||||
// Color and Styling Configurations
|
||||
const COLOR_PARAM: Color = Color::Yellow;
|
||||
const COLOR_PLASTER: Color = Color::Green;
|
||||
const COLOR_WATER: Color = Color::Blue;
|
||||
const COLOR_TARGET: Color = Color::Magenta;
|
||||
|
||||
#[derive(ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum ColorChoice {
|
||||
Never,
|
||||
Auto,
|
||||
Always,
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about = "Calculates plaster mixing weights", long_about = None)]
|
||||
struct Args {
|
||||
/// Volume in cm³ or ml
|
||||
volume: f64,
|
||||
|
||||
/// Concentration (parts water per 100 parts plaster by weight)
|
||||
#[arg(short, long, default_value_t = 70.0)]
|
||||
concentration: f64,
|
||||
|
||||
/// Density in grams per liter (defaults to 1674 if concentration is 70)
|
||||
#[arg(short, long)]
|
||||
density: Option<f64>,
|
||||
|
||||
/// Control terminal color output
|
||||
#[arg(long, default_value = "auto")]
|
||||
color: ColorChoice,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
|
||||
// Configure color output globally based on the CLI argument
|
||||
match args.color {
|
||||
ColorChoice::Always => colored::control::set_override(true),
|
||||
ColorChoice::Never => colored::control::set_override(false),
|
||||
ColorChoice::Auto => {} // Respects standard stream capabilities (default)
|
||||
}
|
||||
|
||||
// Determine density and target wet weight
|
||||
let density = args.density.or_else(|| {
|
||||
if (args.concentration - DEFAULT_CONCENTRATION).abs() < f64::EPSILON {
|
||||
Some(DEFAULT_DENSITY)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
let target_wet_weight = density.map(|d| (args.volume / 1000.0) * d);
|
||||
|
||||
let (plaster_nominal, water_nominal) = match target_wet_weight {
|
||||
Some(wet_weight) => {
|
||||
let plaster = wet_weight / (1.0 + (args.concentration / PERCENT));
|
||||
let water = plaster * (args.concentration / PERCENT);
|
||||
(Some(plaster), Some(water))
|
||||
}
|
||||
None => (None, None),
|
||||
};
|
||||
|
||||
// Output Header
|
||||
println!("--- Plaster Calculation Parameters ---");
|
||||
println!(
|
||||
"Volume: {}ml",
|
||||
format!("{}", args.volume).color(COLOR_PARAM).bold()
|
||||
);
|
||||
println!(
|
||||
"Concentration: {}g water per 100g plaster",
|
||||
format!("{}", args.concentration).color(COLOR_PARAM).bold()
|
||||
);
|
||||
|
||||
let density_str = density.map_or("Not provided/calculated".to_string(), |d| {
|
||||
format!("{}g/L", format!("{}", d).color(COLOR_PARAM).bold())
|
||||
});
|
||||
println!("Density: {}", density_str);
|
||||
println!("--------------------------------------");
|
||||
|
||||
// Output Mixing Amounts and Target Weights
|
||||
if let (Some(p_nom), Some(w_nom)) = (plaster_nominal, water_nominal) {
|
||||
let p_slack = p_nom * (1.0 + SLACK);
|
||||
let w_slack = w_nom * (1.0 + SLACK);
|
||||
let dry_weight = p_nom * DRY_WEIGHT_MULTIPLIER;
|
||||
|
||||
println!("Mixing Amounts:");
|
||||
println!(" Nominal:");
|
||||
println!(
|
||||
" Plaster: {}g",
|
||||
format!("{:.1}", p_nom).color(COLOR_PLASTER)
|
||||
);
|
||||
println!(
|
||||
" Water: {}g",
|
||||
format!("{:.1}", w_nom).color(COLOR_WATER)
|
||||
);
|
||||
println!(" {:2}% Slack:", SLACK * PERCENT);
|
||||
println!(
|
||||
" Plaster: {}g",
|
||||
format!("{:.1}", p_slack).color(COLOR_PLASTER).bold()
|
||||
);
|
||||
println!(
|
||||
" Water: {}g",
|
||||
format!("{:.1}", w_slack).color(COLOR_WATER).bold()
|
||||
);
|
||||
|
||||
println!("\nTarget Weights:");
|
||||
println!(
|
||||
" Wet Cast: {}g",
|
||||
format!("{:.1}", target_wet_weight.unwrap())
|
||||
.color(COLOR_TARGET)
|
||||
.bold()
|
||||
);
|
||||
println!(
|
||||
" Dry Cast: {}g",
|
||||
format!("{:.1}", dry_weight).color(COLOR_TARGET).bold()
|
||||
);
|
||||
} else {
|
||||
println!("{}",
|
||||
"Target weights and mixing amounts cannot be calculated. Please specify a density with `-d` for any non-70 concentration.".red()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user