diff --git a/Cargo.lock b/Cargo.lock index d4da309..240c632 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,6 +183,25 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "is-docker" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3" +dependencies = [ + "once_cell", +] + +[[package]] +name = "is-wsl" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5" +dependencies = [ + "is-docker", + "once_cell", +] + [[package]] name = "js-sys" version = "0.3.64" @@ -259,6 +278,17 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "open" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfabf1927dce4d6fdf563d63328a0a506101ced3ec780ca2135747336c98cef8" +dependencies = [ + "is-wsl", + "libc", + "pathdiff", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -282,6 +312,12 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -347,7 +383,7 @@ dependencies = [ [[package]] name = "rtkill" -version = "1.0.0" +version = "1.1.0" dependencies = [ "anyhow", "chrono", @@ -355,6 +391,7 @@ dependencies = [ "fs_extra", "lazy_static", "number_prefix", + "open", "rand", "toml", "tui", diff --git a/Cargo.toml b/Cargo.toml index 722372d..7bb7471 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rtkill" -version = "1.0.0" +version = "1.1.0" edition = "2021" authors = ["Ilingu"] rust-version = "1.56.1" @@ -22,6 +22,7 @@ crossterm = "0.26.1" fs_extra = "1.3.0" lazy_static = "1.4.0" number_prefix = "0.4.0" +open = "5.0.0" rand = "0.8.5" toml = "0.7.5" tui = "0.19.0" diff --git a/src/app/mod.rs b/src/app/mod.rs index 4f1ead2..55c7e81 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -16,7 +16,7 @@ use crate::{ ui::{ components::{ list_with_state::ListWithState, - message::{Message, MessageAction}, + message::{Message, MessageAction, MessageType}, }, ui, }, @@ -98,9 +98,20 @@ pub fn run_app( if event::poll(Duration::from_millis(refresh_rate))? { if let Event::Key(key) = event::read()? { match key.code { - KeyCode::Char('q') => return Ok(()), KeyCode::Up => state.prev_item(), KeyCode::Down => state.next_item(), + KeyCode::Char('q') => return Ok(()), + KeyCode::Char('o') => { + let path_to_open = ¤t_appstate.target_directories.current().path; + if open::that(path_to_open).is_err() { + state.set_message(Some(Message::new( + "Couldn't open path in your file explorer", + MessageType::Warning, + Some(Duration::from_secs(2)), + None, + ))) + } + } KeyCode::Char(' ') => state.delete_current_item(), KeyCode::Char('r') => { // to avoid user to spam refresh, which could cause memory issue diff --git a/src/ui/components/list_with_state.rs b/src/ui/components/list_with_state.rs index f47b499..70738ec 100644 --- a/src/ui/components/list_with_state.rs +++ b/src/ui/components/list_with_state.rs @@ -18,6 +18,9 @@ pub struct ListWithState { } impl ListWithState { + pub fn current(&self) -> &T { + &self.datas[self.index] + } pub fn next(&mut self) { match self.index >= self.datas.len() - 1 { true => self.index = 0, diff --git a/src/ui/info_section.rs b/src/ui/info_section.rs index 80a0a38..f5a35d1 100644 --- a/src/ui/info_section.rs +++ b/src/ui/info_section.rs @@ -90,6 +90,11 @@ pub fn draw_info_section(f: &mut Frame, area: Rect, state: &AppSt "r (Refresh)", Style::default().add_modifier(Modifier::BOLD | Modifier::UNDERLINED), ), + Span::raw(", "), + Span::styled( + "o (open)", + Style::default().add_modifier(Modifier::BOLD | Modifier::UNDERLINED), + ), ])) .alignment(Alignment::Center), sub_chunck[1],