From 2135d667671787ad522d6ff8ed462606c098165b Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sun, 21 Jan 2024 17:37:29 +0800 Subject: [PATCH] Add Display trait implementation for Config struct --- src/config.rs | 18 ++++++++++++++++++ src/main.rs | 3 +++ src/win.rs | 11 ++--------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/config.rs b/src/config.rs index ef89770..148324d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + pub const HELP_MESSAGE: &str = r#"call [options] [--] [arguments] Options: --hide Hide console window (default) @@ -10,6 +12,7 @@ Options: --help Print this help message "#; +#[derive(Clone)] pub struct Config { pub show_console: bool, pub chdir: Option, @@ -19,6 +22,21 @@ pub struct Config { pub bin_arg: String, } +impl Display for Config { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut s = String::new(); + s.push_str("Config {\n"); + s.push_str(&format!(" show_console: {}\n", self.show_console)); + s.push_str(&format!(" chdir: {:?}\n", self.chdir)); + s.push_str(&format!(" bin: {:?}\n", self.bin)); + s.push_str(&format!(" dir: {:?}\n", self.dir)); + s.push_str(&format!(" config: {:?}\n", self.config)); + s.push_str(&format!(" bin_arg: {:?}\n", self.bin_arg)); + s.push_str("}"); + write!(f, "{}", s) + } +} + impl Config { pub fn from_cli() -> Option { let mut show_console = false; diff --git a/src/main.rs b/src/main.rs index ac271e6..223460c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,9 @@ fn main() { return; } let config = config.unwrap(); + // 输出相关信息 + println!("call {}", VERSION); + println!("config: {}", config); if config.show_console { win::show_window(); } else { diff --git a/src/win.rs b/src/win.rs index 07c223c..8cc1cdf 100644 --- a/src/win.rs +++ b/src/win.rs @@ -1,10 +1,3 @@ +pub fn hide_window() {} - -pub fn hide_window () { - -} - -pub fn show_window () { - -} - +pub fn show_window() {}