Skip to content

Commit 9fa22cd

Browse files
committed
refactor: 🪛 use function to exit
1 parent 754bb57 commit 9fa22cd

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

‎src/colors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ pub const YELLOW: &str = "\x1B[32m"; //( bright, medium yellow color)
99
pub const YELLOW_BRIGHT: &str = "\x1B[93m"; //( very bright, light yellow color)
1010
pub const RESET: &str = "\x1B[0m"; //( resets the text color to the default)
1111

12-
// unused colors rn :-
13-
//pub const MAGENTAA: &str = "\x1b[35m"; //( bright, medium pinkish-purple color)
14-
//pub const WHITE: &str = "\x1B[37m"; //( bright, pale gray color)
12+
// unused colors rn :-
13+
//pub const MAGENTAA: &str = "\x1b[35m"; //( bright, medium pinkish-purple color)
14+
//pub const WHITE: &str = "\x1B[37m"; //( bright, pale gray color)

‎src/main.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
7272

7373
Ok(())
7474
}
75+
76+
fn exit_on_error() {
77+
std::process::exit(0);
78+
}
79+
7580
async fn run(
7681
url: String,
7782
outdir: Option<String>,
@@ -81,12 +86,11 @@ async fn run(
8186
height: Option<u32>,
8287
silent: bool,
8388
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
84-
// Check if the browser binary path is valid
89+
// Check if the browser binary path is valid
8590
if !Path::new(&binary_path).exists() {
8691
println!("{RED}[  ]Browser binary not found at path {}, You should try manually pasing the binary path !!{RESET}", binary_path);
8792
println!("{BLUE}[ ﯦ ]{RESET}{CYAN} $ hxn -b $(which brave) <url> or use --help flag");
88-
std::process::exit(0);
89-
93+
exit_on_error();
9094
}
9195
let outdir = match outdir {
9296
Some(dir) => dir,
@@ -161,6 +165,7 @@ async fn run(
161165
handle
162166
.await?
163167
.expect("Something went wrong while waiting for taking screenshot and saving to file");
168+
exit_on_error();
164169
}
165170

166171
println!("{RED}♥ {GREEN} {YELLOW_BRIGHT}Yoo 1337!! Screenshots saved in dir {outdir}{RED} ♥ {GREEN}{RESET} ");
@@ -211,4 +216,3 @@ async fn take_screenshots(
211216

212217
Ok(())
213218
}
214-

0 commit comments

Comments
 (0)