Skip to content

Commit 010993a

Browse files
committed
chore: codefix
codefix
1 parent 55c737e commit 010993a

5 files changed

Lines changed: 17 additions & 23 deletions

File tree

src/config.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,16 @@ pub(crate) fn get_config_file_path() -> Result<PathBuf, String> {
3434
if config_file.exists() {
3535
// Load the config for validation
3636
let config = crate::config::load_config(&config_file)
37-
.map_err(|e| format!("Failed to load config for validation: {}", e))?;
37+
.map_err(|e| format!("Failed to load config for validation: {e}"))?;
3838

3939
// Validate the JSON structure
4040
if validate_json(&config) {
41-
println!(
42-
"✅ Config file loaded successfully from path: {:?}",
43-
config_file
44-
);
41+
println!("✅ Config file loaded successfully from path: {config_file:?}");
4542
}
4643
} else {
47-
println!(
48-
"⚠️ Config file not found. Creating new default config at: {:?}",
49-
config_file
50-
);
44+
println!("⚠️ Config file not found. Creating new default config at: {config_file:?}");
5145
create_default_config(&config_file)
52-
.map_err(|e| format!("Failed to create default config file: {}", e))?;
46+
.map_err(|e| format!("Failed to create default config file: {e}"))?;
5347
}
5448

5549
Ok(config_file)
@@ -66,7 +60,7 @@ pub fn load_config(path: &PathBuf) -> anyhow::Result<Config> {
6660
// Save the entire configuration (including commands and other sections) to a file.
6761
pub fn save_config(path: &Path, config: &Config) {
6862
let config_data = serde_json::to_string_pretty(config).expect("❌ Failed to serialize config");
69-
let mut file = File::create(path).expect("❌ Unable to create config file");
63+
let mut file = File::create(path).expect("❌ Unable to create config file ");
7064
// Write the serialized config data to the file
7165
file.write_all(config_data.as_bytes())
7266
.expect("❌ Unable to write to config file");
@@ -92,7 +86,7 @@ pub fn edit_cmd_sound(config: &mut Config, changes_made: &mut bool) {
9286
.as_ref()
9387
.map_or(String::new(), |path| path.display().to_string());
9488

95-
println!("Current sound file: {}", current_sound);
89+
println!("Current sound file: {current_sound}");
9690

9791
let sound_path = Text::new("Enter the new path for cmd_sound (leave empty to clear):")
9892
.with_initial_value(&current_sound)
@@ -134,7 +128,7 @@ pub fn edit_window_title(config: &mut Config, changes_made: &mut bool) {
134128
.as_ref()
135129
.map_or(String::new(), |title| title.clone());
136130

137-
println!("Current window title: {}", current_title);
131+
println!("Current window title: {current_title}");
138132

139133
let new_title = Text::new("Enter the new window title (leave empty to clear):")
140134
.with_initial_value(&current_title)
@@ -147,7 +141,7 @@ pub fn edit_window_title(config: &mut Config, changes_made: &mut bool) {
147141
} else {
148142
let new_title = new_title.trim();
149143
config.window_title = Some(new_title.to_string());
150-
println!("✅ Window title updated to: {}", new_title);
144+
println!("✅ Window title updated to: {new_title}");
151145
}
152146

153147
*changes_made = true;

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ mod utils;
77
fn main() {
88
// Print the version
99
let version = crate::utils::get_version();
10-
println!("Welcome to CLI_Menu v{}!", version);
10+
println!("Welcome to CLI_Menu v{version}!");
1111
// Execute the config::get_config_file_path function to get the config file path and load it; else create it
1212
let config_path = match config::get_config_file_path() {
1313
Ok(path) => {
1414
path // Return the path
1515
}
1616
Err(e) => {
17-
let _ = &eprintln!("{}", e); // Print the error message
17+
let _ = &eprintln!("{e}"); // Print the error message
1818
std::process::exit(1); // Exit if unable to get the config path
1919
}
2020
};

src/menu_edit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use textwrap::fill;
1212

1313
pub fn edit_menu(config_path: &PathBuf) {
1414
let mut config = crate::config::load_config(config_path).unwrap_or_else(|e| {
15-
eprintln!("Error: {}", e);
15+
eprintln!("Error: {e}");
1616
process::exit(1);
1717
});
1818
let _original_config = config.clone();
@@ -206,7 +206,7 @@ pub fn reorder_command(config: &mut Config, changes_made: &mut bool) {
206206
if new_position > 0 && new_position <= config.commands.len() {
207207
let command_to_move = config.commands.remove(command_number);
208208
config.commands.insert(new_position - 1, command_to_move);
209-
println!("✅ Command moved to position {}.", new_position);
209+
println!("✅ Command moved to position {new_position}.");
210210
*changes_made = true;
211211
} else {
212212
println!(

src/menu_main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub fn generate_menu(commands: &[CommandOption], selected_commands: &[usize]) ->
120120
.enumerate()
121121
.map(|(index, cmd)| {
122122
let number = index + 1;
123-
let padded_number = format!("{: >width$}", number, width = max_number_width);
123+
let padded_number = format!("{number: >max_number_width$}");
124124
if selected_commands.contains(&number) {
125125
format!("{}. {}", padded_number, strike_through(&cmd.display_name))
126126
} else {
@@ -150,5 +150,5 @@ fn strike_through(text: &str) -> String {
150150
}
151151

152152
pub fn set_window_title(title: &str) {
153-
print!("\x1b]0;{}\x07", title);
153+
print!("\x1b]0;{title}\x07");
154154
}

src/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use tokio::task; // Importing task module from Tokio for asynchronous task handl
1010
// Function to run a shell command
1111
/// Runs a shell command and prints the result, capturing stdout/stderr for cleaner output.
1212
pub fn run_command(command: &str) {
13-
println!("Running command: {}", command); // Printing the command being executed
13+
println!("Running command: {command}"); // Printing the command being executed
1414
let mut child = Command::new("sh") // Starting a new shell command
1515
.arg("-c") // Passing a command to the shell
1616
.arg(command) // The command to execute
@@ -54,13 +54,13 @@ pub async fn play_sound(file_path: PathBuf) {
5454
sink.sleep_until_end(); // Sleeping until the audio playback ends
5555
}
5656
_ => {
57-
println!("❌ Failed to decode audio file: {:?}", file_path);
57+
println!("❌ Failed to decode audio file: {file_path:?}");
5858
// Printing error message if decoding fails
5959
}
6060
}
6161
}
6262
_ => {
63-
println!("❌ Failed to open audio file: {:?}", file_path);
63+
println!("❌ Failed to open audio file: {file_path:?}");
6464
// Printing error message if file opening fails
6565
}
6666
}

0 commit comments

Comments
 (0)