Parse the command line options.
(call: &EvaluatedCall)
| 51 | |
| 52 | /// Parse the command line options. |
| 53 | fn parse_cli_opts(call: &EvaluatedCall) -> Result<CliOpts, LabeledError> { |
| 54 | // scale the width and height to the size of the terminal unless specified on the cli |
| 55 | let height_op: Option<u32> = call.get_flag("height").map(|e| e.map(|f: i64| f as u32))?; |
| 56 | let width_op: Option<u32> = call.get_flag("width").map(|e| e.map(|f: i64| f as u32))?; |
| 57 | |
| 58 | let mut height: Option<u32>; |
| 59 | let mut width: Option<u32>; |
| 60 | |
| 61 | if let Some((w, h)) = term_size::dimensions() { |
| 62 | // don't know why I need to scale this, but I do - I hope it works |
| 63 | // as intended for other terminals. |
| 64 | height = Some(height_op.unwrap_or((h as f32 * 1.7) as u32)); |
| 65 | width = Some(width_op.unwrap_or((w as f32 * 1.7) as u32)); |
| 66 | |
| 67 | // textplot panics if either of these are below 32 units. |
| 68 | if height.unwrap() < 32 { |
| 69 | height = Some(32); |
| 70 | } |
| 71 | if width.unwrap() < 32 { |
| 72 | width = Some(32); |
| 73 | } |
| 74 | } else { |
| 75 | // we couldnt detect terminal size for some reason |
| 76 | height = height_op; |
| 77 | width = width_op; |
| 78 | } |
| 79 | |
| 80 | let legend = call.has_flag("legend")?; |
| 81 | let steps = call.has_flag("steps")?; |
| 82 | let bars = call.has_flag("bars")?; |
| 83 | let points = call.has_flag("points")?; |
| 84 | let bins: Option<u32> = call.get_flag("bins").map(|e| e.map(|f: i64| f as u32))?; |
| 85 | let title: Option<String> = call.get_flag("title")?; |
| 86 | |
| 87 | Ok(CliOpts { |
| 88 | height_op: height, |
| 89 | width_op: width, |
| 90 | legend, |
| 91 | steps, |
| 92 | bars, |
| 93 | points, |
| 94 | bins, |
| 95 | title, |
| 96 | }) |
| 97 | } |
| 98 | |
| 99 | /// The shape of the plot. Default is `Shape::Lines`, |
| 100 | /// but also includes `Shape::Bars` and `Shape::Steps`. |
no outgoing calls
no test coverage detected