From f62fea3d2b098fab898fe6bfce9aeef49233c678 Mon Sep 17 00:00:00 2001 From: rain-bus Date: Sun, 5 Jan 2025 16:18:37 +0800 Subject: [PATCH] temp --- Cargo.lock | 259 +++++++++++++++++++++++++++++++++++--- Cargo.toml | 4 + src/app.rs | 9 +- src/global.rs | 9 ++ src/main.rs | 75 ++++++++--- src/session.rs | 21 +++- src/session/connection.rs | 23 +++- src/session/credential.rs | 20 ++- src/util.rs | 2 +- src/util/file.rs | 16 +++ src/view/home.rs | 4 +- 11 files changed, 400 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c5e57cd..25bc5b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,6 +14,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "2.6.0" @@ -90,6 +96,27 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + [[package]] name = "either" version = "1.13.0" @@ -109,7 +136,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -124,6 +151,17 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "hashbrown" version = "0.15.0" @@ -147,6 +185,16 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "instability" version = "0.3.2" @@ -184,6 +232,16 @@ version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags", + "libc", +] + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -215,6 +273,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + [[package]] name = "mio" version = "1.0.2" @@ -225,7 +289,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -243,6 +307,12 @@ dependencies = [ "libc", ] +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "parking_lot" version = "0.12.3" @@ -263,7 +333,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -327,13 +397,28 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + [[package]] name = "rstemp" version = "0.1.0" dependencies = [ + "base64", "crossterm", + "dirs", "lazy_static", "ratatui", + "serde", + "toml", "unicode-width 0.2.0", ] @@ -347,7 +432,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -370,24 +455,33 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.210" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + [[package]] name = "signal-hook" version = "0.3.17" @@ -454,15 +548,35 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.79" +version = "2.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "thiserror" +version = "1.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "time" version = "0.3.36" @@ -484,6 +598,40 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "unicode-ident" version = "1.0.13" @@ -547,13 +695,37 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -562,28 +734,46 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -596,26 +786,59 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml index 975defc..eb5837b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,11 @@ version = "0.1.0" edition = "2021" [dependencies] +base64 = "0.22.1" crossterm = { version = "0.28.1", features = ["event-stream"] } +dirs = "5.0.1" lazy_static = "1.5.0" ratatui = { version = "0.28.1", features = ["all-widgets"] } +serde = { version = "1.0.214", features = ["derive"] } +toml = "0.8.19" unicode-width = "0.2.0" diff --git a/src/app.rs b/src/app.rs index 9b7737f..843ba9e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -3,11 +3,16 @@ use std::io; use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind}; use ratatui::{DefaultTerminal, Frame}; -use crate::view::{home::Home, View}; +use crate::{ + session::{connection::ConnectionManager, credential::CredentialManager}, + view::{home::Home, View}, +}; pub struct App { running: bool, view: Home, + connection_manager: ConnectionManager, + credential_manager: CredentialManager, } impl Default for App { @@ -15,6 +20,8 @@ impl Default for App { App { running: true, view: Home::default(), + connection_manager: ConnectionManager::default(), + credential_manager: CredentialManager::default(), } } } diff --git a/src/global.rs b/src/global.rs index 8b13789..a012198 100644 --- a/src/global.rs +++ b/src/global.rs @@ -1 +1,10 @@ +use std::path::PathBuf; +use lazy_static::lazy_static; + +lazy_static! { + pub static ref CONFIG_DIR: PathBuf = dirs::config_local_dir().unwrap().join("tethers"); + pub static ref CACHE_DIR: PathBuf = dirs::cache_dir().unwrap().join("tethers"); + pub static ref SSH_CONFIG_DIR: PathBuf = dirs::home_dir().unwrap().join(".ssh"); + pub static ref SSH_CONFIG_PATH: PathBuf = dirs::home_dir().unwrap().join(".ssh").join("config"); +} diff --git a/src/main.rs b/src/main.rs index 4e3a017..ba97086 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,24 +1,69 @@ -use std::io; +use std::{io, path::Path}; use app::App; -use session::connection::{Connection, ShConnection}; +use base64::{engine::general_purpose::STANDARD, Engine as _}; +use session::{ + connection::{Connection, ConnectionManager, Connections, ShConnection, SshConnection}, + credential::{Credential, CredentialManager, CredentialType}, + SessionManager, +}; +use util::file; mod app; -mod session; -mod view; mod global; +mod session; mod util; - -// fn main() -> io::Result<()> { -// let mut terminal = ratatui::init(); -// let app_result = App::default().run(&mut terminal); -// ratatui::restore(); -// app_result -// } -// +mod view; fn main() -> io::Result<()> { - let sh = ShConnection::new("zsh".to_string(), "/usr/bin/nu".to_string(), None); - let _ = sh.exec_cmd(); - Ok(()) + let mut terminal = ratatui::init(); + let app_result = App::default().run(&mut terminal); + ratatui::restore(); + app_result } + +// fn main() -> io::Result<()> { +// // let sh = ShConnection::new("zsh".to_string(), "/usr/bin/nu".to_string(), None); +// // let _ = sh.exec_cmd(); +// let ssh = SshConnection::new("".to_string(), "myhost.fallen-angle.com".to_string(), 7044, "rainbus".to_string(), "".to_string()); +// ssh.exec_cmd(); +// Ok(()) +// } + +/* fn main() -> io::Result<()> { + let mut cnm = ConnectionManager::default(); + let sh = Connections::Sh(ShConnection::new( + "zsh".to_string(), + "/usr/bin/zsh".to_string(), + None, + )); + let ssh_sec = Connections::Ssh(SshConnection::new( + "Tencent".to_string(), + "myhost.fallen-angle.com".to_string(), + 22, + "rainbus".to_string(), + "Server".to_string(), + )); + let ssh_pwd = Connections::Ssh(SshConnection::new( + "Aliyun".to_string(), + "myweb.fallen-angle.com".to_string(), + 22, + "rainbus".to_string(), + "AliPwd".to_string(), + )); + cnm.connections().extend([sh, ssh_sec, ssh_pwd]); + let mut crm = CredentialManager::default(); + let ser_crd = Credential::new( + "Server".to_string(), + CredentialType::Secret(STANDARD.encode(file::read_file(Path::new("")))), + ); + let pwd_crd = Credential::new( + "Alipwd".to_string(), + CredentialType::Password("20001001".to_string()), + ); + crm.credentials().extend([ser_crd, pwd_crd]); + let sem = SessionManager::new(cnm, crm); + // println!("{}", toml::to_string_pretty(&sem).unwrap()); + file::write_file(&global::CONFIG_DIR.join("tethers.toml"), toml::to_string_pretty(&sem).unwrap().as_str()); + Ok(()) +} */ diff --git a/src/session.rs b/src/session.rs index 5548632..b8e6711 100644 --- a/src/session.rs +++ b/src/session.rs @@ -1,2 +1,21 @@ +use connection::ConnectionManager; +use credential::CredentialManager; +use serde::{Deserialize, Serialize}; + pub mod connection; -mod credential; +pub mod credential; + +#[derive(Serialize, Deserialize)] +pub struct SessionManager { + connection_manager: ConnectionManager, + credential_manager: CredentialManager, +} + +impl SessionManager { + pub fn new(cnm: ConnectionManager, crm: CredentialManager) -> Self { + Self { + connection_manager: cnm, + credential_manager: crm, + } + } +} diff --git a/src/session/connection.rs b/src/session/connection.rs index c90d3ee..c8693ea 100644 --- a/src/session/connection.rs +++ b/src/session/connection.rs @@ -1,4 +1,8 @@ -use std::{env, io, path::Path, process::Command}; +use std::{env, fs, io, path::Path, process::Command}; + +use serde::{Deserialize, Serialize}; + +use crate::util::file; use super::credential::{Credential, CredentialType}; @@ -6,6 +10,7 @@ pub trait Connection { fn exec_cmd(&self) -> io::Result<()>; } +#[derive(Serialize, Deserialize)] pub struct ShConnection { name: String, path: String, @@ -38,6 +43,7 @@ impl ShConnection { } } +#[derive(Serialize, Deserialize)] pub struct SshConnection { name: String, host: String, @@ -66,10 +72,13 @@ impl SshConnection { impl Connection for SshConnection { fn exec_cmd(&self) -> io::Result<()> { - let credential = - Credential::new("zsh".to_string(), CredentialType::Password("".to_string())); + let credential = Credential::new( + "zsh".to_string(), + CredentialType::Secret(file::read_file(Path::new(""))), + ); let mut ssh_command = Command::new("ssh"); let secret_path = env::temp_dir().join("tethers").join("secret.tmp"); + let _ = fs::create_dir_all(secret_path.parent().unwrap()); ssh_command .args(["-p", &self.port.to_string()]) .args(["-l", &self.user]); @@ -89,11 +98,19 @@ impl Connection for SshConnection { } } +#[derive(Serialize, Deserialize)] pub enum Connections { Sh(ShConnection), Ssh(SshConnection), } +#[derive(Default, Serialize, Deserialize)] pub struct ConnectionManager { connections: Vec, } + +impl ConnectionManager { + pub fn connections(&mut self) -> &mut Vec { + &mut self.connections + } +} diff --git a/src/session/credential.rs b/src/session/credential.rs index 73d0bf0..6434a9f 100644 --- a/src/session/credential.rs +++ b/src/session/credential.rs @@ -5,11 +5,18 @@ use std::{ path::Path, }; +use base64::{engine::general_purpose::STANDARD, Engine}; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize)] pub enum CredentialType { Password(String), Secret(String), } +impl CredentialType {} + +#[derive(Serialize, Deserialize)] pub struct Credential { credential: CredentialType, name: String, @@ -35,6 +42,13 @@ impl Credential { impl Credential { pub fn new(name: String, credential: CredentialType) -> Self { + // TODO: modify this to Type + let credential = match credential { + CredentialType::Password(password) => { + CredentialType::Password(STANDARD.encode(password)) + } + CredentialType::Secret(secret) => CredentialType::Secret(STANDARD.encode(secret)), + }; Self { name, credential } } @@ -43,12 +57,16 @@ impl Credential { } } -#[derive(Default)] +#[derive(Default, Serialize, Deserialize)] pub struct CredentialManager { credentials: Vec, } impl CredentialManager { + pub fn credentials(&mut self) -> &mut Vec { + &mut self.credentials + } + pub fn find_by_name(&self, name: &str) -> io::Result<&Credential> { self.credentials .iter() diff --git a/src/util.rs b/src/util.rs index 8b13789..2e172cd 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1 +1 @@ - +pub mod file; diff --git a/src/util/file.rs b/src/util/file.rs index 139597f..6dee3b9 100644 --- a/src/util/file.rs +++ b/src/util/file.rs @@ -1,2 +1,18 @@ +use std::{ + fs::File, + io::{Read, Write}, + path::{self, Path}, +}; +pub fn read_file(path: &Path) -> String { + let path = dirs::home_dir().unwrap().join(".ssh/Server"); + let mut file = File::open(path).unwrap(); + let mut content = String::new(); + file.read_to_string(&mut content).unwrap(); + content +} +pub fn write_file(path: &Path, content: &str) { + let mut file = File::create(path).unwrap(); + let res = file.write_all(content.as_bytes()); +} diff --git a/src/view/home.rs b/src/view/home.rs index 224219d..b28b851 100644 --- a/src/view/home.rs +++ b/src/view/home.rs @@ -37,8 +37,8 @@ impl Default for Home { help: HelpComponent::default(), setting: SettingView::default(), }; - // home.table.active_state().set_active(true); - home.setting.active_state().set_active(true); + home.table.active_state().set_active(true); + // home.setting.active_state().set_active(true); home } }