From f479143ebae64cf27c5498a12c470c7a5a4bc297 Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Thu, 3 Oct 2024 23:22:40 +0200 Subject: [PATCH] Refactor format crtc --- src/card.rs | 2 +- src/main.rs | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/card.rs b/src/card.rs index 6383d27..8fdb31f 100644 --- a/src/card.rs +++ b/src/card.rs @@ -56,4 +56,4 @@ impl Debug for Card { } } -impl ControlDevice for Card {} \ No newline at end of file +impl ControlDevice for Card {} diff --git a/src/main.rs b/src/main.rs index b2a5105..5d6aa56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,10 +27,7 @@ fn main() { let encoder_info = match current_encoder { Some(encoder) => { - let crtc_info = encoder.crtc() - .and_then(|crtc_handle| gpu.get_crtc(crtc_handle).ok()) - .and_then(|crtc| Some(format!("{:?}", crtc))) - .unwrap_or_else(|| format!("No CRTC data")); + let crtc_info = format_crtc(&gpu, encoder.crtc()); format!("{:?}, {}", encoder.kind(), crtc_info) } @@ -38,10 +35,17 @@ fn main() { }; println!("\t\tEncoder: {}", encoder_info); - + println!(""); // Add blank line }, Err(_) => {} } } -} \ No newline at end of file +} + +fn format_crtc(gpu: &card::Card, crtc_handle: Option) -> String { + match crtc_handle.and_then(|handle| Some(gpu.get_crtc(handle))) { + Some(crtc) => format!("{:?}", crtc), + None => format!("No CRTC data") + } +}