#[arg(short, long)]
relative: bool,
- /// Output in CSV format. Single row by default, or table if csv-fraction and csv-stops specified.
+ /// Output table in emacs org-mode format
+ #[arg(short, long)]
+ org: bool,
+
+ /// Output table in CSV format
#[arg(short, long)]
csv: bool,
fractions_to_steps(&fractions, cli.stops.unwrap_or(3))
};
- let row_steps = match cli.csv {
+ let row_steps = match cli.csv || cli.org {
true => {
let fractions = denominators_to_fractions(&cli.table_fraction);
fractions_to_steps(&fractions, cli.table_stops.unwrap_or(3))
}
}
+// print an f-stop table in org-mode format
+fn fstop_table_org(col_steps: &Vec<Fraction>, row_steps: &Vec<Fraction>, table: &Vec<FstopEntry>, cli: &CalcArgs) {
+ println!("|-");
+ print!("|");
+ if !cli.csv_skip_header {
+ print!(" |");
+ for col_frac in col_steps {
+ print!(" {} |", col_frac.offset_str(0, true));
+ }
+ println!();
+ println!("|-");
+ }
+ for (row, row_frac) in row_steps.iter().enumerate() {
+ print!("|");
+ if !cli.csv_skip_header {
+ print!(" {} |", row_frac.offset_str(0, true));
+ }
+ for (col, _col_frac) in col_steps.iter().enumerate() {
+ print!(" {} |", table[row*col_steps.len() + col].str(cli.precision(), cli.relative));
+ }
+ println!();
+ }
+ println!("|-");
+}
+
// print a single-rowed f-stop table for the terminal
fn fstop_table_print_row(col_steps: &Vec<Fraction>, table: &Vec<FstopEntry>, cli: &CalcArgs) {
for idx in 0..col_steps.len() {
1 => fstop_table_print_row(&col_steps, &table, &cli),
_ => match cli.csv_formulas {
true => fstop_table_formula_csv(&col_steps, &row_steps, &table, &cli),
- _ => fstop_table_csv(&col_steps, &row_steps, &table, &cli),
+ _ => match cli.org {
+ true => fstop_table_org(&col_steps, &row_steps, &table, &cli),
+ _ => fstop_table_csv(&col_steps, &row_steps, &table, &cli),
+ },
},
}
},