Skip to content

Commit

Permalink
No need to use Option for boolean values.
Browse files Browse the repository at this point in the history
This commit simplify the code without changing the logic.
I use [this trick](TeXitoi/structopt#93 (comment)) to be able to define a default value for a boolean field.
  • Loading branch information
IohannRabeson committed Dec 22, 2019
1 parent d023f11 commit d3073e0
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use structopt::StructOpt;
use app::UI;
use core::time;
use std::time::{SystemTime, UNIX_EPOCH};
use structopt::StructOpt;
use termion::async_stdin;
use termion::input::TermRead;
use app::UI;
use core::time;


mod app;
mod plotting_utils;
mod widget_progress_bar;
mod widget_main_chart;
mod widget_progress_bar;
mod widget_text_output;

static ONE_BILLION: f32 = 1000000000.0;
Expand All @@ -22,11 +21,15 @@ struct Cli {
#[structopt(short = "t", long = "target")]
target_result: Option<f64>,

#[structopt(long = "show-regression-line")]
show_regression_line: Option<bool>,
#[structopt(
long = "show-regression-line",
parse(try_from_str),
default_value = "true"
)]
show_regression_line: bool,

#[structopt(long = "show-target-line")]
show_target_line: Option<bool>,
show_target_line: bool,

#[structopt(short = "l", long = "history-len", default_value = "100")]
history_len: usize,
Expand All @@ -42,20 +45,23 @@ fn main() {
&args.command,
args.target_result,
args.history_len,
args.show_regression_line.or(Some(true)).unwrap(),
args.show_target_line.or(Some(false)).unwrap()
args.show_regression_line,
args.show_target_line,
);
let mut keys = async_stdin().keys();

loop{
let current_time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs_f64();
loop {
let current_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs_f64();
if refresh_rate.as_secs_f64() < current_time - last_time {
ui.evaluate();
last_time = current_time;
}
if !ui.event_handler(keys.next()) {
ui.clean_up_terminal();
break
break;
}
}
}
}
}

0 comments on commit d3073e0

Please sign in to comment.