generated from PlexSheep/rs-base
Apply some clippy suggestions
This commit is contained in:
parent
55346b5b79
commit
9126f0ae0b
5 changed files with 19 additions and 13 deletions
16
src/app.rs
16
src/app.rs
|
@ -77,13 +77,17 @@ impl App {
|
||||||
no_seconds: false,
|
no_seconds: false,
|
||||||
});
|
});
|
||||||
match mode {
|
match mode {
|
||||||
Mode::Clock { no_date, no_seconds, millis } => {
|
Mode::Clock {
|
||||||
|
no_date,
|
||||||
|
no_seconds,
|
||||||
|
millis,
|
||||||
|
} => {
|
||||||
self.clock = Some(Clock {
|
self.clock = Some(Clock {
|
||||||
size: self.size,
|
size: self.size,
|
||||||
style,
|
style,
|
||||||
show_date: !no_date.to_owned(),
|
show_date: !no_date,
|
||||||
show_millis: millis.to_owned(),
|
show_millis: *millis,
|
||||||
show_secs: !*no_seconds,
|
show_secs: !no_seconds,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Mode::Timer {
|
Mode::Timer {
|
||||||
|
@ -97,7 +101,7 @@ impl App {
|
||||||
DurationFormat::HourMinSecDeci
|
DurationFormat::HourMinSecDeci
|
||||||
};
|
};
|
||||||
self.timer = Some(Timer::new(
|
self.timer = Some(Timer::new(
|
||||||
duration.to_owned(),
|
*duration,
|
||||||
self.size,
|
self.size,
|
||||||
style,
|
style,
|
||||||
format,
|
format,
|
||||||
|
@ -162,7 +166,7 @@ fn parse_duration(s: &str) -> Result<Duration, String> {
|
||||||
"m" => Ok(Duration::minutes(num)),
|
"m" => Ok(Duration::minutes(num)),
|
||||||
"h" => Ok(Duration::hours(num)),
|
"h" => Ok(Duration::hours(num)),
|
||||||
"d" => Ok(Duration::days(num)),
|
"d" => Ok(Duration::days(num)),
|
||||||
_ => Err(format!("Invalid duration: {}", s).into()),
|
_ => Err(format!("Invalid duration: {}", s)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ impl Timer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute(execute: &Vec<String>) -> String {
|
fn execute(execute: &[String]) -> String {
|
||||||
let mut cmd = Command::new("sh");
|
let mut cmd = Command::new("sh");
|
||||||
cmd.arg("-c");
|
cmd.arg("-c");
|
||||||
let cmd_str = execute.join(" ");
|
let cmd_str = execute.join(" ");
|
||||||
|
@ -90,7 +90,7 @@ impl Widget for &Timer {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
let remaining_time = self.remaining_time();
|
let remaining_time = self.remaining_time();
|
||||||
let time_str = if remaining_time < Duration::zero() {
|
let time_str = if remaining_time < Duration::zero() {
|
||||||
if self.execute.len() > 0 && self.execute_result.borrow().is_none() {
|
if !self.execute.is_empty() && self.execute_result.borrow().is_none() {
|
||||||
let result = execute(&self.execute);
|
let result = execute(&self.execute);
|
||||||
*self.execute_result.borrow_mut() = Some(result);
|
*self.execute_result.borrow_mut() = Some(result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ impl BricksText {
|
||||||
|
|
||||||
impl Widget for &BricksText {
|
impl Widget for &BricksText {
|
||||||
fn render(self, area: tui::layout::Rect, buf: &mut tui::buffer::Buffer) {
|
fn render(self, area: tui::layout::Rect, buf: &mut tui::buffer::Buffer) {
|
||||||
let mut area = area.clone();
|
let mut area = area;
|
||||||
for char in self.text.chars() {
|
for char in self.text.chars() {
|
||||||
let Point(w, _) = BrickChar::size(self.size);
|
let Point(w, _) = BrickChar::size(self.size);
|
||||||
let char = BrickChar::from(char);
|
let char = BrickChar::from(char);
|
||||||
|
|
|
@ -13,7 +13,7 @@ impl BrickChar {
|
||||||
const UNIT_SIZE: Point = Point(3 * Self::H_UNIT, 5 * Self::V_UNIT);
|
const UNIT_SIZE: Point = Point(3 * Self::H_UNIT, 5 * Self::V_UNIT);
|
||||||
|
|
||||||
pub(crate) fn size(size: u16) -> Point {
|
pub(crate) fn size(size: u16) -> Point {
|
||||||
Self::UNIT_SIZE.clone() * size
|
Self::UNIT_SIZE * size
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from(char: char) -> BrickChar {
|
pub(crate) fn from(char: char) -> BrickChar {
|
||||||
|
@ -219,7 +219,7 @@ impl BrickChar {
|
||||||
for _ in 0..size {
|
for _ in 0..size {
|
||||||
let mut p = from;
|
let mut p = from;
|
||||||
for _ in (0..len).step_by(max(step.0, step.1).into()) {
|
for _ in (0..len).step_by(max(step.0, step.1).into()) {
|
||||||
if !p.in_area(&area) {
|
if !p.in_area(area) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// println!("p = {:?} area = {:?}", p, area);
|
// println!("p = {:?} area = {:?}", p, area);
|
||||||
|
|
|
@ -30,7 +30,7 @@ fn run_app<B: Backend>(
|
||||||
|
|
||||||
let timeout = tick_rate
|
let timeout = tick_rate
|
||||||
.checked_sub(last_tick.elapsed())
|
.checked_sub(last_tick.elapsed())
|
||||||
.unwrap_or(Duration::from_secs(0));
|
.unwrap_or(Duration::ZERO);
|
||||||
if event::poll(timeout)? {
|
if event::poll(timeout)? {
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
match key.code {
|
||||||
|
@ -61,7 +61,9 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
// create app and run it
|
// create app and run it
|
||||||
let low_rate = match app.mode {
|
let low_rate = match app.mode {
|
||||||
Some(Mode::Clock { millis, no_seconds, .. }) => !millis || no_seconds,
|
Some(Mode::Clock {
|
||||||
|
millis, no_seconds, ..
|
||||||
|
}) => !millis || no_seconds,
|
||||||
Some(Mode::Timer { no_millis, .. }) => no_millis,
|
Some(Mode::Timer { no_millis, .. }) => no_millis,
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue