mirror of
https://github.com/emersion/kanshi
synced 2024-11-23 00:02:16 +01:00
Pretty-print connected outputs
This commit is contained in:
parent
3922251786
commit
d10ca2c66b
@ -1,6 +1,7 @@
|
||||
extern crate edid;
|
||||
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::fs::{File, read_dir};
|
||||
use std::io::prelude::*;
|
||||
|
||||
@ -10,6 +11,38 @@ pub struct ConnectedOutput {
|
||||
pub edid: edid::EDID,
|
||||
}
|
||||
|
||||
impl ConnectedOutput {
|
||||
pub fn vendor(&self) -> String {
|
||||
self.edid.header.vendor[..].iter().collect::<String>()
|
||||
}
|
||||
|
||||
pub fn product(&self) -> String {
|
||||
self.edid.descriptors.iter()
|
||||
.filter_map(|d| match d {
|
||||
&edid::Descriptor::ProductName(ref s) => Some(s.to_string()),
|
||||
_ => None,
|
||||
})
|
||||
.nth(0)
|
||||
.unwrap_or(format!("0x{:X}", self.edid.header.product))
|
||||
}
|
||||
|
||||
pub fn serial(&self) -> String {
|
||||
self.edid.descriptors.iter()
|
||||
.filter_map(|d| match d {
|
||||
&edid::Descriptor::SerialNumber(ref s) => Some(s.to_string()),
|
||||
_ => None,
|
||||
})
|
||||
.nth(0)
|
||||
.unwrap_or(format!("0x{:X}", self.edid.header.serial))
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ConnectedOutput {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "output {} vendor {} product {} serial {}", self.name, self.vendor(), self.product(), self.serial())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Backend {
|
||||
fn list_outputs(&self) -> Result<Vec<ConnectedOutput>, Box<Error>>;
|
||||
}
|
||||
|
30
src/main.rs
30
src/main.rs
@ -42,8 +42,7 @@ impl PartialEq<SavedOutput> for ConnectedOutput {
|
||||
}
|
||||
}
|
||||
if other.vendor != "" {
|
||||
let vendor = self.edid.header.vendor[..].iter().collect::<String>();
|
||||
if vendor != other.vendor {
|
||||
if self.vendor() != other.vendor {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -53,16 +52,7 @@ impl PartialEq<SavedOutput> for ConnectedOutput {
|
||||
return false;
|
||||
}
|
||||
} else if other.product != "" {
|
||||
let ok = self.edid.descriptors.iter()
|
||||
.filter_map(|d| match d {
|
||||
&edid::Descriptor::ProductName(ref s) => Some(s.as_ref()),
|
||||
_ => None,
|
||||
})
|
||||
.nth(0)
|
||||
.map(|product| product == other.product)
|
||||
.unwrap_or(false);
|
||||
|
||||
if !ok {
|
||||
if self.product() != other.product {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -72,16 +62,7 @@ impl PartialEq<SavedOutput> for ConnectedOutput {
|
||||
return false;
|
||||
}
|
||||
} else if other.serial != "" {
|
||||
let ok = self.edid.descriptors.iter()
|
||||
.filter_map(|d| match d {
|
||||
&edid::Descriptor::SerialNumber(ref s) => Some(s.as_ref()),
|
||||
_ => None,
|
||||
})
|
||||
.nth(0)
|
||||
.map(|serial| serial == other.serial)
|
||||
.unwrap_or(false);
|
||||
|
||||
if !ok {
|
||||
if self.serial() != other.serial {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -122,7 +103,10 @@ fn main() {
|
||||
},
|
||||
};
|
||||
|
||||
writeln!(&mut stderr, "Connected outputs: {:?}", connected_outputs).unwrap();
|
||||
writeln!(&mut stderr, "Connected outputs:").unwrap();
|
||||
for o in &connected_outputs {
|
||||
writeln!(&mut stderr, "{}", o).unwrap();
|
||||
}
|
||||
|
||||
//let store = GnomeStore{};
|
||||
let store = store::KanshiStore{};
|
||||
|
Loading…
Reference in New Issue
Block a user