mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-22 13:22:28 +00:00
Merge pull request #241 from cartercanedy/main
Close linutil on Control-C, don't reset cursor position on exit
This commit is contained in:
commit
6d0a357072
|
@ -64,9 +64,7 @@ impl Float {
|
|||
// Returns true if the floating window is finished.
|
||||
pub fn handle_key_event(&mut self, key: &KeyEvent) -> bool {
|
||||
match key.code {
|
||||
KeyCode::Enter | KeyCode::Char('p') | KeyCode::Esc | KeyCode::Char('q')
|
||||
if self.content.is_finished() =>
|
||||
{
|
||||
KeyCode::Enter | KeyCode::Char('p') | KeyCode::Esc if self.content.is_finished() => {
|
||||
true
|
||||
}
|
||||
_ => self.content.handle_key_event(key),
|
||||
|
|
|
@ -14,7 +14,6 @@ use std::{
|
|||
use crate::theme::Theme;
|
||||
use clap::Parser;
|
||||
use crossterm::{
|
||||
cursor::RestorePosition,
|
||||
event::{self, DisableMouseCapture, Event, KeyEventKind},
|
||||
style::ResetColor,
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
|
@ -38,7 +37,7 @@ struct Args {
|
|||
override_validation: bool,
|
||||
}
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
fn main() -> io::Result<()> {
|
||||
let args = Args::parse();
|
||||
|
||||
let mut state = AppState::new(args.theme, args.override_validation);
|
||||
|
@ -55,8 +54,8 @@ fn main() -> std::io::Result<()> {
|
|||
terminal.backend_mut().execute(LeaveAlternateScreen)?;
|
||||
terminal.backend_mut().execute(DisableMouseCapture)?;
|
||||
terminal.backend_mut().execute(ResetColor)?;
|
||||
terminal.backend_mut().execute(RestorePosition)?;
|
||||
terminal.show_cursor()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
running_command::RunningCommand,
|
||||
theme::Theme,
|
||||
};
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
|
||||
use ego_tree::NodeId;
|
||||
use linutil_core::{Command, ListNode, Tab};
|
||||
use ratatui::{
|
||||
|
@ -185,6 +185,7 @@ impl AppState {
|
|||
|
||||
draw_shortcuts(self, frame, vertical[1]);
|
||||
}
|
||||
|
||||
pub fn handle_key(&mut self, key: &KeyEvent) -> bool {
|
||||
match &mut self.focus {
|
||||
Focus::FloatingWindow(command) => {
|
||||
|
@ -192,31 +193,43 @@ impl AppState {
|
|||
self.focus = Focus::List;
|
||||
}
|
||||
}
|
||||
|
||||
Focus::Search => match self.filter.handle_key(key) {
|
||||
SearchAction::Exit => self.exit_search(),
|
||||
SearchAction::Update => self.update_items(),
|
||||
_ => {}
|
||||
},
|
||||
_ if key.code == KeyCode::Char('q') => return false,
|
||||
|
||||
_ if key.code == KeyCode::Char('q')
|
||||
|| key.code == KeyCode::Char('c')
|
||||
&& key.modifiers.contains(KeyModifiers::CONTROL) =>
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Focus::TabList => match key.code {
|
||||
KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right | KeyCode::Tab => {
|
||||
self.focus = Focus::List
|
||||
}
|
||||
|
||||
KeyCode::Char('j') | KeyCode::Down
|
||||
if self.current_tab.selected().unwrap() + 1 < self.tabs.len() =>
|
||||
{
|
||||
self.current_tab.select_next();
|
||||
self.refresh_tab();
|
||||
}
|
||||
|
||||
KeyCode::Char('k') | KeyCode::Up => {
|
||||
self.current_tab.select_previous();
|
||||
self.refresh_tab();
|
||||
}
|
||||
|
||||
KeyCode::Char('/') => self.enter_search(),
|
||||
KeyCode::Char('t') => self.theme.next(),
|
||||
KeyCode::Char('T') => self.theme.prev(),
|
||||
_ => {}
|
||||
},
|
||||
|
||||
Focus::List if key.kind != KeyEventKind::Release => match key.code {
|
||||
KeyCode::Char('j') | KeyCode::Down => self.selection.select_next(),
|
||||
KeyCode::Char('k') | KeyCode::Up => self.selection.select_previous(),
|
||||
|
@ -235,10 +248,12 @@ impl AppState {
|
|||
KeyCode::Char('T') => self.theme.prev(),
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
|
||||
_ => (),
|
||||
};
|
||||
true
|
||||
}
|
||||
|
||||
fn update_items(&mut self) {
|
||||
self.filter.update_items(
|
||||
&self.tabs,
|
||||
|
@ -246,12 +261,14 @@ impl AppState {
|
|||
*self.visit_stack.last().unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Checks ehther the current tree node is the root node (can we go up the tree or no)
|
||||
/// Returns `true` if we can't go up the tree (we are at the tree root)
|
||||
/// else returns `false`
|
||||
pub fn at_root(&self) -> bool {
|
||||
self.visit_stack.len() == 1
|
||||
}
|
||||
|
||||
fn enter_parent_directory(&mut self) {
|
||||
self.visit_stack.pop();
|
||||
self.selection.select(Some(0));
|
||||
|
|
Loading…
Reference in New Issue
Block a user