From 41cb67b1f3f08eb114c5aa77853a9cdab2cb40a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=98=A4=EB=B3=91=EC=A4=80?= Date: Thu, 2 May 2024 03:24:26 +0900 Subject: [PATCH] add: save client config --- src/client.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index f57ecdb..f379983 100644 --- a/src/client.rs +++ b/src/client.rs @@ -262,5 +262,59 @@ fn prompt_display_position(displays: &mut Vec, server_conf: Vec ch, + Err(_) => { + continue; + } + }; + + match ch { + 'y' => { + let path = config_dir!("client").join("client_config.json"); + + let mut file = match fs::File::create(&path) { + Ok(file) => file, + Err(e) => { + eprintln!( + "[ERR] failed to create {:?}: {:?}", + path.as_os_str().to_str().unwrap(), + e + ); + break; + } + }; + + match serde_json::to_string_pretty(&displays) { + Ok(json) => { + if let Err(e) = file.write_all(json.as_bytes()) { + eprintln!( + "[ERR] failed to write to {:?}: {:?}", + path.as_os_str().to_str().unwrap(), + e + ); + } + + println!( + "[INF] config saved at {:?}", + path.as_os_str().to_str().unwrap() + ); + } + Err(e) => eprintln!("[ERR] failed to save config into file: {:?}", e), + } + + break; + } + 'n' => { + break; // current display again + } + _ => { + continue; + } + } + } }