mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-29 00:24:36 +02:00
Quit functionality
This commit is contained in:
parent
b304db6a2f
commit
56a9856796
26
src/app.rs
26
src/app.rs
@ -203,6 +203,10 @@ impl AppState {
|
||||
// TODO: Redraw
|
||||
}
|
||||
}
|
||||
|
||||
fn quit(&mut self) {
|
||||
self.terminator.store(true, SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
impl Application for AppState {
|
||||
@ -264,9 +268,27 @@ impl Application for AppState {
|
||||
&mut self, event: crate::tuine::Event, _messages: &mut Vec<Self::Message>,
|
||||
) {
|
||||
use crate::tuine::Event;
|
||||
use crossterm::event::{KeyCode, KeyModifiers};
|
||||
|
||||
match event {
|
||||
Event::Keyboard(_) => {}
|
||||
Event::Mouse(_) => {}
|
||||
Event::Keyboard(event) => {
|
||||
if event.modifiers.is_empty() {
|
||||
match event.code {
|
||||
KeyCode::Char('q') | KeyCode::Char('Q') => {
|
||||
self.quit();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else if let KeyModifiers::CONTROL = event.modifiers {
|
||||
match event.code {
|
||||
KeyCode::Char('c') | KeyCode::Char('C') => {
|
||||
self.quit();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
Event::Mouse(event) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handles a [`Event`].
|
||||
fn on_event<A>(
|
||||
application: &mut A, user_interface: &mut Element<'_, A::Message>, app_data: &mut AppData,
|
||||
layout: &mut LayoutNode, event: Event,
|
||||
@ -98,6 +99,7 @@ fn on_event<A>(
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new [`Element`] representing the root of the user interface.
|
||||
fn new_user_interface<A>(
|
||||
application: &mut A, app_data: &mut AppData,
|
||||
) -> Element<'static, A::Message>
|
||||
@ -108,6 +110,7 @@ where
|
||||
application.view(&mut ctx)
|
||||
}
|
||||
|
||||
/// Updates the layout, and draws the given user interface.
|
||||
fn draw<M, B>(
|
||||
user_interface: &mut Element<'_, M>, terminal: &mut Terminal<B>, app_data: &mut AppData,
|
||||
layout: &mut LayoutNode,
|
||||
|
Loading…
x
Reference in New Issue
Block a user