named enum params

This commit is contained in:
2023-08-23 01:15:12 +00:00
parent 0745b69d81
commit b1f674e729

View File

@@ -4,8 +4,14 @@ use json;
use json::JsonValue; use json::JsonValue;
enum SwayOutput { enum SwayOutput {
Disabled(String), Disabled {
Enabled(String,i32,i32), name: String,
},
Enabled {
name: String,
width: i32,
height: i32,
}
} }
fn main() { fn main() {
let output = Command::new("swaymsg") let output = Command::new("swaymsg")
@@ -32,16 +38,20 @@ fn main() {
let mode = &json_output["modes"][0]; let mode = &json_output["modes"][0];
//println!("mode:{:#}",mode); //println!("mode:{:#}",mode);
println!("swaymsg output {} mode {}x{}", name, mode["width"], mode["height"]); println!("swaymsg output {} mode {}x{}", name, mode["width"], mode["height"]);
outputs.push(SwayOutput::Enabled(name.to_string(), 1, 1)); outputs.push(SwayOutput::Enabled {
name: name.to_string(),
width: 1,
height: 1
});
} }
for output in &outputs { for output in &outputs {
match output { match output {
SwayOutput::Disabled(name) => { SwayOutput::Disabled { name } => {
println!("swaymsg output {} disabled", name); println!("swaymsg output {} disabled", name);
}, },
SwayOutput::Enabled(name,w,h) => { SwayOutput::Enabled { name, width, height } => {
println!("swaymsg output {} mode {}x{}", name, w, h); println!("swaymsg output {} mode {}x{}", name, width, height);
} }
} }
} }