mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 13:48:29 +00:00
Rewrite project from Python to Rust and add Windows/MacOS supports
This commit is contained in:
17
src/utils/fs.rs
Normal file
17
src/utils/fs.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn check_dir(dir: Option<&str>) -> io::Result<Vec<String>> {
|
||||
let path: PathBuf = match dir {
|
||||
None | Some(".") | Some("./") => std::env::current_dir()?,
|
||||
Some(value) => std::env::current_dir()?.join(value),
|
||||
};
|
||||
|
||||
let mut items = Vec::new();
|
||||
for entry in std::fs::read_dir(path)? {
|
||||
let entry = entry?;
|
||||
items.push(entry.file_name().to_string_lossy().to_string());
|
||||
}
|
||||
|
||||
Ok(items)
|
||||
}
|
||||
30
src/utils/log.rs
Normal file
30
src/utils/log.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use crate::utils::text::{BOLD, BRIGHT_GREEN, BRIGHT_RED, BRIGHT_YELLOW, colored};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn error(msg: &str) {
|
||||
println!(
|
||||
"{}: {msg}",
|
||||
colored("error", &(BRIGHT_RED.to_owned() + BOLD))
|
||||
);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn warn(msg: &str) {
|
||||
println!(
|
||||
"{}: {msg}",
|
||||
colored("warn", &(BRIGHT_YELLOW.to_owned() + BOLD))
|
||||
);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn info(msg: &str) {
|
||||
println!("{}: {msg}", colored("info", BOLD));
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn ok(msg: &str) {
|
||||
println!(
|
||||
"{}: {msg}",
|
||||
colored("ok", &(BRIGHT_GREEN.to_owned() + BOLD))
|
||||
);
|
||||
}
|
||||
3
src/utils/mod.rs
Normal file
3
src/utils/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod fs;
|
||||
pub mod log;
|
||||
pub mod text;
|
||||
16
src/utils/text.rs
Normal file
16
src/utils/text.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
pub const RESET: &str = "\x1b[0m";
|
||||
|
||||
pub const BOLD: &str = "\x1b[1m";
|
||||
|
||||
pub const BRIGHT_RED: &str = "\x1b[91m";
|
||||
pub const BRIGHT_GREEN: &str = "\x1b[92m";
|
||||
pub const BRIGHT_YELLOW: &str = "\x1b[93m";
|
||||
pub const BRIGHT_CYAN: &str = "\x1b[96m";
|
||||
|
||||
pub fn colored(msg: &str, style: &str) -> String {
|
||||
format!("{style}{msg}{RESET}")
|
||||
}
|
||||
|
||||
pub fn printc(msg: &str, style: &str) {
|
||||
println!("{style}{msg}{RESET}");
|
||||
}
|
||||
Reference in New Issue
Block a user