Skip to content

Commit 5b82b9f

Browse files
authored
Merge pull request #5 from VuiMuich/main
chore: update dependencies and fix clippy lints
2 parents a9f2f21 + ca36d88 commit 5b82b9f

File tree

12 files changed

+574
-327
lines changed

12 files changed

+574
-327
lines changed

Cargo.lock

Lines changed: 482 additions & 240 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ readme = "README.md"
99

1010
[dependencies]
1111
anyhow = {version="1.0.69", features=["backtrace"]}
12-
clap = "3.2.22"
13-
# clap = "4.1.0"
14-
xdg = "2.4.1"
12+
clap = "4.5.41"
13+
xdg = "3.0.0"
1514
serde = { version = "1.0.152", features = ["derive", "rc"] }
16-
ron = "0.8.0"
15+
ron = "0.10.1"
1716
serde_json = "1.0.94"
1817
log = "0.4.17"
1918
git-version = "0.3.5"
20-
thiserror = "1.0.39"
19+
thiserror = "2.0.12"
2120
tui = "0.19.0"
22-
crossterm = "0.26.1"
21+
crossterm = "0.29.0"
2322
glob = "0.3.1"
24-
toml = "0.7.2"
23+
toml = "0.8.2"

src/config/check.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ use crate::config;
22
use crate::config::Config;
33
use crate::config::{all_ids_some, all_ids_unique, get_workspace_ids};
44
use anyhow::bail;
5-
use anyhow::{Error, Result};
5+
use anyhow::Result;
66
use std::collections::HashSet;
7-
use std::process::{Command, Stdio};
87
use std::{env, fs};
98

109
pub fn check_config(path: Option<&str>, verbose: bool) -> Result<()> {
@@ -28,7 +27,7 @@ pub fn check_config(path: Option<&str>, verbose: bool) -> Result<()> {
2827
config.check_keybinds(verbose);
2928
}
3029
Err(e) => {
31-
println!("Configuration failed. Reason: {:?}", e);
30+
println!("Configuration failed. Reason: {e:?}");
3231
bail!("Configuration failed. Reason: {:?}", e);
3332
}
3433
}
@@ -106,7 +105,7 @@ impl Config {
106105
{
107106
returns.push((
108107
Some(keybind.clone()),
109-
format!("Modifier `{}` is not valid", m),
108+
format!("Modifier `{m}` is not valid"),
110109
));
111110
}
112111
}
@@ -154,7 +153,7 @@ fn check_elogind(verbose: bool) -> Result<()> {
154153
) {
155154
(Ok(val), true) => {
156155
if verbose {
157-
println!(":: XDG_RUNTIME_DIR: {}, LOGINCTL OKAY", val);
156+
println!(":: XDG_RUNTIME_DIR: {val}, LOGINCTL OKAY");
158157
}
159158

160159
println!("\x1b[0;92m -> Environment OK \x1b[0m");
@@ -163,7 +162,7 @@ fn check_elogind(verbose: bool) -> Result<()> {
163162
}
164163
(Ok(val), false) => {
165164
if verbose {
166-
println!(":: XDG_RUNTIME_DIR: {}, LOGINCTL not installed", val);
165+
println!(":: XDG_RUNTIME_DIR: {val}, LOGINCTL not installed");
167166
}
168167

169168
println!("\x1b[0;92m -> Environment OK (has XDG_RUNTIME_DIR) \x1b[0m");
@@ -172,7 +171,7 @@ fn check_elogind(verbose: bool) -> Result<()> {
172171
}
173172
(Err(e), false) => {
174173
if verbose {
175-
println!(":: XDG_RUNTIME_DIR_ERROR: {:?}, LOGINCTL BAD", e);
174+
println!(":: XDG_RUNTIME_DIR_ERROR: {e:?}, LOGINCTL BAD");
176175
}
177176

178177
bail!(
@@ -182,7 +181,7 @@ fn check_elogind(verbose: bool) -> Result<()> {
182181
}
183182
(Err(e), true) => {
184183
if verbose {
185-
println!(":: XDG_RUNTIME_DIR: {:?}, LOGINCTL OKAY", e);
184+
println!(":: XDG_RUNTIME_DIR: {e:?}, LOGINCTL OKAY");
186185
}
187186
println!(
188187
"\x1b[1;93mWARN: Elogind/systemd installed but XDG_RUNTIME_DIR not set.\nThis may be because elogind isn't started. \x1b[0m",
@@ -196,7 +195,7 @@ fn check_elogind(verbose: bool) -> Result<()> {
196195
fn is_program_in_path(program: &str) -> bool {
197196
if let Ok(path) = env::var("PATH") {
198197
for p in path.split(':') {
199-
let p_str = format!("{}/{}", p, program);
198+
let p_str = format!("{p}/{program}");
200199
if fs::metadata(p_str).is_ok() {
201200
return true;
202201
}

src/config/filehandler.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::config::Config;
1111
#[must_use]
1212
pub fn load() -> Config {
1313
load_from_file(None, false)
14-
.map_err(|err| eprintln!("ERROR LOADING CONFIG: {:?}", err))
14+
.map_err(|err| eprintln!("ERROR LOADING CONFIG: {err:?}"))
1515
.unwrap_or_default()
1616
}
1717

@@ -23,12 +23,12 @@ pub fn load() -> Config {
2323
/// If a path is specified and does not exist, returns `LeftError`.
2424
pub fn load_from_file(fspath: Option<&str>, verbose: bool) -> Result<Config> {
2525
let config_filename = if let Some(fspath) = fspath {
26-
println!("\x1b[1;35mNote: Using file {} \x1b[0m", fspath);
26+
println!("\x1b[1;35mNote: Using file {fspath} \x1b[0m");
2727
PathBuf::from(fspath)
2828
} else {
29-
let ron_file = BaseDirectories::with_prefix("leftwm")?
29+
let ron_file = BaseDirectories::with_prefix("leftwm")
3030
.place_config_file(crate::CONFIG_NAME.to_string() + ".ron")?;
31-
let toml_file = BaseDirectories::with_prefix("leftwm")?
31+
let toml_file = BaseDirectories::with_prefix("leftwm")
3232
.place_config_file(crate::CONFIG_NAME.to_string() + ".toml")?;
3333
if Path::new(&ron_file).exists() {
3434
ron_file
@@ -61,9 +61,9 @@ pub fn load_from_file(fspath: Option<&str>, verbose: bool) -> Result<Config> {
6161
}
6262

6363
pub fn get_config_file() -> Result<PathBuf> {
64-
let ron_file = BaseDirectories::with_prefix("leftwm")?
64+
let ron_file = BaseDirectories::with_prefix("leftwm")
6565
.place_config_file(crate::CONFIG_NAME.to_string() + ".ron")?;
66-
let toml_file = BaseDirectories::with_prefix("leftwm")?
66+
let toml_file = BaseDirectories::with_prefix("leftwm")
6767
.place_config_file(crate::CONFIG_NAME.to_string() + ".toml")?;
6868
if Path::new(&ron_file).exists() {
6969
Ok(ron_file)
@@ -82,7 +82,7 @@ pub fn get_config_file() -> Result<PathBuf> {
8282

8383
pub fn save_to_file(config: &Config) -> Result<()> {
8484
write_to_file(
85-
&BaseDirectories::with_prefix("leftwm")?
85+
&BaseDirectories::with_prefix("leftwm")
8686
.place_config_file(crate::CONFIG_NAME.to_string() + ".ron")?,
8787
config,
8888
)
@@ -94,15 +94,15 @@ pub fn write_to_file(ron_file: &PathBuf, config: &Config) -> Result<(), anyhow::
9494
.extensions(ron::extensions::Extensions::IMPLICIT_SOME);
9595
let ron = ron::ser::to_string_pretty(&config, ron_pretty_conf)?;
9696
let comment_header = String::from(
97-
r#"// _ ___ ___ _
97+
r"// _ ___ ___ _
9898
// | | / __)_ / __|_)
9999
// | | ____| |__| |_ _ _ _ ____ ____ ___ ____ | |__ _ ____ ____ ___ ____
100100
// | |/ _ ) __) _) | | | \ / ___) _ \| _ \| __) |/ _ | / ___) _ \| _ \
101101
// | ( (/ /| | | |_| | | | | | | ( (__| |_| | | | | | | ( ( | |_| | | |_| | | | |
102102
// |_|\____)_| \___)____|_|_|_| \____)___/|_| |_|_| |_|\_|| (_)_| \___/|_| |_|
103103
// A WindowManager for Adventurers (____/
104104
// For info about configuration please visit https://github.com/leftwm/leftwm/wiki
105-
"#,
105+
",
106106
);
107107
let ron_with_header = comment_header + &ron;
108108
let mut file = File::create(ron_file)?;
@@ -111,7 +111,7 @@ pub fn write_to_file(ron_file: &PathBuf, config: &Config) -> Result<(), anyhow::
111111
}
112112

113113
pub fn generate_new_config() -> Result<()> {
114-
let file = BaseDirectories::with_prefix("leftwm")?
114+
let file = BaseDirectories::with_prefix("leftwm")
115115
.place_config_file(crate::CONFIG_NAME.to_string() + ".ron")?;
116116

117117
if file.exists() {

src/config/keybind.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub struct Keybind {
1616
pub key: String,
1717
}
1818

19+
// TODO lift this allow by actually using those items
20+
#[allow(dead_code)]
1921
pub struct CoreKeybind {
2022
pub command: CoreCommand,
2123
pub modifier: Vec<String>,

src/config/layout.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub enum Layout {
2020
LeftWiderRightStack,
2121
}
2222

23+
// TODO fix this by matching the layout handling to leftwm
24+
#[allow(dead_code)]
2325
pub const LAYOUTS: &[Layout] = &[
2426
Layout::MainAndVertStack,
2527
Layout::MainAndHorizontalStack,

src/config/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn default_terminal<'s>() -> &'s str {
8181
pub fn is_program_in_path(program: &str) -> bool {
8282
if let Ok(path) = env::var("PATH") {
8383
for p in path.split(':') {
84-
let p_str = format!("{}/{}", p, program);
84+
let p_str = format!("{p}/{program}");
8585
if fs::metadata(p_str).is_ok() {
8686
return true;
8787
}
@@ -278,7 +278,7 @@ impl Default for Config {
278278
});
279279
}
280280

281-
let tags = vec!["1", "2", "3", "4", "5", "6", "7", "8", "9"]
281+
let tags = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
282282
.iter()
283283
.map(|s| (*s).to_string())
284284
.collect();
@@ -315,7 +315,7 @@ fn exit_strategy<'s>() -> &'s str {
315315
#[allow(dead_code)]
316316
#[must_use]
317317
pub fn check_workspace_ids(config: &Config) -> bool {
318-
config.workspaces.clone().map_or(true, |wss| {
318+
config.workspaces.clone().is_none_or(|wss| {
319319
let ids = get_workspace_ids(&wss);
320320
if ids.iter().any(Option::is_some) {
321321
all_ids_some(&ids) && all_ids_unique(&ids)

src/config/modifier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl std::convert::From<&str> for Modifier {
5353
impl std::fmt::Display for Modifier {
5454
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5555
match self {
56-
Self::Single(modifier) => write!(f, "{}", modifier),
56+
Self::Single(modifier) => write!(f, "{modifier}"),
5757
Self::List(modifiers) => write!(f, "{}", modifiers.join("+")),
5858
}
5959
}

src/main.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mod utils;
1414
use crate::config::check_config;
1515
use crate::config::filehandler::{load_from_file, write_to_file};
1616
use anyhow::Result;
17-
use clap::{App, Arg};
17+
use clap::{Arg, Command as ClapCmd};
1818
use std::path::Path;
1919
use std::process::Command;
2020
use std::{env, fs, io};
@@ -26,52 +26,52 @@ const CONFIG_NAME: &str = "test_config";
2626
const CONFIG_NAME: &str = "config";
2727

2828
fn main() -> Result<()> {
29-
let matches = App::new("LeftWM Command")
29+
let matches = ClapCmd::new("LeftWM Command")
3030
.author("BlackDragon2447 <[email protected]>")
3131
.version(env!("CARGO_PKG_VERSION"))
3232
.about("a tool for managing your LeftWM config")
3333
.arg(
34-
Arg::with_name("New")
34+
Arg::new("New")
3535
.short('n')
3636
.long("new")
3737
.help("Generate a new config file"),
3838
)
3939
.arg(
40-
Arg::with_name("Editor")
40+
Arg::new("Editor")
4141
.short('e')
4242
.long("editor")
4343
.help("Open the current config file in the default editor (default)"),
4444
)
4545
.arg(
46-
Arg::with_name("TUI")
46+
Arg::new("TUI")
4747
.short('t')
4848
.long("tui")
4949
.help("Open the current config file in the TUI"),
5050
)
5151
.arg(
52-
Arg::with_name("Check")
52+
Arg::new("Check")
5353
.short('c')
5454
.long("check")
5555
.help("Check if the current config is valid"),
5656
)
5757
.arg(
58-
Arg::with_name("Verbose")
58+
Arg::new("Verbose")
5959
.short('v')
6060
.long("verbose")
6161
.help("Outputs received configuration file."),
6262
)
6363
.arg(
64-
Arg::with_name("Migrate")
64+
Arg::new("Migrate")
6565
.long("migrate")
6666
.help("Migrate an old .toml config to the RON format."),
6767
)
6868
.get_matches();
6969

70-
let verbose = matches.occurrences_of("Verbose") >= 1;
70+
let verbose = matches.get_flag("Verbose");
7171

72-
if matches.is_present("Migrate") {
72+
if matches.get_flag("Migrate") {
7373
println!("\x1b[0;94m::\x1b[0m Migrating configuration . . .");
74-
let path = BaseDirectories::with_prefix("leftwm")?;
74+
let path = BaseDirectories::with_prefix("leftwm");
7575
let ron_file = path.place_config_file(crate::CONFIG_NAME.to_string() + ".ron")?;
7676
let toml_file = path.place_config_file(crate::CONFIG_NAME.to_string() + ".toml")?;
7777

@@ -80,13 +80,13 @@ fn main() -> Result<()> {
8080
write_to_file(&ron_file, &config)?;
8181

8282
return Ok(());
83-
} else if matches.is_present("Editor") {
83+
} else if matches.get_flag("Editor") {
8484
run_editor(config::filehandler::get_config_file()?.as_path())?;
85-
} else if matches.is_present("TUI") {
85+
} else if matches.get_flag("TUI") {
8686
crate::tui::run()?;
87-
} else if matches.is_present("New") {
87+
} else if matches.get_flag("New") {
8888
config::filehandler::generate_new_config()?;
89-
} else if matches.is_present("Check") {
89+
} else if matches.get_flag("Check") {
9090
check_config(None, verbose)?;
9191
} else {
9292
run_editor(config::filehandler::get_config_file()?.as_path())?;

0 commit comments

Comments
 (0)