Skip to content

Commit

Permalink
[V1]: +open 'target' folder in file explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilingu committed Jul 6, 2023
1 parent 45096bf commit 61df529
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
39 changes: 38 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rtkill"
version = "1.0.0"
version = "1.1.0"
edition = "2021"
authors = ["Ilingu"]
rust-version = "1.56.1"
Expand All @@ -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"
15 changes: 13 additions & 2 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
ui::{
components::{
list_with_state::ListWithState,
message::{Message, MessageAction},
message::{Message, MessageAction, MessageType},
},
ui,
},
Expand Down Expand Up @@ -98,9 +98,20 @@ pub fn run_app<B: Backend>(
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 = &current_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
Expand Down
3 changes: 3 additions & 0 deletions src/ui/components/list_with_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub struct ListWithState<T> {
}

impl<T> ListWithState<T> {
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,
Expand Down
5 changes: 5 additions & 0 deletions src/ui/info_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ pub fn draw_info_section<B: Backend>(f: &mut Frame<B>, 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],
Expand Down

0 comments on commit 61df529

Please sign in to comment.