Skip to content

Commit

Permalink
chore: format let else
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Aug 25, 2023
1 parent f3c8b48 commit f7ce956
Showing 1 changed file with 48 additions and 44 deletions.
92 changes: 48 additions & 44 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,35 @@ fn parseslurp(posmessage: String) -> SlurpParseResult {
}
let position: Vec<&str> = posmessage[0].split(',').collect();

let Ok(pos_x) = position[0]
.parse::<i32>() else {
tracing::error!("Error parse, Cannot get pos_x");
#[cfg(feature = "notify")]
notify_error("Error parse, Cannot get pos_x");
return SlurpParseResult::MeetError;
let Ok(pos_x) = position[0].parse::<i32>() else {
tracing::error!("Error parse, Cannot get pos_x");
#[cfg(feature = "notify")]
notify_error("Error parse, Cannot get pos_x");
return SlurpParseResult::MeetError;
};
let Ok(pos_y) = position[1]
.parse::<i32>() else {
tracing::error!("Error parse, Cannot get pos_y");
#[cfg(feature = "notify")]
notify_error("Error parse, Cannot get pos_y");
return SlurpParseResult::MeetError;
let Ok(pos_y) = position[1].parse::<i32>() else {
tracing::error!("Error parse, Cannot get pos_y");
#[cfg(feature = "notify")]
notify_error("Error parse, Cannot get pos_y");
return SlurpParseResult::MeetError;
};

let map: Vec<&str> = posmessage[1].split('x').collect();
if map.len() != 2 {
eprintln!("Error input");
return SlurpParseResult::MeetError;
}
let Ok(width) = map[0]
.parse::<i32>() else {
tracing::error!("Error parse, cannot get width");
#[cfg(feature = "notify")]
notify_error("Error parse, Cannot get width");
return SlurpParseResult::MeetError;
let Ok(width) = map[0].parse::<i32>() else {
tracing::error!("Error parse, cannot get width");
#[cfg(feature = "notify")]
notify_error("Error parse, Cannot get width");
return SlurpParseResult::MeetError;
};
let Ok(height) = map[1]
.parse::<i32>() else {
tracing::error!("Error parse, cannot get height");
#[cfg(feature = "notify")]
notify_error("Error parse, Cannot get height");
return SlurpParseResult::MeetError;
let Ok(height) = map[1].parse::<i32>() else {
tracing::error!("Error parse, cannot get height");
#[cfg(feature = "notify")]
notify_error("Error parse, Cannot get height");
return SlurpParseResult::MeetError;
};
SlurpParseResult::Finished(pos_x, pos_y, width, height)
}
Expand Down Expand Up @@ -200,7 +196,8 @@ fn main() {
if !usestdout {
tracing_subscriber::fmt::init();
}
let SlurpParseResult::Finished(pos_x, pos_y, width, height) = parseslurp(posmessage) else {
let SlurpParseResult::Finished(pos_x, pos_y, width, height) = parseslurp(posmessage)
else {
return;
};
take_screenshot(ClapOption::ShotWithSlurp {
Expand Down Expand Up @@ -288,14 +285,20 @@ fn take_screenshot(option: ClapOption) {
if usestdout {
tracing_subscriber::fmt().init();
}
tracing::error!("Cannot get frame from screen: {} ", state.display_names[id]);
tracing::error!(
"Cannot get frame from screen: {} ",
state.display_names[id]
);
#[cfg(feature = "notify")]
{
use crate::constenv::{FAILED_IMAGE, TIMEOUT};
use notify_rust::Notification;
let _ = Notification::new()
.summary("FileSavedFailed")
.body(&format!("Cannot get frame from screen: {}", state.display_names[id]))
.body(&format!(
"Cannot get frame from screen: {}",
state.display_names[id]
))
.icon(FAILED_IMAGE)
.timeout(TIMEOUT)
.show();
Expand Down Expand Up @@ -398,26 +401,27 @@ fn take_screenshot(option: ClapOption) {
shoot_choosed_screen(false, index as usize, &mut state);
}
slintbackend::SlintSelection::Slurp => {
let Ok(output) = std::process::Command::new("slurp")
.arg("-d")
.output() else {
tracing::error!("Maybe Slurp Missing?");
#[cfg(feature = "notify")]
{
use crate::constenv::{FAILED_IMAGE, TIMEOUT};
use notify_rust::Notification;
let _ = Notification::new()
.summary("FileSavedFailed")
.body("Maybe Slurp Missing?")
.icon(FAILED_IMAGE)
.timeout(TIMEOUT)
.show();
}
return;
let Ok(output) = std::process::Command::new("slurp").arg("-d").output()
else {
tracing::error!("Maybe Slurp Missing?");
#[cfg(feature = "notify")]
{
use crate::constenv::{FAILED_IMAGE, TIMEOUT};
use notify_rust::Notification;
let _ = Notification::new()
.summary("FileSavedFailed")
.body("Maybe Slurp Missing?")
.icon(FAILED_IMAGE)
.timeout(TIMEOUT)
.show();
}
return;
};
let message = output.stdout;
let posmessage = String::from_utf8_lossy(&message).to_string();
let SlurpParseResult::Finished(pos_x, pos_y , width , height ) = parseslurp(posmessage) else {
let SlurpParseResult::Finished(pos_x, pos_y, width, height) =
parseslurp(posmessage)
else {
return;
};
match state.get_pos_display_ids((pos_x, pos_y), (width, height)) {
Expand Down

0 comments on commit f7ce956

Please sign in to comment.