Don't panic on a missing 3rd argument, use the default
This commit is contained in:
parent
fa22a5e838
commit
e51336b3f2
@ -18,7 +18,7 @@ fn send<T: Write>(w: &mut T, f: &Frame) -> std::io::Result<()> {
|
|||||||
w.flush()
|
w.flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_LOOP_TIME: usize = 120;
|
const DEFAULT_ARG: usize = 120;
|
||||||
const MIN_LOOP_TIME: usize = 20;
|
const MIN_LOOP_TIME: usize = 20;
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
@ -27,10 +27,12 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
let x_size = args[1].parse::<usize>().unwrap();
|
let x_size = args[1].parse::<usize>().unwrap();
|
||||||
let y_size = args[2].parse::<usize>().unwrap();
|
let y_size = args[2].parse::<usize>().unwrap();
|
||||||
let loop_time = args[3]
|
let arg = if let Some(s) = args.get(3) {
|
||||||
.parse::<usize>()
|
s.parse::<usize>().unwrap_or(DEFAULT_ARG)
|
||||||
.unwrap_or(DEFAULT_LOOP_TIME)
|
} else {
|
||||||
.max(MIN_LOOP_TIME);
|
DEFAULT_ARG
|
||||||
|
};
|
||||||
|
let loop_time = arg.max(MIN_LOOP_TIME);
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"screen size {}x{}, loop time {:?}s",
|
"screen size {}x{}, loop time {:?}s",
|
||||||
x_size, y_size, loop_time
|
x_size, y_size, loop_time
|
||||||
|
@ -48,7 +48,11 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
let x_size = args[1].parse::<usize>().unwrap();
|
let x_size = args[1].parse::<usize>().unwrap();
|
||||||
let y_size = args[2].parse::<usize>().unwrap();
|
let y_size = args[2].parse::<usize>().unwrap();
|
||||||
let arg = args[3].parse::<usize>().unwrap_or(DEFAULT_ARG);
|
let arg = if let Some(s) = args.get(3) {
|
||||||
|
s.parse::<usize>().unwrap_or(DEFAULT_ARG)
|
||||||
|
} else {
|
||||||
|
DEFAULT_ARG
|
||||||
|
};
|
||||||
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
||||||
|
|
||||||
let t_frame = 0.040; // s
|
let t_frame = 0.040; // s
|
||||||
|
@ -240,7 +240,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_ARG: isize = 16;
|
const DEFAULT_ARG: usize = 10;
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
let args = args().collect::<Vec<_>>();
|
let args = args().collect::<Vec<_>>();
|
||||||
@ -248,7 +248,11 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
let x_size = args[1].parse::<i64>().unwrap();
|
let x_size = args[1].parse::<i64>().unwrap();
|
||||||
let y_size = args[2].parse::<i64>().unwrap();
|
let y_size = args[2].parse::<i64>().unwrap();
|
||||||
let arg = args[3].parse::<isize>().unwrap_or(DEFAULT_ARG);
|
let arg = if let Some(s) = args.get(3) {
|
||||||
|
s.parse::<usize>().unwrap_or(DEFAULT_ARG)
|
||||||
|
} else {
|
||||||
|
DEFAULT_ARG
|
||||||
|
};
|
||||||
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
||||||
|
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
|
@ -68,7 +68,11 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
let x_size = args[1].parse::<usize>().unwrap();
|
let x_size = args[1].parse::<usize>().unwrap();
|
||||||
let y_size = args[2].parse::<usize>().unwrap();
|
let y_size = args[2].parse::<usize>().unwrap();
|
||||||
let arg = args[3].parse::<u64>().unwrap_or(DEFAULT_ARG);
|
let arg = if let Some(s) = args.get(3) {
|
||||||
|
s.parse::<u64>().unwrap_or(DEFAULT_ARG)
|
||||||
|
} else {
|
||||||
|
DEFAULT_ARG
|
||||||
|
};
|
||||||
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
||||||
|
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
|
@ -28,7 +28,11 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
let x_size = args[1].parse::<usize>().unwrap();
|
let x_size = args[1].parse::<usize>().unwrap();
|
||||||
let y_size = args[2].parse::<usize>().unwrap();
|
let y_size = args[2].parse::<usize>().unwrap();
|
||||||
let arg = args[3].parse::<usize>().unwrap_or(DEFAULT_ARG);
|
let arg = if let Some(s) = args.get(3) {
|
||||||
|
s.parse::<usize>().unwrap_or(DEFAULT_ARG)
|
||||||
|
} else {
|
||||||
|
DEFAULT_ARG
|
||||||
|
};
|
||||||
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
||||||
|
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
|
@ -191,7 +191,11 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
|
|
||||||
let x_size = args[1].parse::<usize>().unwrap();
|
let x_size = args[1].parse::<usize>().unwrap();
|
||||||
let y_size = args[2].parse::<usize>().unwrap();
|
let y_size = args[2].parse::<usize>().unwrap();
|
||||||
let arg = args[3].parse::<u64>().unwrap_or(DEFAULT_ARG);
|
let arg = if let Some(s) = args.get(3) {
|
||||||
|
s.parse::<u64>().unwrap_or(DEFAULT_ARG)
|
||||||
|
} else {
|
||||||
|
DEFAULT_ARG
|
||||||
|
};
|
||||||
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
||||||
|
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
|
@ -239,7 +239,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_ARG: isize = 16;
|
const DEFAULT_ARG: usize = 10;
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
let args = args().collect::<Vec<_>>();
|
let args = args().collect::<Vec<_>>();
|
||||||
@ -247,7 +247,11 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
let x_size = args[1].parse::<i64>().unwrap();
|
let x_size = args[1].parse::<i64>().unwrap();
|
||||||
let y_size = args[2].parse::<i64>().unwrap();
|
let y_size = args[2].parse::<i64>().unwrap();
|
||||||
let arg = args[3].parse::<isize>().unwrap_or(DEFAULT_ARG);
|
let arg = if let Some(s) = args.get(3) {
|
||||||
|
s.parse::<usize>().unwrap_or(DEFAULT_ARG)
|
||||||
|
} else {
|
||||||
|
DEFAULT_ARG
|
||||||
|
};
|
||||||
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
||||||
|
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
|
@ -76,7 +76,11 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
let x_size = args[1].parse::<i64>().unwrap();
|
let x_size = args[1].parse::<i64>().unwrap();
|
||||||
let y_size = args[2].parse::<i64>().unwrap();
|
let y_size = args[2].parse::<i64>().unwrap();
|
||||||
let arg = args[3].parse::<usize>().unwrap_or(DEFAULT_ARG);
|
let arg = if let Some(s) = args.get(3) {
|
||||||
|
s.parse::<usize>().unwrap_or(DEFAULT_ARG)
|
||||||
|
} else {
|
||||||
|
DEFAULT_ARG
|
||||||
|
};
|
||||||
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
eprintln!("screen size {}x{}, arg {}", x_size, y_size, arg);
|
||||||
|
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
|
Loading…
Reference in New Issue
Block a user