mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-05 21:28:48 +00:00
Merged with #82, still need testing
This commit is contained in:
parent
b3dedea471
commit
0ca4f09dbc
18
src/list.rs
18
src/list.rs
|
@ -9,6 +9,7 @@ use ratatui::{
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
struct ListNode {
|
struct ListNode {
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
command: Command,
|
command: Command,
|
||||||
|
@ -161,7 +162,8 @@ impl CustomList {
|
||||||
self.filtered_items
|
self.filtered_items
|
||||||
.iter()
|
.iter()
|
||||||
.map(|node| {
|
.map(|node| {
|
||||||
Line::from(format!("{} {}", state.theme.cmd_icon, node.value().name)).style(state.theme.cmd_color)
|
Line::from(format!("{} {}", state.theme.cmd_icon, node.name))
|
||||||
|
.style(state.theme.cmd_color)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
};
|
};
|
||||||
|
@ -313,6 +315,7 @@ impl CustomList {
|
||||||
} else {
|
} else {
|
||||||
self.filtered_items.len()
|
self.filtered_items.len()
|
||||||
};
|
};
|
||||||
|
|
||||||
let curr_selection = self.list_state.selected().unwrap();
|
let curr_selection = self.list_state.selected().unwrap();
|
||||||
if self.at_root() {
|
if self.at_root() {
|
||||||
self.list_state
|
self.list_state
|
||||||
|
@ -378,12 +381,15 @@ impl CustomList {
|
||||||
///
|
///
|
||||||
/// Returns `Some(command)` when command is selected, othervise we returns `None`
|
/// Returns `Some(command)` when command is selected, othervise we returns `None`
|
||||||
fn handle_enter(&mut self) -> Option<Command> {
|
fn handle_enter(&mut self) -> Option<Command> {
|
||||||
// Get the current node (current directory)
|
// Get the selected index
|
||||||
|
let selected = self.list_state.selected().unwrap();
|
||||||
|
|
||||||
|
if self.filter_query.is_empty() {
|
||||||
|
// No filter query, use the regular tree navigation
|
||||||
let curr = self
|
let curr = self
|
||||||
.inner_tree
|
.inner_tree
|
||||||
.get(*self.visit_stack.last().unwrap())
|
.get(*self.visit_stack.last().unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let selected = self.list_state.selected().unwrap();
|
|
||||||
|
|
||||||
// if we are not at the root, and the first element is selected,
|
// if we are not at the root, and the first element is selected,
|
||||||
// we can be sure it's '..', so we go up the directory
|
// we can be sure it's '..', so we go up the directory
|
||||||
|
@ -409,6 +415,12 @@ impl CustomList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Filter query is active, use the filtered items
|
||||||
|
if let Some(filtered_node) = self.filtered_items.get(selected) {
|
||||||
|
return Some(filtered_node.command.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -145,7 +145,27 @@ fn run<B: Backend>(terminal: &mut Terminal<B>, state: &AppState) -> io::Result<(
|
||||||
if key.code == KeyCode::Char('q') {
|
if key.code == KeyCode::Char('q') {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if let Some(cmd) = custom_list.handle_key(key, state) {
|
//Activate search mode if the forward slash key gets pressed
|
||||||
|
if key.code == KeyCode::Char('/') {
|
||||||
|
// Enter search mode
|
||||||
|
in_search_mode = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//Insert user input into the search bar
|
||||||
|
if in_search_mode {
|
||||||
|
match key.code {
|
||||||
|
KeyCode::Char(c) => search_input.push(c),
|
||||||
|
KeyCode::Backspace => {
|
||||||
|
search_input.pop();
|
||||||
|
}
|
||||||
|
KeyCode::Esc => {
|
||||||
|
search_input = String::new();
|
||||||
|
in_search_mode = false
|
||||||
|
}
|
||||||
|
KeyCode::Enter => in_search_mode = false,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
} else if let Some(cmd) = custom_list.handle_key(key, state) {
|
||||||
command_opt = Some(RunningCommand::new(cmd, state));
|
command_opt = Some(RunningCommand::new(cmd, state));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user