mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-05-05 23:21:22 +02:00
refactor: delete a ton of unused code
This commit is contained in:
parent
35ec66eaa7
commit
5c87974fb7
1837
src/app.rs
1837
src/app.rs
File diff suppressed because it is too large
Load Diff
110
src/lib.rs
110
src/lib.rs
@ -20,21 +20,13 @@ use std::{
|
||||
};
|
||||
|
||||
use crossterm::{
|
||||
event::{
|
||||
poll, read, DisableMouseCapture, Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent,
|
||||
MouseEventKind,
|
||||
},
|
||||
event::{poll, read, DisableMouseCapture, Event, KeyEvent, MouseEvent, MouseEventKind},
|
||||
execute,
|
||||
style::Print,
|
||||
terminal::{disable_raw_mode, LeaveAlternateScreen},
|
||||
};
|
||||
|
||||
use app::{
|
||||
data_harvester::{self},
|
||||
event::EventResult,
|
||||
layout_manager::WidgetDirection,
|
||||
AppState, UsedWidgets,
|
||||
};
|
||||
use app::{data_harvester, AppState, UsedWidgets};
|
||||
use constants::*;
|
||||
use options::*;
|
||||
use utils::error;
|
||||
@ -75,104 +67,6 @@ pub enum ThreadControlEvent {
|
||||
UpdateUpdateTime(u64),
|
||||
}
|
||||
|
||||
pub fn handle_key_event(
|
||||
event: KeyEvent, app: &mut AppState, reset_sender: &std::sync::mpsc::Sender<ThreadControlEvent>,
|
||||
) -> EventResult {
|
||||
// debug!("KeyEvent: {:?}", event);
|
||||
|
||||
// TODO: [PASTE] Note that this does NOT support some emojis like flags. This is due to us
|
||||
// catching PER CHARACTER right now WITH A forced throttle! This means multi-char will not work.
|
||||
// We can solve this (when we do paste probably) while keeping the throttle (mainly meant for movement)
|
||||
// by throttling after *bulk+singular* actions, not just singular ones.
|
||||
|
||||
if event.modifiers.is_empty() {
|
||||
// Required catch for searching - otherwise you couldn't search with q.
|
||||
if event.code == KeyCode::Char('q') && !app.is_in_search_widget() {
|
||||
return EventResult::Quit;
|
||||
}
|
||||
match event.code {
|
||||
KeyCode::End => app.skip_to_last(),
|
||||
KeyCode::Home => app.skip_to_first(),
|
||||
KeyCode::Up => app.on_up_key(),
|
||||
KeyCode::Down => app.on_down_key(),
|
||||
KeyCode::Left => app.on_left_key(),
|
||||
KeyCode::Right => app.on_right_key(),
|
||||
KeyCode::Char(caught_char) => app.on_char_key(caught_char),
|
||||
// KeyCode::Esc => app.on_esc(),
|
||||
KeyCode::Enter => app.on_enter(),
|
||||
KeyCode::Tab => app.on_tab(),
|
||||
KeyCode::Backspace => app.on_backspace(),
|
||||
KeyCode::Delete => app.on_delete(),
|
||||
KeyCode::F(1) => app.toggle_ignore_case(),
|
||||
KeyCode::F(2) => app.toggle_search_whole_word(),
|
||||
KeyCode::F(3) => app.toggle_search_regex(),
|
||||
KeyCode::F(5) => app.toggle_tree_mode(),
|
||||
KeyCode::F(6) => app.toggle_sort(),
|
||||
KeyCode::F(9) => app.start_killing_process(),
|
||||
_ => {
|
||||
return EventResult::NoRedraw;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Otherwise, track the modifier as well...
|
||||
if let KeyModifiers::ALT = event.modifiers {
|
||||
match event.code {
|
||||
KeyCode::Char('c') | KeyCode::Char('C') => app.toggle_ignore_case(),
|
||||
KeyCode::Char('w') | KeyCode::Char('W') => app.toggle_search_whole_word(),
|
||||
KeyCode::Char('r') | KeyCode::Char('R') => app.toggle_search_regex(),
|
||||
KeyCode::Char('h') => app.on_left_key(),
|
||||
KeyCode::Char('l') => app.on_right_key(),
|
||||
_ => {}
|
||||
}
|
||||
} else if let KeyModifiers::CONTROL = event.modifiers {
|
||||
if event.code == KeyCode::Char('c') {
|
||||
return EventResult::Quit;
|
||||
}
|
||||
|
||||
match event.code {
|
||||
KeyCode::Char('f') => app.on_slash(),
|
||||
KeyCode::Left => app.move_widget_selection(&WidgetDirection::Left),
|
||||
KeyCode::Right => app.move_widget_selection(&WidgetDirection::Right),
|
||||
KeyCode::Up => app.move_widget_selection(&WidgetDirection::Up),
|
||||
KeyCode::Down => app.move_widget_selection(&WidgetDirection::Down),
|
||||
KeyCode::Char('r') => {
|
||||
if reset_sender.send(ThreadControlEvent::Reset).is_ok() {
|
||||
app.reset();
|
||||
}
|
||||
}
|
||||
KeyCode::Char('a') => app.skip_cursor_beginning(),
|
||||
KeyCode::Char('e') => app.skip_cursor_end(),
|
||||
KeyCode::Char('u') => app.clear_search(),
|
||||
KeyCode::Char('w') => app.clear_previous_word(),
|
||||
KeyCode::Char('h') => app.on_backspace(),
|
||||
// KeyCode::Char('j') => {}, // Move down
|
||||
// KeyCode::Char('k') => {}, // Move up
|
||||
// KeyCode::Char('h') => {}, // Move right
|
||||
// KeyCode::Char('l') => {}, // Move left
|
||||
// Can't do now, CTRL+BACKSPACE doesn't work and graphemes
|
||||
// are hard to iter while truncating last (eloquently).
|
||||
// KeyCode::Backspace => app.skip_word_backspace(),
|
||||
_ => {
|
||||
return EventResult::NoRedraw;
|
||||
}
|
||||
}
|
||||
} else if let KeyModifiers::SHIFT = event.modifiers {
|
||||
match event.code {
|
||||
KeyCode::Left => app.move_widget_selection(&WidgetDirection::Left),
|
||||
KeyCode::Right => app.move_widget_selection(&WidgetDirection::Right),
|
||||
KeyCode::Up => app.move_widget_selection(&WidgetDirection::Up),
|
||||
KeyCode::Down => app.move_widget_selection(&WidgetDirection::Down),
|
||||
KeyCode::Char(caught_char) => app.on_char_key(caught_char),
|
||||
_ => {
|
||||
return EventResult::NoRedraw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EventResult::Redraw
|
||||
}
|
||||
|
||||
pub fn read_config(config_location: Option<&str>) -> error::Result<Option<PathBuf>> {
|
||||
let config_path = if let Some(conf_loc) = config_location {
|
||||
Some(PathBuf::from(conf_loc))
|
||||
|
Loading…
x
Reference in New Issue
Block a user